declarative_authorization-dta 0.1
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 +148 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +504 -0
- data/Rakefile +35 -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 +218 -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 +169 -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 +10 -0
- data/garlic_example.rb +20 -0
- data/init.rb +5 -0
- data/lib/declarative_authorization.rb +17 -0
- data/lib/declarative_authorization/authorization.rb +687 -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 +623 -0
- data/lib/declarative_authorization/in_model.new.rb +298 -0
- data/lib/declarative_authorization/in_model.rb +463 -0
- data/lib/declarative_authorization/maintenance.rb +212 -0
- data/lib/declarative_authorization/obligation_scope.rb +354 -0
- data/lib/declarative_authorization/rails_legacy.rb +22 -0
- data/lib/declarative_authorization/railsengine.rb +6 -0
- data/lib/declarative_authorization/reader.rb +521 -0
- data/lib/tasks/authorization_tasks.rake +82 -0
- data/test/authorization_test.rb +1065 -0
- data/test/controller_filter_resource_access_test.rb +511 -0
- data/test/controller_test.rb +465 -0
- data/test/dsl_reader_test.rb +178 -0
- data/test/helper_test.rb +172 -0
- data/test/maintenance_test.rb +46 -0
- data/test/model_test.rb +2216 -0
- data/test/schema.sql +62 -0
- data/test/test_helper.rb +152 -0
- metadata +108 -0
data/test/schema.sql
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
CREATE TABLE 'test_model_security_model_with_include_attributes' (
|
2
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
3
|
+
'attr_1' integer default 1,
|
4
|
+
'attr_2' integer default 1,
|
5
|
+
'attr_3' integer default 1,
|
6
|
+
'attr_4' integer default 1
|
7
|
+
);
|
8
|
+
|
9
|
+
CREATE TABLE 'test_models' (
|
10
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
11
|
+
'test_attr_through_id' INTEGER,
|
12
|
+
'content' text,
|
13
|
+
'country_id' integer,
|
14
|
+
'created_at' datetime,
|
15
|
+
'updated_at' datetime
|
16
|
+
);
|
17
|
+
|
18
|
+
CREATE TABLE 'test_attrs' (
|
19
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
20
|
+
'test_model_id' integer,
|
21
|
+
'test_another_model_id' integer,
|
22
|
+
'test_a_third_model_id' integer,
|
23
|
+
'branch_id' integer,
|
24
|
+
'company_id' integer,
|
25
|
+
'test_attr_through_id' INTEGER,
|
26
|
+
'n_way_join_item_id' INTEGER,
|
27
|
+
'test_model_security_model_id' integer,
|
28
|
+
'attr' integer default 1
|
29
|
+
);
|
30
|
+
|
31
|
+
CREATE TABLE 'test_attr_throughs' (
|
32
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
33
|
+
'test_attr_id' integer
|
34
|
+
);
|
35
|
+
|
36
|
+
CREATE TABLE 'test_model_security_models' (
|
37
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
38
|
+
'attr' integer default 1,
|
39
|
+
'attr_2' integer default 1
|
40
|
+
);
|
41
|
+
|
42
|
+
CREATE TABLE 'n_way_join_items' (
|
43
|
+
'id' INTEGER PRIMARY KEY NOT NULL
|
44
|
+
);
|
45
|
+
|
46
|
+
CREATE TABLE 'branches' (
|
47
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
48
|
+
'company_id' integer,
|
49
|
+
'name' text
|
50
|
+
);
|
51
|
+
|
52
|
+
CREATE TABLE 'companies' (
|
53
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
54
|
+
'country_id' integer,
|
55
|
+
'type' text,
|
56
|
+
'name' text
|
57
|
+
);
|
58
|
+
|
59
|
+
CREATE TABLE 'countries' (
|
60
|
+
'id' INTEGER PRIMARY KEY NOT NULL,
|
61
|
+
'name' text
|
62
|
+
);
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
unless defined?(RAILS_ROOT)
|
5
|
+
RAILS_ROOT = ENV['RAILS_ROOT'] ?
|
6
|
+
ENV['RAILS_ROOT'] + "" :
|
7
|
+
File.join(File.dirname(__FILE__), %w{.. .. .. ..})
|
8
|
+
end
|
9
|
+
|
10
|
+
unless defined?(ActiveRecord)
|
11
|
+
if File.directory? RAILS_ROOT + '/config'
|
12
|
+
puts 'Using config/boot.rb'
|
13
|
+
ENV['RAILS_ENV'] = 'test'
|
14
|
+
require File.join(RAILS_ROOT, 'config', 'environment.rb')
|
15
|
+
else
|
16
|
+
# simply use installed gems if available
|
17
|
+
version_requirement = ENV['RAILS_VERSION'] ? "= #{ENV['RAILS_VERSION']}" : "> 2.1.0"
|
18
|
+
puts "Using Rails from RubyGems (#{version_requirement || "default"})"
|
19
|
+
require 'rubygems'
|
20
|
+
%w{actionpack activerecord activesupport rails}.each do |gem_name|
|
21
|
+
gem gem_name, version_requirement
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
unless defined?(Rails) # needs to be explicit in Rails < 3
|
26
|
+
%w(action_pack action_controller active_record active_support initializer).each {|f| require f}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
DA_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
|
31
|
+
|
32
|
+
require DA_ROOT + File.join(%w{lib declarative_authorization rails_legacy})
|
33
|
+
require DA_ROOT + File.join(%w{lib declarative_authorization authorization})
|
34
|
+
require DA_ROOT + File.join(%w{lib declarative_authorization in_controller})
|
35
|
+
require DA_ROOT + File.join(%w{lib declarative_authorization maintenance})
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'ruby-debug'
|
39
|
+
rescue MissingSourceFile; end
|
40
|
+
|
41
|
+
|
42
|
+
class MockDataObject
|
43
|
+
def initialize (attrs = {})
|
44
|
+
attrs.each do |key, value|
|
45
|
+
instance_variable_set(:"@#{key}", value)
|
46
|
+
self.class.class_eval do
|
47
|
+
attr_reader key
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.descends_from_active_record?
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.table_name
|
57
|
+
name.tableize
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.name
|
61
|
+
"Mock"
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.find(*args)
|
65
|
+
raise "Couldn't find #{self.name} with id #{args[0].inspect}" unless args[0]
|
66
|
+
new :id => args[0]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class MockUser < MockDataObject
|
71
|
+
def initialize (*roles)
|
72
|
+
options = roles.last.is_a?(::Hash) ? roles.pop : {}
|
73
|
+
super(options.merge(:role_symbols => roles, :login => hash))
|
74
|
+
end
|
75
|
+
|
76
|
+
def initialize_copy (other)
|
77
|
+
@role_symbols = @role_symbols.clone
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class MocksController < ActionController::Base
|
82
|
+
attr_accessor :current_user
|
83
|
+
attr_writer :authorization_engine
|
84
|
+
|
85
|
+
def authorized?
|
86
|
+
!!@authorized
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.define_action_methods (*methods)
|
90
|
+
methods.each do |method|
|
91
|
+
define_method method do
|
92
|
+
@authorized = true
|
93
|
+
render :text => 'nothing'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.define_resource_actions
|
99
|
+
define_action_methods :index, :show, :edit, :update, :new, :create, :destroy
|
100
|
+
end
|
101
|
+
|
102
|
+
def logger (*args)
|
103
|
+
Class.new do
|
104
|
+
def warn(*args)
|
105
|
+
#p args
|
106
|
+
end
|
107
|
+
alias_method :info, :warn
|
108
|
+
alias_method :debug, :warn
|
109
|
+
def warn?; end
|
110
|
+
alias_method :info?, :warn?
|
111
|
+
alias_method :debug?, :warn?
|
112
|
+
end.new
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if Rails.version < "3"
|
117
|
+
ActionController::Routing::Routes.draw do |map|
|
118
|
+
map.connect ':controller/:action/:id'
|
119
|
+
end
|
120
|
+
else
|
121
|
+
Rails::Application.routes.draw do
|
122
|
+
match '/name/spaced_things(/:action)' => 'name/spaced_things'
|
123
|
+
match '/deep/name_spaced/things(/:action)' => 'deep/name_spaced/things'
|
124
|
+
match '/:controller(/:action(/:id))'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
ActionController::Base.send :include, Authorization::AuthorizationInController
|
129
|
+
if Rails.version < "3"
|
130
|
+
require "action_controller/test_process"
|
131
|
+
end
|
132
|
+
|
133
|
+
class Test::Unit::TestCase
|
134
|
+
include Authorization::TestHelper
|
135
|
+
|
136
|
+
def request! (user, action, reader, params = {})
|
137
|
+
action = action.to_sym if action.is_a?(String)
|
138
|
+
@controller.current_user = user
|
139
|
+
@controller.authorization_engine = Authorization::Engine.new(reader)
|
140
|
+
|
141
|
+
((params.delete(:clear) || []) + [:@authorized]).each do |var|
|
142
|
+
@controller.instance_variable_set(var, nil)
|
143
|
+
end
|
144
|
+
get action, params
|
145
|
+
end
|
146
|
+
|
147
|
+
unless Rails.version < "3"
|
148
|
+
def setup
|
149
|
+
@routes = Rails::Application.routes
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: declarative_authorization-dta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Luehr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-09-03 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.0
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: yanosz@gmx.net
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- CHANGELOG
|
34
|
+
files:
|
35
|
+
- CHANGELOG
|
36
|
+
- MIT-LICENSE
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
39
|
+
- authorization_rules.dist.rb
|
40
|
+
- garlic_example.rb
|
41
|
+
- init.rb
|
42
|
+
- app/controllers/authorization_rules_controller.rb
|
43
|
+
- app/controllers/authorization_usages_controller.rb
|
44
|
+
- app/helpers/authorization_rules_helper.rb
|
45
|
+
- app/views/authorization_rules/_change.erb
|
46
|
+
- app/views/authorization_rules/_show_graph.erb
|
47
|
+
- app/views/authorization_rules/_suggestions.erb
|
48
|
+
- app/views/authorization_rules/change.html.erb
|
49
|
+
- app/views/authorization_rules/graph.dot.erb
|
50
|
+
- app/views/authorization_rules/graph.html.erb
|
51
|
+
- app/views/authorization_rules/index.html.erb
|
52
|
+
- app/views/authorization_usages/index.html.erb
|
53
|
+
- config/routes.rb
|
54
|
+
- lib/declarative_authorization.rb
|
55
|
+
- lib/declarative_authorization/authorization.rb
|
56
|
+
- lib/declarative_authorization/development_support/analyzer.rb
|
57
|
+
- lib/declarative_authorization/development_support/change_analyzer.rb
|
58
|
+
- lib/declarative_authorization/development_support/change_supporter.rb
|
59
|
+
- lib/declarative_authorization/development_support/development_support.rb
|
60
|
+
- lib/declarative_authorization/helper.rb
|
61
|
+
- lib/declarative_authorization/in_controller.rb
|
62
|
+
- lib/declarative_authorization/in_model.new.rb
|
63
|
+
- lib/declarative_authorization/in_model.rb
|
64
|
+
- lib/declarative_authorization/maintenance.rb
|
65
|
+
- lib/declarative_authorization/obligation_scope.rb
|
66
|
+
- lib/declarative_authorization/rails_legacy.rb
|
67
|
+
- lib/declarative_authorization/railsengine.rb
|
68
|
+
- lib/declarative_authorization/reader.rb
|
69
|
+
- lib/tasks/authorization_tasks.rake
|
70
|
+
- test/authorization_test.rb
|
71
|
+
- test/controller_filter_resource_access_test.rb
|
72
|
+
- test/controller_test.rb
|
73
|
+
- test/dsl_reader_test.rb
|
74
|
+
- test/helper_test.rb
|
75
|
+
- test/maintenance_test.rb
|
76
|
+
- test/model_test.rb
|
77
|
+
- test/schema.sql
|
78
|
+
- test/test_helper.rb
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://github.com/yanosz/declarative_authorization
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.8.6
|
93
|
+
version:
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: "0"
|
99
|
+
version:
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.3.5
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: declarative_authorization is a Rails plugin for authorization based on readable authorization rules.
|
107
|
+
test_files: []
|
108
|
+
|