annotation_security 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/CHANGELOG.md +14 -0
  2. data/HOW-TO.md +275 -0
  3. data/{MIT-LICENSE → LICENSE} +1 -1
  4. data/README.md +39 -0
  5. data/Rakefile +62 -55
  6. data/assets/app/helpers/annotation_security_helper.rb +8 -8
  7. data/assets/config/initializers/annotation_security.rb +11 -11
  8. data/assets/config/security/relations.rb +20 -20
  9. data/assets/vendor/plugins/annotation_security/init.rb +13 -13
  10. data/bin/annotation_security +7 -7
  11. data/lib/annotation_security/exceptions.rb +124 -124
  12. data/lib/annotation_security/exec.rb +188 -188
  13. data/lib/annotation_security/filters.rb +37 -37
  14. data/lib/annotation_security/includes/action_controller.rb +144 -143
  15. data/lib/annotation_security/includes/active_record.rb +27 -27
  16. data/lib/annotation_security/includes/helper.rb +215 -215
  17. data/lib/annotation_security/includes/resource.rb +84 -84
  18. data/lib/annotation_security/includes/role.rb +30 -30
  19. data/lib/annotation_security/includes/user.rb +26 -26
  20. data/lib/annotation_security/manager/policy_factory.rb +29 -29
  21. data/lib/annotation_security/manager/policy_manager.rb +79 -79
  22. data/lib/annotation_security/manager/relation_loader.rb +272 -272
  23. data/lib/annotation_security/manager/resource_manager.rb +36 -36
  24. data/lib/annotation_security/manager/right_loader.rb +87 -87
  25. data/lib/annotation_security/model_observer.rb +61 -61
  26. data/lib/annotation_security/policy/abstract_policy.rb +344 -344
  27. data/lib/annotation_security/policy/abstract_static_policy.rb +75 -75
  28. data/lib/annotation_security/policy/all_resources_policy.rb +20 -20
  29. data/lib/annotation_security/policy/rule.rb +340 -340
  30. data/lib/annotation_security/policy/rule_set.rb +138 -138
  31. data/lib/annotation_security/rails.rb +38 -38
  32. data/lib/annotation_security/user_wrapper.rb +73 -73
  33. data/lib/annotation_security/utils.rb +141 -141
  34. data/lib/annotation_security/version.rb +10 -0
  35. data/lib/annotation_security.rb +102 -97
  36. data/lib/extensions/action_controller.rb +32 -32
  37. data/lib/extensions/active_record.rb +34 -34
  38. data/lib/extensions/filter.rb +133 -133
  39. data/lib/extensions/object.rb +10 -10
  40. data/lib/security_context.rb +589 -551
  41. data/spec/annotation_security/exceptions_spec.rb +16 -16
  42. data/spec/annotation_security/includes/helper_spec.rb +82 -82
  43. data/spec/annotation_security/manager/policy_manager_spec.rb +15 -15
  44. data/spec/annotation_security/manager/resource_manager_spec.rb +17 -17
  45. data/spec/annotation_security/manager/right_loader_spec.rb +17 -17
  46. data/spec/annotation_security/policy/abstract_policy_spec.rb +16 -16
  47. data/spec/annotation_security/policy/all_resources_policy_spec.rb +24 -24
  48. data/spec/annotation_security/policy/rule_set_spec.rb +112 -112
  49. data/spec/annotation_security/policy/rule_spec.rb +77 -77
  50. data/spec/annotation_security/policy/test_policy_spec.rb +80 -80
  51. data/spec/annotation_security/security_context_spec.rb +78 -78
  52. data/spec/annotation_security/utils_spec.rb +73 -73
  53. data/spec/helper/test_controller.rb +65 -65
  54. data/spec/helper/test_helper.rb +5 -5
  55. data/spec/helper/test_relations.rb +6 -6
  56. data/spec/helper/test_resource.rb +38 -38
  57. data/spec/helper/test_role.rb +21 -21
  58. data/spec/helper/test_user.rb +31 -31
  59. data/spec/rails_stub.rb +37 -37
  60. metadata +94 -72
  61. data/CHANGELOG +0 -2
  62. data/HOW-TO +0 -261
  63. data/README +0 -39
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ Changelog
2
+ =========
3
+
4
+ 1.0.2
5
+ -----
6
+
7
+ * dropped rails 2.3.8 support in favour of rails 2.3.18 support
8
+ * updated docs
9
+
10
+
11
+ 1.0.1
12
+ -----
13
+
14
+ * first public release
data/HOW-TO.md ADDED
@@ -0,0 +1,275 @@
1
+ # How to secure your Rails application with Annotation Security
2
+
3
+ ## Step 0: Install Annotation Security
4
+
5
+ Annotation Security comes as a gem hosted on rubygems.org. You can install it
6
+ via `gem install annotation_security`.
7
+ The gem contains a binary called `annotation_security`. It can be used to
8
+ install the security layer into a rails app via
9
+ `annotation_security --rails RAILS_HOME`. This will make your app ready to be
10
+ secured.
11
+
12
+ ### Version Notes
13
+
14
+ Use the gem version < 2 for Rails 2.3.x applications.
15
+ Use the gem version 3.x for Rails 3.x applications.
16
+
17
+ ## Step 1: Defining user and roles
18
+
19
+ Annotation Security assumes that there is a user class, representing the user,
20
+ and some role classes containing additional information if the user has a
21
+ certain role in the application.
22
+
23
+ If you don't have user or role classes in your application,
24
+ continue with step 2.
25
+
26
+ ### User
27
+
28
+ In most cases the user class will be a subclass of `ActiveRecord::Base`,
29
+ but this is not necessary.
30
+
31
+ Include the `module AnnotationSecurity::User` into this class.
32
+
33
+ class User < ActiveRecord::Base
34
+ include AnnotationSecurity::User
35
+ ...
36
+
37
+ ### Roles
38
+
39
+ Include the module `AnnotationSecurity::Role` into these classes. If you are
40
+ having a hierachy of role classes, only include the module in the topmost class.
41
+
42
+ class Role < ActiveRecord::Base
43
+ belongs_to :user
44
+ include AnnotationSecurity::Role
45
+ ...
46
+
47
+ class Student < Role
48
+ # no include here
49
+ ...
50
+
51
+ A role object should respond to `user` with returning the user object
52
+ it belongs to.
53
+
54
+ __Do not include both modules in one class!__
55
+
56
+ ### Connecting user and roles
57
+
58
+ As next, you should provide some default methods for accessing the roles
59
+ of a user. You can skip this step, but it will be helpfull later on.
60
+
61
+ There are two types of access methods: `is_ROLE?` and `as_ROLE`.
62
+
63
+ IS-methods return true or false whether a user has a role or not.
64
+
65
+ class User < ActiveRecord::Base
66
+ def is_administrator?
67
+ self.admin_flag == 1
68
+ end
69
+
70
+ def is_student?
71
+ self.roles.any? { |role| role.is_a? Student }
72
+ end
73
+ ...
74
+
75
+ AS-methods return a single object or an array of objects representing the role.
76
+ If the user does not have the role, the result should be an empty array or nil.
77
+
78
+ class User < ActiveRecord::Base
79
+ def as_administrator
80
+ # there is no administrator class, just return the user
81
+ is_administrator? ? self : nil
82
+ end
83
+
84
+ def as_student
85
+ # assuming a user can only be student once
86
+ self.roles.detect { |role| role.is_a? Student }
87
+ end
88
+
89
+ def as_corrector
90
+ # assuming a user can be a corrector several times
91
+ self.roles.select { |role| role.is_a? Corrector }
92
+ end
93
+
94
+ ## Step 2: Providing the current credential
95
+
96
+ To evaluate the security policies, for each request the current credential has
97
+ to be provided. Therefore, a new filter type was introduced: security filters
98
+ are around filters that are always the first in the filter chain. You can also
99
+ use these filters to react to security violations.
100
+
101
+ In this example, the user is simply fetched from the session. However, you
102
+ could also pass a symbol or a string (e.g. if you are using API-keys).
103
+
104
+ Passing `nil` will be interpreted as not being authenticated in any way.
105
+
106
+ class ApplicationController < ActionController::Base
107
+
108
+ security_filter :security_filter
109
+
110
+ private
111
+
112
+ def security_filter
113
+ SecurityContext.current_credential = session[:user]
114
+ yield
115
+ rescue SecurityViolationError
116
+ if SecurityContext.is? :logged_in
117
+ render :template => "welcome/not_allowed"
118
+ else
119
+ render :template => "welcome/please_login"
120
+ end
121
+ end
122
+
123
+ Please notice that once set, the credential cannot be changed.
124
+
125
+ ## Step 3: Defining your resources
126
+
127
+ Another wild assumption we made is that your application contains some resources
128
+ you want to protect. In most cases, this will be your ActiveRecord classes.
129
+ To turn them into resources, just call `resource(symbol)` in the class
130
+ definition.
131
+
132
+ class Course < ActiveRecord::Base
133
+ resource :course
134
+ ...
135
+
136
+ The symbol is used to further identify this class and should be unique.
137
+
138
+ It is possible (and likely) that the users and roles are resources as well.
139
+
140
+ If you want to restrict access to other resource classes, see
141
+ `AnnotationSecurity::Resource` for more information.
142
+
143
+ ## Step 4: Defining relations and rights
144
+
145
+ in `config/security` you will find the files `relations.rb` and
146
+ `rights.yml`.
147
+
148
+ ### Relations
149
+
150
+ The relations between the user (or the roles) and the resources are defined
151
+ as code blocks, that evaluate to true or false.
152
+
153
+ The `:as`-flag causes that instead of the user object, a role object
154
+ will be passed into the block (using the `as_ROLE`-method from above).
155
+ Similar, the `:is`-flag can be used as precondition.
156
+
157
+ AnnotationSecurity.define_relations do
158
+ resource :course do
159
+ enrolled :as => :student { |student,course| course.students.include? student }
160
+ corrector :as => :corrector { |corrector,course| corrector.corrects? course }
161
+ lecturer :as => :lecturer { |lecturer,course| lecturer.lectures? course }
162
+ end
163
+ ...
164
+
165
+ You can also define relations that are valid for all resources.
166
+
167
+ all_resources do
168
+ # corrector and lecturer are defined by the resource
169
+ responsible { corrector or lecturer }
170
+ # no block required here
171
+ administrator :is => :administrator
172
+ end
173
+
174
+ For more details and features on defining relations,
175
+ see `AnnotationSecurity::RelationLoader`.
176
+
177
+ ### Rights
178
+
179
+ The rights of application are specified in a YAML-file, they correspond to the
180
+ actions(not necessarily the controller actions) that can be performed on a
181
+ resource. For instance, to edit a course object, you will need the edit-right
182
+ for the course resource. If you are not sure which rights your application
183
+ needs, just skip this now and return after step 5.
184
+
185
+ Rights should be valid ruby conditional statements.
186
+
187
+ course:
188
+ create: if lecturer
189
+ show: if enrolled or responsible
190
+ edit: if responsible
191
+
192
+ AnnotationSecurity provides two default relations: `logged_in`, that is true
193
+ if there is a user at all, and +self+, that can be used to determine if a user
194
+ or role resource belongs to the current user.
195
+
196
+ user:
197
+ register: unless logged_in
198
+ show: if logged_in
199
+ edit: if self or administrator
200
+ student:
201
+ show_results: if self
202
+
203
+ To improve readability, you can append 'may', 'is', 'can' or 'has' as prefix and
204
+ 'for', 'in', 'of' or 'to' as suffix to the relation name.
205
+ This is especially recommended if you are defining rights that depend on
206
+ other rights of the resource.
207
+
208
+ assignment:
209
+ edit: if responsible
210
+ delete: if may_edit
211
+
212
+ Another example can be found at `AnnotationSecurity::RightLoader`.
213
+
214
+ ## Step 5: Securing your actions
215
+
216
+ The main goal of AnnotationSecurity was to remove security logic from
217
+ controller actions. Now you only have to define the abstract effects of an
218
+ action.
219
+
220
+ An action performs one or more tasks on different resources. You have to provide
221
+ this information as a descriptions, using the
222
+ [Action Annotation Gem](http://github.com/Nikku/action_annotation).
223
+ A description always has the form 'ACTION on RESOURCE'.
224
+
225
+ desc 'shows a course'
226
+ def show
227
+ @course = Course.find(params[:id])
228
+ end
229
+
230
+ To perform a task, the user must have the right for it. Thus, when a course is
231
+ fetched from the database during the show-action, the right course/show will be
232
+ evaluated for the current user and the course instance.
233
+
234
+ In our example, the user has to be responsible or enrolled. If both relations
235
+ evaluate to false, the right is not given and access will be denied by raising
236
+ a SecurityViolationError, which will then be catched in the security filter.
237
+
238
+ Congratulations, you Rails application is secured now.
239
+
240
+ ## Step 6: Securing your views
241
+
242
+ However, actions aren't the only place with security code. Links to the actions
243
+ are shown in the view and very often, the view itself depends on the
244
+ user's rights.
245
+
246
+ When setting up Annotation Security in your Rails project, a helper will be
247
+ included automatically. The most important functions this helper provides are
248
+ `allowed?` and `link_to_if_allowed`.
249
+
250
+ The method `allowed?` expects a right and a resource and returns true iif
251
+ the current user has that right.
252
+
253
+ <% unless allowed? :edit, @course %>
254
+ <p>You may not edit this course!</p>
255
+ <% end %>
256
+
257
+ `link_to_if_allowed` expects the same arguments as +link_to+, except it also
258
+ expects a block like +link_to_if+ (which will be called internally).
259
+
260
+ <%= link_to_if_allowed("New", new_course_path) { "You may not create a new course." } %>
261
+ <%= link_to_if_allowed("Edit", edit_course_path(@course)) { } %>
262
+ <%= link_to_if_allowed("Delete", @course, {:method => :delete}) { } %>
263
+
264
+ `link_to_if_allowed` tries to automatically detect the accessed resources.
265
+ In case this should not work for you, see `AnnotationSecurity::Helper` for more
266
+ features.
267
+
268
+ ## Step 7: Live long and prosper
269
+
270
+ Well, that's it. Here are some additional notes:
271
+
272
+ * in development mode, the rights and relations are reloaded with every request.
273
+ * See `AnnotationSecurity::RelationLoader` and `AnnotationSecurity::RightLoader`
274
+ for more examples and features for defining relations and rights.
275
+ * See `AnnotationSecurity::Helper` for more methods for securing your views.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Nico Rehwaldt, Arian Treffer
1
+ Copyright (c) 2009, 2010, 2013 Nico Rehwaldt, Arian Treffer
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Resource Based security for Rails applications
2
+
3
+ This plugin provides a thin security layer for rails applications. It performs access
4
+ checks based on a behavioural description of controller actions. Security rules
5
+ are defined on a resource model which is cleanly separated from your models and controllers.
6
+
7
+ ## Installation steps
8
+
9
+ The security layer is a gem and may be installed using
10
+ `gem install annotation_security`.
11
+
12
+ After installing the gem, run `annotation_security --rails RAILS_HOME` to
13
+ integrate the security layer in your rails app. Along with the
14
+ annotation_security plugin this will add
15
+
16
+ * the `AnnotationSecurity::Helper` in the `app/helpers` folder of your
17
+ rails-app. It provides some useful methods to create links and query the
18
+ security layer from views.
19
+ * example configuration files to setup the security layer under `config/security`
20
+ * an initializer for the security layer under `config/initializer`
21
+
22
+ ## Where to start
23
+
24
+ Check out the basic introduction on [how to secure your application](HOW-TO.md).
25
+ In order to get a detailed idea about how things work, have a deeper look
26
+ inside `AnnotationSecurity::ActionController` (how to secure your application),
27
+ `AnnotationSecurity::RightLoader` (how to setup rights) and
28
+ `AnnotationSecurity::RelationLoader` (how to setup relations).
29
+
30
+ Have a look at the view methods provided by the `AnnotationSecurity::Helper` as
31
+ well and at the `SecurityContext` which is the main entry-point for security related
32
+ functionality in the layer.
33
+
34
+ ## License
35
+
36
+ Copyright Nico Rehwaldt, Arian Treffer 2009, 2010, 2013
37
+
38
+ You may use, copy and redistribute this library under the same terms as
39
+ [Ruby itself](http://www.ruby-lang.org/en/LICENSE.txt) or under the MIT license.
data/Rakefile CHANGED
@@ -1,56 +1,63 @@
1
- #
2
- # To change this template, choose Tools | Templates
3
- # and open the template in the editor.
4
-
5
-
6
- require 'rubygems'
7
- require 'rake'
8
- require 'rake/clean'
9
- require 'rake/gempackagetask'
10
- require 'rake/rdoctask'
11
- require 'spec/rake/spectask'
12
-
13
- spec = Gem::Specification.new do |s|
14
- s.name = 'annotation_security'
15
- s.version = '1.0.1'
16
- s.has_rdoc = true
17
- s.extra_rdoc_files = ['README', 'MIT-LICENSE', 'CHANGELOG', 'HOW-TO']
18
- s.summary = 'A role based security model for rails applications with ' +
19
- 'descriptive definitions and automated evaluation.'
20
- s.description =
21
- 'AnnotationSecurity provides a role based security model with automated ' +
22
- 'rule evaluation for Ruby on Rails. It allows you to define user-resource-'+
23
- 'relations and rights in separate files, keeping your controllers and ' +
24
- 'views free from any security logic. See the gem\'s homepage for an ' +
25
- 'example.'
26
- s.author = 'Nico Rehwaldt, Arian Treffer'
27
- s.email = 'ruby@nixis.de'
28
- s.homepage = 'http://tech.lefedt.de/2010/3/annotation-based-security-for-rails'
29
- s.add_dependency 'action_annotation', '>= 1.0.1'
30
- s.add_dependency 'activesupport', '>= 2.3.5'
31
- s.add_development_dependency 'rspec', '>= 1.2.0'
32
- s.add_development_dependency 'mocha', '>= 0.9.8'
33
- s.executables = ['annotation_security']
34
- s.files = %w(CHANGELOG MIT-LICENSE README HOW-TO Rakefile) + Dir.glob("{bin,lib,spec,assets}/**/*")
35
- s.require_path = "lib"
36
- s.bindir = "bin"
37
- end
38
-
39
- Rake::GemPackageTask.new(spec) do |p|
40
- p.gem_spec = spec
41
- p.need_tar = true
42
- p.need_zip = true
43
- end
44
-
45
- Rake::RDocTask.new do |rdoc|
46
- files = ['README', 'MIT-LICENSE', 'CHANGELOG', 'HOW-TO', 'lib/**/*.rb']
47
- rdoc.rdoc_files.add(files)
48
- rdoc.main = "README" # page to start on
49
- rdoc.title = "Annotation Security Docs"
50
- rdoc.rdoc_dir = 'doc' # rdoc output folder
51
- rdoc.options << '--line-numbers'
52
- end
53
-
54
- Spec::Rake::SpecTask.new do |t|
55
- t.spec_files = FileList['spec/**/*_spec.rb']
1
+ require 'rubygems'
2
+ require 'rubygems/package_task'
3
+
4
+ require 'rake'
5
+ require 'rake/clean'
6
+
7
+ require 'rdoc/task'
8
+
9
+ require 'rspec/core/rake_task'
10
+
11
+ require File.dirname(__FILE__) + '/lib/annotation_security/version'
12
+
13
+ module RakeFileUtils
14
+ extend Rake::FileUtilsExt
15
+ end
16
+
17
+ spec = Gem::Specification.new do |s|
18
+ s.name = 'annotation_security'
19
+ s.version = AnnotationSecurity::Version
20
+ s.has_rdoc = true
21
+ s.extra_rdoc_files = ['README.md', 'LICENSE', 'CHANGELOG.md', 'HOW-TO.md']
22
+ s.summary = 'A role based security model for rails applications with ' +
23
+ 'descriptive definitions and automated evaluation.'
24
+ s.description =
25
+ 'AnnotationSecurity provides a role based security model with automated ' +
26
+ 'rule evaluation for Ruby on Rails. It allows you to define user-resource-'+
27
+ 'relations and rights in separate files, keeping your controllers and ' +
28
+ 'views free from any security logic. See the gem\'s homepage for an ' +
29
+ 'example.'
30
+ s.author = 'Nico Rehwaldt, Arian Treffer'
31
+ s.email = 'ruby@nixis.de'
32
+ s.homepage = 'http://github.com/Nikku/annotation_security'
33
+ s.add_dependency 'action_annotation', '>= 1.0.1'
34
+ s.add_dependency 'activesupport', '>= 2.3.18'
35
+ s.add_development_dependency 'rspec', '>= 1.3.2'
36
+ s.add_development_dependency 'mocha', '>= 0.9.8'
37
+ s.executables = ['annotation_security']
38
+ s.files = %w(CHANGELOG.md LICENSE README.md HOW-TO.md Rakefile) + Dir.glob("{bin,lib,spec,assets}/**/*")
39
+ s.require_path = "lib"
40
+ s.bindir = "bin"
41
+ end
42
+
43
+ desc "Create rdoc documentation"
44
+ Rake::RDocTask.new do |rdoc|
45
+ files = ['README.md', 'LICENSE', 'CHANGELOG.md', 'HOW-TO.md', 'lib/**/*.rb']
46
+ rdoc.rdoc_files.add(files)
47
+ rdoc.main = "README.md" # page to start on
48
+ rdoc.title = "Annotation Security Docs"
49
+ rdoc.rdoc_dir = 'doc' # rdoc output folder
50
+ rdoc.options << '--line-numbers'
51
+ end
52
+
53
+ desc "Run rspec tests"
54
+ RSpec::Core::RakeTask.new do |t|
55
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
56
+ t.pattern = 'spec/**/*_spec.rb'
57
+ end
58
+
59
+ desc "Package library as gem"
60
+ Gem::PackageTask.new(spec) do |pkg|
61
+ pkg.need_zip = true
62
+ pkg.need_tar = true
56
63
  end
@@ -1,9 +1,9 @@
1
- #
2
- # = app/helpers/annotation_security_helper.rb
3
- #
4
- # This helper provides some useful view methods to be used in conjunction with
5
- # the plugin. See AnnotationSecurity::Helper for documentation.
6
- #
7
- module AnnotationSecurityHelper
8
- include AnnotationSecurity::Helper
1
+ #
2
+ # = app/helpers/annotation_security_helper.rb
3
+ #
4
+ # This helper provides some useful view methods to be used in conjunction with
5
+ # the plugin. See AnnotationSecurity::Helper for documentation.
6
+ #
7
+ module AnnotationSecurityHelper
8
+ include AnnotationSecurity::Helper
9
9
  end
@@ -1,12 +1,12 @@
1
- #
2
- # = config/initializers/annotation_security.rb
3
- #
4
- # Sets up files under <tt>config/security</tt> which hold
5
- # the security configuration.
6
-
7
- #
8
- # Add your own files here if they should also be loaded.
9
- #
10
- AnnotationSecurity.load_relations('relations')
11
- AnnotationSecurity.load_rights('rights')
1
+ #
2
+ # = config/initializers/annotation_security.rb
3
+ #
4
+ # Sets up files under <tt>config/security</tt> which hold
5
+ # the security configuration.
6
+
7
+ #
8
+ # Add your own files here if they should also be loaded.
9
+ #
10
+ AnnotationSecurity.load_relations('relations')
11
+ AnnotationSecurity.load_rights('rights')
12
12
  # AnnotationSecurity.load_rights('rights', 'rb) # loads rights from a ruby file
@@ -1,20 +1,20 @@
1
- AnnotationSecurity.define_relations do
2
-
3
- # All relations are defined in the context of a resource.
4
- # The block should return true iif the user has this relations.
5
-
6
- # all_resources do
7
- # administrator(:system, :is => :administrator)
8
- # owner_or_admin(:pretest){ owner or administrator }
9
- # owner(:system) { |user| user.status == :registered }
10
- # end
11
-
12
- # resource :album do
13
- # owner { |user, album| album.owner == user }
14
- # end
15
-
16
- # resource :picture do
17
- # owner "if owner: album"
18
- # end
19
-
20
- end
1
+ AnnotationSecurity.define_relations do
2
+
3
+ # All relations are defined in the context of a resource.
4
+ # The block should return true iif the user has this relations.
5
+
6
+ # all_resources do
7
+ # administrator(:system, :is => :administrator)
8
+ # owner_or_admin(:pretest){ owner or administrator }
9
+ # owner(:system) { |user| user.status == :registered }
10
+ # end
11
+
12
+ # resource :album do
13
+ # owner { |user, album| album.owner == user }
14
+ # end
15
+
16
+ # resource :picture do
17
+ # owner "if owner: album"
18
+ # end
19
+
20
+ end
@@ -1,14 +1,14 @@
1
- #
2
- # = init.rb
3
- #
4
- # This file will be copied to a rails apps `vendors/plugins/annotation_security`
5
- # directory if the annotation_security gem is installed into a rails app
6
- # via `annosec --rails`. It will be invoked by the rails app during startup an
7
- # loads the security layer.
8
- #
9
-
10
- require "annotation_security"
11
-
12
- # Initialize security layer for rails root
13
- puts "Initializing AnnotationSecurity security layer"
1
+ #
2
+ # = init.rb
3
+ #
4
+ # This file will be copied to a rails apps `vendors/plugins/annotation_security`
5
+ # directory if the annotation_security gem is installed into a rails app
6
+ # via `annosec --rails`. It will be invoked by the rails app during startup an
7
+ # loads the security layer.
8
+ #
9
+
10
+ require "annotation_security"
11
+
12
+ # Initialize security layer for rails root
13
+ puts "Initializing AnnotationSecurity security layer"
14
14
  AnnotationSecurity::init_rails(binding)
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env ruby
2
- # The command line to install .
3
-
4
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
-
6
- require "annotation_security/exec"
7
-
1
+ #!/usr/bin/env ruby
2
+ # The command line to install .
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+
6
+ require "annotation_security/exec"
7
+
8
8
  AnnotationSecurity::Exec::RailsInstaller.new(ARGV).parse!