uhees-declarative_authorization 0.3.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.
Files changed (42) hide show
  1. data/CHANGELOG +77 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +490 -0
  4. data/Rakefile +43 -0
  5. data/app/controllers/authorization_rules_controller.rb +235 -0
  6. data/app/controllers/authorization_usages_controller.rb +23 -0
  7. data/app/helpers/authorization_rules_helper.rb +183 -0
  8. data/app/views/authorization_rules/_change.erb +49 -0
  9. data/app/views/authorization_rules/_show_graph.erb +37 -0
  10. data/app/views/authorization_rules/_suggestion.erb +9 -0
  11. data/app/views/authorization_rules/_suggestions.erb +24 -0
  12. data/app/views/authorization_rules/change.html.erb +124 -0
  13. data/app/views/authorization_rules/graph.dot.erb +68 -0
  14. data/app/views/authorization_rules/graph.html.erb +40 -0
  15. data/app/views/authorization_rules/index.html.erb +17 -0
  16. data/app/views/authorization_usages/index.html.erb +36 -0
  17. data/authorization_rules.dist.rb +20 -0
  18. data/config/routes.rb +7 -0
  19. data/garlic_example.rb +20 -0
  20. data/init.rb +5 -0
  21. data/lib/declarative_authorization.rb +15 -0
  22. data/lib/declarative_authorization/authorization.rb +630 -0
  23. data/lib/declarative_authorization/development_support/analyzer.rb +252 -0
  24. data/lib/declarative_authorization/development_support/change_analyzer.rb +253 -0
  25. data/lib/declarative_authorization/development_support/change_supporter.rb +578 -0
  26. data/lib/declarative_authorization/development_support/development_support.rb +243 -0
  27. data/lib/declarative_authorization/helper.rb +60 -0
  28. data/lib/declarative_authorization/in_controller.rb +367 -0
  29. data/lib/declarative_authorization/in_model.rb +150 -0
  30. data/lib/declarative_authorization/maintenance.rb +188 -0
  31. data/lib/declarative_authorization/obligation_scope.rb +297 -0
  32. data/lib/declarative_authorization/rails_legacy.rb +14 -0
  33. data/lib/declarative_authorization/reader.rb +438 -0
  34. data/test/authorization_test.rb +823 -0
  35. data/test/controller_test.rb +418 -0
  36. data/test/dsl_reader_test.rb +157 -0
  37. data/test/helper_test.rb +154 -0
  38. data/test/maintenance_test.rb +41 -0
  39. data/test/model_test.rb +1171 -0
  40. data/test/schema.sql +53 -0
  41. data/test/test_helper.rb +103 -0
  42. metadata +104 -0
data/test/schema.sql ADDED
@@ -0,0 +1,53 @@
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
+ 'name' text
48
+ );
49
+
50
+ CREATE TABLE 'countries' (
51
+ 'id' INTEGER PRIMARY KEY NOT NULL,
52
+ 'name' text
53
+ );
@@ -0,0 +1,103 @@
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 descends_from_active_record?
38
+ true
39
+ end
40
+
41
+ def self.table_name
42
+ "mocks"
43
+ end
44
+ end
45
+
46
+ class MockUser < MockDataObject
47
+ def initialize (*roles)
48
+ options = roles.last.is_a?(::Hash) ? roles.pop : {}
49
+ super(options.merge(:role_symbols => roles, :login => hash))
50
+ end
51
+
52
+ def initialize_copy (other)
53
+ @role_symbols = @role_symbols.clone
54
+ end
55
+ end
56
+
57
+ class MocksController < ActionController::Base
58
+ attr_accessor :current_user
59
+ attr_writer :authorization_engine
60
+
61
+ def authorized?
62
+ !!@authorized
63
+ end
64
+
65
+ def self.define_action_methods (*methods)
66
+ methods.each do |method|
67
+ define_method method do
68
+ @authorized = true
69
+ render :text => 'nothing'
70
+ end
71
+ end
72
+ end
73
+
74
+ def logger (*args)
75
+ Class.new do
76
+ def warn(*args)
77
+ #p args
78
+ end
79
+ alias_method :info, :warn
80
+ def warn?; end
81
+ alias_method :info?, :warn?
82
+ end.new
83
+ end
84
+ end
85
+
86
+ ActionController::Routing::Routes.draw do |map|
87
+ map.connect ':controller/:action/:id'
88
+ end
89
+ ActionController::Base.send :include, Authorization::AuthorizationInController
90
+ require "action_controller/test_process"
91
+
92
+ class Test::Unit::TestCase
93
+ def request! (user, action, reader, params = {})
94
+ action = action.to_sym if action.is_a?(String)
95
+ @controller.current_user = user
96
+ @controller.authorization_engine = Authorization::Engine.new(reader)
97
+
98
+ ((params.delete(:clear) || []) + [:@authorized]).each do |var|
99
+ @controller.instance_variable_set(var, nil)
100
+ end
101
+ get action, params
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uhees-declarative_authorization
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Steffen Bartsch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07: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: sbartsch@tzi.org
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - CHANGELOG
35
+ - MIT-LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - authorization_rules.dist.rb
39
+ - garlic_example.rb
40
+ - init.rb
41
+ - app/controllers/authorization_rules_controller.rb
42
+ - app/controllers/authorization_usages_controller.rb
43
+ - app/helpers/authorization_rules_helper.rb
44
+ - app/views/authorization_rules/_change.erb
45
+ - app/views/authorization_rules/_show_graph.erb
46
+ - app/views/authorization_rules/_suggestion.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.rb
63
+ - lib/declarative_authorization/maintenance.rb
64
+ - lib/declarative_authorization/obligation_scope.rb
65
+ - lib/declarative_authorization/rails_legacy.rb
66
+ - lib/declarative_authorization/reader.rb
67
+ - test/authorization_test.rb
68
+ - test/controller_test.rb
69
+ - test/development_support
70
+ - test/dsl_reader_test.rb
71
+ - test/helper_test.rb
72
+ - test/maintenance_test.rb
73
+ - test/model_test.rb
74
+ - test/schema.sql
75
+ - test/test_helper.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/stffn/declarative_authorization
78
+ licenses:
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.8.6
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 2
102
+ summary: declarative_authorization is a Rails plugin for authorization based on readable authorization rules.
103
+ test_files: []
104
+