bledig-tuersteher 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ pkg
2
+ .idea
@@ -0,0 +1,9 @@
1
+ lib/tuersteher.rb
2
+ Rakefile
3
+ init.rb
4
+ Manifest
5
+ tuersteher.gemspec
6
+ README.rdoc
7
+ samples/access_rules.rb
8
+ samples/application_controller.rb
9
+ license.txt
@@ -0,0 +1,43 @@
1
+
2
+ = Tuersteher
3
+ Security-Layer for Rails-Application acts like a firewall.
4
+ It's check your URL's or Modells to have the rights for this.
5
+
6
+ == Install
7
+
8
+ gem install bledig-tuersteher --source http://gems.github.org
9
+
10
+
11
+ == Usage
12
+
13
+ Create in your Rails-Application the rules-file "config/access_rules.rb"
14
+ (or copy the sample from samples-directory and modify)
15
+
16
+ Here is as small sample for "config/access_rules.rb"
17
+
18
+ # Path-Acces-Rules
19
+ grant_path '/', :get, :all
20
+ grant_path '/admin-area/', :all, :ADMIN
21
+
22
+ # Model-Acces-Rules
23
+ grant_model Product, :view, :all
24
+ grant_model Product, :update, :EDITOR do |product, current_user|
25
+ product.owner_id == current_user.id
26
+ end
27
+
28
+ Then extend your ApplicationController with:
29
+
30
+ include Tuersteher::ControllerExtensions
31
+ before_filter :check_access # methode is from Tuersteher::ControllerExtensions
32
+
33
+ Check if your authendicate-system has implemented the methods:
34
+
35
+ * current_user
36
+ * access_denied
37
+
38
+ If not, just implemen it (see samples/application_controller.rb)
39
+
40
+ == License
41
+
42
+ LGPL V3 (see license.txt)
43
+
@@ -0,0 +1,35 @@
1
+ # Rakefile
2
+ require 'rubygems'
3
+ require 'rake'
4
+
5
+ =begin
6
+
7
+ require 'echoe'
8
+
9
+ Echoe.new('tuersteher', '0.0.5') do |p|
10
+ p.description = "Security-Layer for Rails-Application acts like a firewall."
11
+ p.url = "http://github.com/bledig/tuersteher"
12
+ p.author = "Bernd Ledig"
13
+ p.email = "bernd@ledig.info"
14
+ p.ignore_pattern = ["tmp/*", "script/*"]
15
+ p.development_dependencies = []
16
+ end
17
+
18
+ =end
19
+
20
+ begin
21
+ require 'jeweler'
22
+ Jeweler::Tasks.new do |gemspec|
23
+ gemspec.name = "tuersteher"
24
+ gemspec.summary = "Security-Layer for Rails-Application"
25
+ gemspec.description = "Security-Layer for Rails-Application acts like a firewall."
26
+ gemspec.email = "bernd@ledig.info"
27
+ gemspec.homepage = "http://github.com/bledig/tuerstehe"
28
+ gemspec.authors = ["Bernd Ledig"]
29
+ end
30
+ rescue LoadError
31
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
32
+ end
33
+
34
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
35
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require "tuersteher"
@@ -0,0 +1,340 @@
1
+ # Module, welches AccesRules fuer Controller/Actions und
2
+ # Model-Object umsetzt.
3
+ #
4
+ # Die Regeln werden aus der Datei "config/acces_rules.rb" geladen
5
+ #
6
+ # Author: Bernd Ledig
7
+ #
8
+
9
+ require 'singleton'
10
+
11
+ module Tuersteher
12
+
13
+ # Logger to log messages with timestamp and severity
14
+ class TLogger < Logger
15
+ @@logger = nil
16
+
17
+ def format_message(severity, timestamp, progname, msg)
18
+ "#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
19
+ end
20
+
21
+ def self.logger
22
+ return @@logger if @@logger
23
+ @@logger = self.new(File.join(Rails.root, 'log', 'tuersteher.log'), 3)
24
+ @@logger.level = INFO if Rails.env != 'development'
25
+ @@logger
26
+ end
27
+
28
+ def self.logger= logger
29
+ @@logger = logger
30
+ end
31
+ end
32
+
33
+ class AccessRulesStorage
34
+ include Singleton
35
+
36
+ attr_reader :path_rules, :model_rules
37
+ attr_accessor :rules_config_file # to set own access_rules-path
38
+
39
+ DEFAULT_RULES_CONFIG_FILE = File.join(Rails.root, 'config', 'access_rules.rb')
40
+
41
+ def initialize
42
+ @path_rules = []
43
+ @model_rules = []
44
+ end
45
+
46
+ # Laden der AccesRules aus den Dateien
47
+ # config/access_rules.rb
48
+ # In der development-Enviroment wird diese nach jeder Änderung
49
+ # neu geladen, sonst nur einmal
50
+ def load_access_rules
51
+ return if @was_read && Rails.env!='development'
52
+ read_rules
53
+ end
54
+
55
+ def read_rules
56
+ config_file = @rules_config_file || DEFAULT_RULES_CONFIG_FILE
57
+ rules_file = File.new config_file
58
+ if @last_mtime.nil? || rules_file.mtime > @last_mtime
59
+ @last_mtime = rules_file.mtime
60
+ content = rules_file.read
61
+ eval content
62
+ Tuersteher::TLogger.logger.info "Tuersteher::AccessRulesStorage: #{@path_rules.size} path-rules and #{@model_rules.size} model-rules"
63
+ end
64
+ rules_file.close
65
+ @was_read = true
66
+ end
67
+
68
+ # definiert HTTP-Pfad-basierende Zugriffsregel
69
+ #
70
+ # path: :all fuer beliebig, sonst String mit der http-path beginnen muss,
71
+ # wird als RegEX-Ausdruck ausgewertet
72
+ # method: http-Methode, es sind hier erlaubt :get, :put, :delete, :post, :all
73
+ # accepted_roles: Aufzaehlung der erfoderlichen Rolen (oder-Verknuepfung), es sind nur Symbole zulaessig
74
+ # hier ist auch ein Array von Symbolen möglich
75
+ def grant_path url_path, http_methode, *accepted_roles
76
+ @path_rules << PathAccessRule.new(url_path, http_methode, *accepted_roles)
77
+ end
78
+
79
+ # definiert Model-basierende Zugriffsregel
80
+ #
81
+ # model_class: Model-Klassenname oder :all fuer alle
82
+ # access_type: Zugriffsart (:create, :update, :destroy, :all o.A. selbst definierte Typen)
83
+ # roles Aufzählung der erforderliche Rolen (:all für ist egal),
84
+ # hier ist auch ein Array von Symbolen möglich
85
+ # block optionaler Block, wird mit model und user aufgerufen und muss true oder false liefern
86
+ # hier ein Beispiel mit Block:
87
+ # <code>
88
+ # # Regel, in der sich jeder User selbst aendern darf
89
+ # grant_model(User, :update, :all){|model,user| model.id==user.id}
90
+ # </code>
91
+ #
92
+ def grant_model model_class, access_type, *roles, &block
93
+ @model_rules << ModelAccessRule.new(model_class, access_type, *roles, &block)
94
+ end
95
+
96
+ end
97
+
98
+
99
+
100
+ # Module zum Include in Controllers
101
+ # Dieser muss die folgenden Methoden bereitstellen:
102
+ #
103
+ # current_user : akt. Login-User
104
+ # access_denied : Methode aus dem authenticated_system, welche ein redirect zum login auslöst
105
+ #
106
+ # Der Loginuser muss fuer die hier benoetigte Funktionalitaet
107
+ # die Methode:
108
+ # has_role?(*roles) # roles is Array of Symbols
109
+ # besitzen.
110
+ #
111
+ # Beispiel der Einbindung in den ApplicationController
112
+ # include Tuersteher::ControllerExtensions
113
+ # before_filter :check_access # methode is from Tuersteher::ControllerExtensions
114
+ #
115
+ module ControllerExtensions
116
+
117
+
118
+ # Pruefen Zugriff fuer eine Web-action
119
+ #
120
+ # path Pfad der Webresource (String oder Hash mit Options)
121
+ # method http-Methode (:get, :put, :delete, :post), default ist :get
122
+ #
123
+ def path_access?(path, method = :get)
124
+
125
+ # ist path eine Hash (also der alte Stil mit :controller=> .., :action=>..)
126
+ # dann diese in ein http-path wandeln
127
+ path = url_for(path.merge(:only_path => true)) if path.instance_of?(Hash)
128
+
129
+ AccessRulesStorage.instance.load_access_rules # das load cached automatisch
130
+ acr = AccessRulesStorage.instance.path_rules.detect do |rule|
131
+ rule.has_access?(path, method, current_user)
132
+ end
133
+ if Tuersteher::TLogger.logger.debug?
134
+ s = acr!=nil ? "granted with #{acr}" : 'denied'
135
+ Tuersteher::TLogger.logger.debug("Tuersteher: path_access?(#{path}, #{method}) => #{s}")
136
+ end
137
+ acr!=nil
138
+ end
139
+
140
+ # Pruefen Zugriff auf ein Model-Object
141
+ #
142
+ # model das Model-Object
143
+ # permission das geforderte Zugriffsrecht (:create, :update, :destroy, :get)
144
+ #
145
+ # liefert true/false
146
+ def model_access? model, permission
147
+ return false unless model
148
+
149
+ AccessRulesStorage.instance.load_access_rules # das load cached automatisch
150
+ access = AccessRulesStorage.instance.model_rules.detect do |rule|
151
+ rule.has_access? model, permission, current_user
152
+ end
153
+ if Tuersteher::TLogger.logger.debug?
154
+ if model.instance_of?(Class)
155
+ Tuersteher::TLogger.logger.debug("Tuersteher: model_access?(#{model}, #{permission}) => #{access ? access : 'denied'}")
156
+ else
157
+ Tuersteher::TLogger.logger.debug("Tuersteher: model_access?(#{model.class}(#{model.respond_to?(:id) ? model.id : model.object_id }), #{permission}) => #{access ? access : 'denied'}")
158
+ end
159
+ end
160
+ access!=nil
161
+ end
162
+
163
+ def self.included(base)
164
+ base.class_eval do
165
+ # Methoden path_access? und model_access? auch als Helper fuer die Views bereitstellen
166
+ helper_method :path_access?, :model_access?
167
+ end
168
+ end
169
+
170
+ protected
171
+
172
+ # Pruefen, ob Zugriff des current_user
173
+ # fuer aktullen Request erlaubt ist
174
+ def check_access
175
+ unless path_access?(request.request_uri, request.method)
176
+ msg = "Tuersteher#check_access: access denied for #{request.request_uri} :#{request.method}"
177
+ Tuersteher::TLogger.logger.warn msg
178
+ logger.warn msg # log message also for Rails-Default logger
179
+ access_denied # Methode aus dem authenticated_system, welche ein redirect zum login auslöst
180
+ end
181
+ end
182
+
183
+ end
184
+
185
+
186
+ class PathAccessRule
187
+ attr_reader :path, :method, :roles
188
+
189
+ METHOD_NAMES = [:get, :edit, :put, :delete, :post, :all].freeze
190
+
191
+
192
+ # Zugriffsregel
193
+ #
194
+ # path :all fuer beliebig, sonst String mit der http-path beginnen muss
195
+ # method http-Methode, es sind hier erlaubt :get, :put, :delete, :post, :all
196
+ # needed_roles Aufzaehlung der erfoderlichen Rolen (oder-Verknuepfung), es sind nur Symbole zulaessig
197
+ #
198
+ def initialize(path, method, *needed_roles)
199
+ raise "wrong path '#{path}'! Must be a String or :all ." unless path==:all or path.is_a?(String)
200
+ raise "wrong method '#{method}'! Must be #{METHOD_NAMES.join(', ')} !" unless METHOD_NAMES.include?(method)
201
+ raise "needed_roles expected!" if needed_roles.empty?
202
+ @roles = needed_roles.flatten
203
+ for r in @roles
204
+ raise "wrong role '#{r}'! Must be a symbol " unless r.is_a?(Symbol)
205
+ end
206
+ @path = path
207
+ if path != :all
208
+ # path in regex ^#{path} wandeln ausser bei "/",
209
+ # dies darf keine Regex mit ^/ werden,
210
+ # da diese ja immer matchen wuerde
211
+ if path == "/"
212
+ @path = /^\/$/
213
+ else
214
+ @path = /^#{path}/
215
+ end
216
+ end
217
+ @method = method
218
+ end
219
+
220
+
221
+ # pruefen, ob Zugriff fuer angegebenen
222
+ # path / method fuer den current_user erlaubt ist
223
+ #
224
+ # user ist ein Object (meist der Loginuser),
225
+ # welcher die Methode 'has_role?(*roles)' besitzen muss.
226
+ # *roles ist dabei eine Array aus Symbolen
227
+ #
228
+ def has_access?(path, method, user)
229
+ user = nil if user==:false # manche Authenticate-System setzen den user auf :false
230
+ if @path!=:all && !(@path =~ path)
231
+ return false
232
+ end
233
+
234
+ if @method!=:all && @method != method
235
+ return false
236
+ end
237
+
238
+ # ist jetzt role :all, dann prinzipiell Zugriff erlaubt
239
+ return true if @roles.first == :all
240
+
241
+ if user && user.has_role?(*@roles)
242
+ return true
243
+ end
244
+ false
245
+ end
246
+
247
+
248
+ def to_s
249
+ "PathAccesRule[#{@path}, #{@method}, #{@roles.join(' ')}]"
250
+ end
251
+
252
+ end
253
+
254
+
255
+
256
+ class ModelAccessRule
257
+ attr_reader :clazz, :access_type, :role, :block
258
+
259
+
260
+ # erzeugt neue Object-Zugriffsregel
261
+ #
262
+ # clazz Model-Klassenname oder :all fuer alle
263
+ # access_type Zugriffsart (:create, :update, :destroy, :all o.A. selbst definierte Typem)
264
+ # roles Aufzählung der erforderliche Rolen (:all für ist egal),
265
+ # hier ist auch ein Array von Symbolen möglich
266
+ # block optionaler Block, wird mit model und user aufgerufen und muss true oder false liefern
267
+ # hier ein Beispiel mit Block:
268
+ # <code>
269
+ # # Regel, in der sich jeder User selbst aendern darf
270
+ # ModelAccessRule.new(User, :update, :all){|model,user| model.id==user.id}
271
+ # </code>
272
+ #
273
+ def initialize(clazz, access_type, *roles, &block)
274
+ raise "wrong clazz '#{clazz}'! Must be a Class or :all ." unless clazz==:all or clazz.is_a?(Class)
275
+ raise "wrong access_type '#{ access_type}'! Must be a Symbol ." unless access_type.is_a?(Symbol)
276
+ @roles = roles.flatten
277
+ for r in @roles
278
+ raise "wrong role '#{r}'! Must be a symbol " unless r.is_a?(Symbol)
279
+ end
280
+ @clazz = clazz.instance_of?(Symbol) ? clazz : clazz.to_s
281
+ @access_type = access_type
282
+ @block = block
283
+ end
284
+
285
+ # liefert true, wenn zugriff fuer das angegebene model mit
286
+ # der Zugriffsart perm für das security_object hat
287
+ #
288
+ # model des zupruefende ModelObject
289
+ # perm gewunschte Zugriffsart (Symbol :create, :update, :destroy)
290
+ #
291
+ # user ist ein User-Object (meist der Loginuser),
292
+ # welcher die Methode 'has_role?(*roles)' besitzen muss.
293
+ # *roles ist dabei eine Array aus Symbolen
294
+ #
295
+ #
296
+ def has_access? model, perm, user
297
+ user = nil if user==:false # manche Authenticate-System setzen den user auf :false
298
+ m_class = model.instance_of?(Class) ? model : model.class
299
+ if @clazz!=m_class.to_s && @clazz!=:all
300
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why #{@clazz}!=#{model.class.to_s} && #{@clazz}!=:all")
301
+ return false
302
+ end
303
+
304
+ if @access_type!=:all && @access_type!=perm
305
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why #{@access_type}!=:all && #{@access_type}!=#{perm}")
306
+ return false
307
+ end
308
+
309
+ if @roles.first!=:all && (user.nil? || !user.has_role?(*@roles))
310
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why #{@roles.first}!=:all && #{!user.has_role?(*@roles)}")
311
+ return false
312
+ end
313
+
314
+ if @block
315
+ unless @block.call(model, user)
316
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why block return false")
317
+ return false
318
+ end
319
+ end
320
+ true
321
+ end
322
+
323
+ def to_s
324
+ "ModelAccessRule[#{@clazz}, #{@access_type}, #{@roles.join(' ')}]"
325
+ end
326
+
327
+ end
328
+
329
+
330
+ # ActiveRecord erweitern mit
331
+ # Sicherheits-Check
332
+ #
333
+ # class ActiveRecord::Base
334
+ # before_create {|model| SecurityModule::SecurityService.check_model_access model, :create }
335
+ # before_update {|model| SecurityModule::SecurityService.check_model_access model, :update }
336
+ # before_destroy{|model| SecurityModule::SecurityService.check_model_access model, :destroy }
337
+ # end
338
+
339
+
340
+ end
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,30 @@
1
+ # derzeit genutzte Rollen:
2
+ # * ADMIN
3
+ # * EDITOR
4
+ # * APPROVER
5
+ # * USER
6
+
7
+
8
+ #
9
+ # Pfad-Zugriffsregeln
10
+ # Aufbau:
11
+ # Path : URL-Pfad, wird als regex ausgewertet
12
+ # Methode : :all, :get, :put, :post, :delete oder :edit
13
+ # roles :Liste der berechtigten Rollen (es können mehrere Rollen durch Komma getrennt angegeben werden)
14
+ #
15
+ grant_path '/', :get, :all
16
+ grant_path :all, :all, :ADMIN
17
+
18
+
19
+ #
20
+ # Model-Object-Zugriffsregeln
21
+ # Aufbau:
22
+ # Model-Klasse : Klasse des Models
23
+ # Zugriffsart : frei definierbares Symbol, empfohlen :update, :create, :destroy
24
+ # Roles : Aufzählung der Rollen
25
+ # Block : optionaler Block, diesem wird die Model-Instance und der User als Parameter bereitgestellt
26
+
27
+ grant_model String, :view, :all
28
+ grant_model String, :view, :ADMIN, :EDITOR
29
+ grant_model String, :update, :EDITOR do |model, user| model == user.name end
30
+
@@ -0,0 +1,26 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+
4
+
5
+ include Tuersteher::ControllerExtensions
6
+ before_filter :check_access # methode is from Tuersteher::ControllerExtensions
7
+
8
+ # This method need Tuersteher for his rules-check
9
+ # It should return a User-Object, which have a method "has_role?"
10
+ #
11
+ # This is here a dummy Stub-Implementation
12
+ def current_user
13
+ user = Object.new
14
+ def user.has_role?(*roles)
15
+ true
16
+ end
17
+ user
18
+ end
19
+
20
+ # This Method is called from Tuersteher if access are denied (no grant rules fired)
21
+ # stub Authentication-Methode
22
+ def access_denied
23
+ redirect_to "/"
24
+ end
25
+
26
+ end
@@ -0,0 +1,46 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tuersteher}
8
+ s.version = "0.0.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Bernd Ledig"]
12
+ s.date = %q{2009-08-11}
13
+ s.description = %q{Security-Layer for Rails-Application acts like a firewall.}
14
+ s.email = %q{bernd@ledig.info}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "Manifest",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "init.rb",
25
+ "lib/tuersteher.rb",
26
+ "license.txt",
27
+ "samples/access_rules.rb",
28
+ "samples/application_controller.rb",
29
+ "tuersteher.gemspec"
30
+ ]
31
+ s.homepage = %q{http://github.com/bledig/tuerstehe}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Security-Layer for Rails-Application}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ else
43
+ end
44
+ else
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bledig-tuersteher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Bernd Ledig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-11 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Security-Layer for Rails-Application acts like a firewall.
17
+ email: bernd@ledig.info
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - .gitignore
26
+ - Manifest
27
+ - README.rdoc
28
+ - Rakefile
29
+ - VERSION
30
+ - init.rb
31
+ - lib/tuersteher.rb
32
+ - license.txt
33
+ - samples/access_rules.rb
34
+ - samples/application_controller.rb
35
+ - tuersteher.gemspec
36
+ has_rdoc: false
37
+ homepage: http://github.com/bledig/tuerstehe
38
+ licenses:
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Security-Layer for Rails-Application
63
+ test_files: []
64
+