ghart-declarative_authorization 0.3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +83 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +510 -0
- data/Rakefile +43 -0
- data/app/controllers/authorization_rules_controller.rb +259 -0
- data/app/controllers/authorization_usages_controller.rb +23 -0
- data/app/helpers/authorization_rules_helper.rb +187 -0
- data/app/views/authorization_rules/_change.erb +58 -0
- data/app/views/authorization_rules/_show_graph.erb +37 -0
- data/app/views/authorization_rules/_suggestions.erb +48 -0
- data/app/views/authorization_rules/change.html.erb +152 -0
- data/app/views/authorization_rules/graph.dot.erb +68 -0
- data/app/views/authorization_rules/graph.html.erb +40 -0
- data/app/views/authorization_rules/index.html.erb +17 -0
- data/app/views/authorization_usages/index.html.erb +36 -0
- data/authorization_rules.dist.rb +20 -0
- data/config/routes.rb +7 -0
- data/garlic_example.rb +20 -0
- data/init.rb +5 -0
- data/lib/declarative_authorization.rb +15 -0
- data/lib/declarative_authorization/authorization.rb +634 -0
- data/lib/declarative_authorization/development_support/analyzer.rb +252 -0
- data/lib/declarative_authorization/development_support/change_analyzer.rb +253 -0
- data/lib/declarative_authorization/development_support/change_supporter.rb +620 -0
- data/lib/declarative_authorization/development_support/development_support.rb +243 -0
- data/lib/declarative_authorization/helper.rb +60 -0
- data/lib/declarative_authorization/in_controller.rb +597 -0
- data/lib/declarative_authorization/in_model.rb +159 -0
- data/lib/declarative_authorization/maintenance.rb +182 -0
- data/lib/declarative_authorization/obligation_scope.rb +308 -0
- data/lib/declarative_authorization/rails_legacy.rb +14 -0
- data/lib/declarative_authorization/reader.rb +441 -0
- data/test/authorization_test.rb +827 -0
- data/test/controller_filter_resource_access_test.rb +394 -0
- data/test/controller_test.rb +386 -0
- data/test/dsl_reader_test.rb +157 -0
- data/test/helper_test.rb +171 -0
- data/test/maintenance_test.rb +46 -0
- data/test/model_test.rb +1308 -0
- data/test/schema.sql +54 -0
- data/test/test_helper.rb +118 -0
- metadata +106 -0
data/test/schema.sql
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
CREATE TABLE 'test_models' (
|
2
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
3
|
+
'test_attr_through_id' INTEGER,
|
4
|
+
'content' text,
|
5
|
+
'country_id' integer,
|
6
|
+
'created_at' datetime,
|
7
|
+
'updated_at' datetime
|
8
|
+
);
|
9
|
+
|
10
|
+
CREATE TABLE 'test_attrs' (
|
11
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
12
|
+
'test_model_id' integer,
|
13
|
+
'test_another_model_id' integer,
|
14
|
+
'test_a_third_model_id' integer,
|
15
|
+
'branch_id' integer,
|
16
|
+
'company_id' integer,
|
17
|
+
'test_attr_through_id' INTEGER,
|
18
|
+
'n_way_join_item_id' INTEGER,
|
19
|
+
'test_model_security_model_id' integer,
|
20
|
+
'attr' integer default 1
|
21
|
+
);
|
22
|
+
|
23
|
+
CREATE TABLE 'test_attr_throughs' (
|
24
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
25
|
+
'test_attr_id' integer
|
26
|
+
);
|
27
|
+
|
28
|
+
CREATE TABLE 'test_model_security_models' (
|
29
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
30
|
+
'attr' integer default 1,
|
31
|
+
'attr_2' integer default 1
|
32
|
+
);
|
33
|
+
|
34
|
+
CREATE TABLE 'n_way_join_items' (
|
35
|
+
'id' INTEGER PRIMARY KEY NOT NULL
|
36
|
+
);
|
37
|
+
|
38
|
+
CREATE TABLE 'branches' (
|
39
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
40
|
+
'company_id' integer,
|
41
|
+
'name' text
|
42
|
+
);
|
43
|
+
|
44
|
+
CREATE TABLE 'companies' (
|
45
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
46
|
+
'country_id' integer,
|
47
|
+
'type' text,
|
48
|
+
'name' text
|
49
|
+
);
|
50
|
+
|
51
|
+
CREATE TABLE 'countries' (
|
52
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
53
|
+
'name' text
|
54
|
+
);
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
RAILS_ROOT = File.join(File.dirname(__FILE__), %w{.. .. .. ..})
|
3
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization rails_legacy})
|
4
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization authorization})
|
5
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization in_controller})
|
6
|
+
|
7
|
+
unless defined?(ActiveRecord)
|
8
|
+
if File.directory? RAILS_ROOT + 'config'
|
9
|
+
puts 'using config/boot.rb'
|
10
|
+
ENV['RAILS_ENV'] = 'test'
|
11
|
+
require File.join(RAILS_ROOT, 'config', 'boot.rb')
|
12
|
+
else
|
13
|
+
# simply use installed gems if available
|
14
|
+
puts 'using rubygems'
|
15
|
+
require 'rubygems'
|
16
|
+
gem 'actionpack'; gem 'activerecord'; gem 'activesupport'; gem 'rails'
|
17
|
+
end
|
18
|
+
|
19
|
+
%w(action_pack action_controller active_record active_support initializer).each {|f| require f}
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'ruby-debug'
|
24
|
+
rescue MissingSourceFile; end
|
25
|
+
|
26
|
+
|
27
|
+
class MockDataObject
|
28
|
+
def initialize (attrs = {})
|
29
|
+
attrs.each do |key, value|
|
30
|
+
instance_variable_set(:"@#{key}", value)
|
31
|
+
self.class.class_eval do
|
32
|
+
attr_reader key
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.descends_from_active_record?
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.table_name
|
42
|
+
name.tableize
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.name
|
46
|
+
"Mock"
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.find(*args)
|
50
|
+
raise "Couldn't find #{self.name} with id #{args[0].inspect}" unless args[0]
|
51
|
+
new :id => args[0]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class MockUser < MockDataObject
|
56
|
+
def initialize (*roles)
|
57
|
+
options = roles.last.is_a?(::Hash) ? roles.pop : {}
|
58
|
+
super(options.merge(:role_symbols => roles, :login => hash))
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize_copy (other)
|
62
|
+
@role_symbols = @role_symbols.clone
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class MocksController < ActionController::Base
|
67
|
+
attr_accessor :current_user
|
68
|
+
attr_writer :authorization_engine
|
69
|
+
|
70
|
+
def authorized?
|
71
|
+
!!@authorized
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.define_action_methods (*methods)
|
75
|
+
methods.each do |method|
|
76
|
+
define_method method do
|
77
|
+
@authorized = true
|
78
|
+
render :text => 'nothing'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.define_resource_actions
|
84
|
+
define_action_methods :index, :show, :edit, :update, :new, :create, :destroy
|
85
|
+
end
|
86
|
+
|
87
|
+
def logger (*args)
|
88
|
+
Class.new do
|
89
|
+
def warn(*args)
|
90
|
+
#p args
|
91
|
+
end
|
92
|
+
alias_method :info, :warn
|
93
|
+
alias_method :debug, :warn
|
94
|
+
def warn?; end
|
95
|
+
alias_method :info?, :warn?
|
96
|
+
alias_method :debug?, :warn?
|
97
|
+
end.new
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
ActionController::Routing::Routes.draw do |map|
|
102
|
+
map.connect ':controller/:action/:id'
|
103
|
+
end
|
104
|
+
ActionController::Base.send :include, Authorization::AuthorizationInController
|
105
|
+
require "action_controller/test_process"
|
106
|
+
|
107
|
+
class Test::Unit::TestCase
|
108
|
+
def request! (user, action, reader, params = {})
|
109
|
+
action = action.to_sym if action.is_a?(String)
|
110
|
+
@controller.current_user = user
|
111
|
+
@controller.authorization_engine = Authorization::Engine.new(reader)
|
112
|
+
|
113
|
+
((params.delete(:clear) || []) + [:@authorized]).each do |var|
|
114
|
+
@controller.instance_variable_set(var, nil)
|
115
|
+
end
|
116
|
+
get action, params
|
117
|
+
end
|
118
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghart-declarative_authorization
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steffen Bartsch
|
8
|
+
- Greg Hart
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-11-01 01:00:00 -06:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.1.0
|
25
|
+
version:
|
26
|
+
description:
|
27
|
+
email: sbartsch@tzi.org
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
- CHANGELOG
|
35
|
+
files:
|
36
|
+
- CHANGELOG
|
37
|
+
- MIT-LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- authorization_rules.dist.rb
|
41
|
+
- garlic_example.rb
|
42
|
+
- init.rb
|
43
|
+
- app/controllers/authorization_rules_controller.rb
|
44
|
+
- app/controllers/authorization_usages_controller.rb
|
45
|
+
- app/helpers/authorization_rules_helper.rb
|
46
|
+
- app/views/authorization_usages/index.html.erb
|
47
|
+
- app/views/authorization_rules/index.html.erb
|
48
|
+
- app/views/authorization_rules/_show_graph.erb
|
49
|
+
- app/views/authorization_rules/_change.erb
|
50
|
+
- app/views/authorization_rules/_suggestions.erb
|
51
|
+
- app/views/authorization_rules/graph.dot.erb
|
52
|
+
- app/views/authorization_rules/change.html.erb
|
53
|
+
- app/views/authorization_rules/graph.html.erb
|
54
|
+
- config/routes.rb
|
55
|
+
- lib/declarative_authorization.rb
|
56
|
+
- lib/declarative_authorization/in_controller.rb
|
57
|
+
- lib/declarative_authorization/reader.rb
|
58
|
+
- lib/declarative_authorization/rails_legacy.rb
|
59
|
+
- lib/declarative_authorization/obligation_scope.rb
|
60
|
+
- lib/declarative_authorization/in_model.rb
|
61
|
+
- lib/declarative_authorization/helper.rb
|
62
|
+
- lib/declarative_authorization/development_support/analyzer.rb
|
63
|
+
- lib/declarative_authorization/development_support/change_analyzer.rb
|
64
|
+
- lib/declarative_authorization/development_support/change_supporter.rb
|
65
|
+
- lib/declarative_authorization/development_support/development_support.rb
|
66
|
+
- lib/declarative_authorization/authorization.rb
|
67
|
+
- lib/declarative_authorization/maintenance.rb
|
68
|
+
- test/authorization_test.rb
|
69
|
+
- test/schema.sql
|
70
|
+
- test/maintenance_test.rb
|
71
|
+
- test/model_test.rb
|
72
|
+
- test/controller_test.rb
|
73
|
+
- test/helper_test.rb
|
74
|
+
- test/dsl_reader_test.rb
|
75
|
+
- test/controller_filter_resource_access_test.rb
|
76
|
+
- test/test_helper.rb
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://github.com/ghart/declarative_authorization
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.8.6
|
91
|
+
version:
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.5
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: declarative_authorization is a Rails plugin for authorization based on readable authorization rules.
|
105
|
+
test_files: []
|
106
|
+
|