tarsolya-declarative_authorization 0.4.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 +139 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +503 -0
  4. data/Rakefile +43 -0
  5. data/app/controllers/authorization_rules_controller.rb +259 -0
  6. data/app/controllers/authorization_usages_controller.rb +23 -0
  7. data/app/helpers/authorization_rules_helper.rb +218 -0
  8. data/app/views/authorization_rules/_change.erb +58 -0
  9. data/app/views/authorization_rules/_show_graph.erb +37 -0
  10. data/app/views/authorization_rules/_suggestions.erb +48 -0
  11. data/app/views/authorization_rules/change.html.erb +169 -0
  12. data/app/views/authorization_rules/graph.dot.erb +68 -0
  13. data/app/views/authorization_rules/graph.html.erb +40 -0
  14. data/app/views/authorization_rules/index.html.erb +17 -0
  15. data/app/views/authorization_usages/index.html.erb +36 -0
  16. data/authorization_rules.dist.rb +20 -0
  17. data/config/routes.rb +7 -0
  18. data/garlic_example.rb +20 -0
  19. data/init.rb +5 -0
  20. data/lib/declarative_authorization.rb +15 -0
  21. data/lib/declarative_authorization/authorization.rb +681 -0
  22. data/lib/declarative_authorization/development_support/analyzer.rb +252 -0
  23. data/lib/declarative_authorization/development_support/change_analyzer.rb +253 -0
  24. data/lib/declarative_authorization/development_support/change_supporter.rb +620 -0
  25. data/lib/declarative_authorization/development_support/development_support.rb +243 -0
  26. data/lib/declarative_authorization/helper.rb +60 -0
  27. data/lib/declarative_authorization/in_controller.rb +623 -0
  28. data/lib/declarative_authorization/in_model.rb +162 -0
  29. data/lib/declarative_authorization/maintenance.rb +198 -0
  30. data/lib/declarative_authorization/obligation_scope.rb +345 -0
  31. data/lib/declarative_authorization/rails_legacy.rb +14 -0
  32. data/lib/declarative_authorization/reader.rb +496 -0
  33. data/test/authorization_test.rb +971 -0
  34. data/test/controller_filter_resource_access_test.rb +511 -0
  35. data/test/controller_test.rb +465 -0
  36. data/test/dsl_reader_test.rb +173 -0
  37. data/test/helper_test.rb +171 -0
  38. data/test/maintenance_test.rb +46 -0
  39. data/test/model_test.rb +1694 -0
  40. data/test/schema.sql +54 -0
  41. data/test/test_helper.rb +137 -0
  42. metadata +118 -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
+ );
@@ -0,0 +1,137 @@
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
+ DA_ROOT = Pathname.new(File.expand_path("..", File.dirname(__FILE__)))
11
+
12
+ require DA_ROOT + File.join(%w{lib declarative_authorization rails_legacy})
13
+ require DA_ROOT + File.join(%w{lib declarative_authorization authorization})
14
+ require DA_ROOT + File.join(%w{lib declarative_authorization in_controller})
15
+ require DA_ROOT + File.join(%w{lib declarative_authorization maintenance})
16
+
17
+ unless defined?(ActiveRecord)
18
+ if File.directory? RAILS_ROOT + '/config'
19
+ puts 'Using config/boot.rb'
20
+ ENV['RAILS_ENV'] = 'test'
21
+ require File.join(RAILS_ROOT, 'config', 'environment.rb')
22
+ else
23
+ # simply use installed gems if available
24
+ version_requirement = ENV['RAILS_VERSION'] ? "= #{ENV['RAILS_VERSION']}" : "> 2.1.0"
25
+ puts "Using Rails from RubyGems (#{version_requirement || "default"})"
26
+ require 'rubygems'
27
+ %w{actionpack activerecord activesupport rails}.each do |gem_name|
28
+ gem gem_name, version_requirement
29
+ end
30
+ end
31
+
32
+ unless defined?(Rails) # needs to be explicit in Rails < 3
33
+ %w(action_pack action_controller active_record active_support initializer).each {|f| require f}
34
+ end
35
+ end
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
+ ActionController::Routing::Routes.draw do |map|
117
+ map.connect ':controller/:action/:id'
118
+ end
119
+ ActionController::Base.send :include, Authorization::AuthorizationInController
120
+ if Rails.version < "3"
121
+ require "action_controller/test_process"
122
+ end
123
+
124
+ class Test::Unit::TestCase
125
+ include Authorization::TestHelper
126
+
127
+ def request! (user, action, reader, params = {})
128
+ action = action.to_sym if action.is_a?(String)
129
+ @controller.current_user = user
130
+ @controller.authorization_engine = Authorization::Engine.new(reader)
131
+
132
+ ((params.delete(:clear) || []) + [:@authorized]).each do |var|
133
+ @controller.instance_variable_set(var, nil)
134
+ end
135
+ get action, params
136
+ end
137
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tarsolya-declarative_authorization
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 1
9
+ version: 0.4.1
10
+ platform: ruby
11
+ authors:
12
+ - Steffen Bartsch
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-16 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rails
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 0
31
+ version: 2.1.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description:
35
+ email: sbartsch@tzi.org
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.rdoc
42
+ - CHANGELOG
43
+ files:
44
+ - CHANGELOG
45
+ - MIT-LICENSE
46
+ - README.rdoc
47
+ - Rakefile
48
+ - authorization_rules.dist.rb
49
+ - garlic_example.rb
50
+ - init.rb
51
+ - app/controllers/authorization_rules_controller.rb
52
+ - app/controllers/authorization_usages_controller.rb
53
+ - app/helpers/authorization_rules_helper.rb
54
+ - app/views/authorization_rules/_change.erb
55
+ - app/views/authorization_rules/_show_graph.erb
56
+ - app/views/authorization_rules/_suggestions.erb
57
+ - app/views/authorization_rules/change.html.erb
58
+ - app/views/authorization_rules/graph.dot.erb
59
+ - app/views/authorization_rules/graph.html.erb
60
+ - app/views/authorization_rules/index.html.erb
61
+ - app/views/authorization_usages/index.html.erb
62
+ - config/routes.rb
63
+ - lib/declarative_authorization.rb
64
+ - lib/declarative_authorization/authorization.rb
65
+ - lib/declarative_authorization/development_support/analyzer.rb
66
+ - lib/declarative_authorization/development_support/change_analyzer.rb
67
+ - lib/declarative_authorization/development_support/change_supporter.rb
68
+ - lib/declarative_authorization/development_support/development_support.rb
69
+ - lib/declarative_authorization/helper.rb
70
+ - lib/declarative_authorization/in_controller.rb
71
+ - lib/declarative_authorization/in_model.rb
72
+ - lib/declarative_authorization/maintenance.rb
73
+ - lib/declarative_authorization/obligation_scope.rb
74
+ - lib/declarative_authorization/rails_legacy.rb
75
+ - lib/declarative_authorization/reader.rb
76
+ - test/authorization_test.rb
77
+ - test/controller_filter_resource_access_test.rb
78
+ - test/controller_test.rb
79
+ - test/dsl_reader_test.rb
80
+ - test/helper_test.rb
81
+ - test/maintenance_test.rb
82
+ - test/model_test.rb
83
+ - test/schema.sql
84
+ - test/test_helper.rb
85
+ has_rdoc: true
86
+ homepage: http://github.com/stffn/declarative_authorization
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 1
100
+ - 8
101
+ - 6
102
+ version: 1.8.6
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.6
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: declarative_authorization is a Rails plugin for authorization based on readable authorization rules.
117
+ test_files: []
118
+