tuersteher 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ .idea
data/Manifest ADDED
@@ -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
data/README.rdoc ADDED
@@ -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
+
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # Rakefile
2
+ require 'rubygems'
3
+ require 'rake'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "tuersteher"
9
+ gemspec.summary = "Security-Layer for Rails-Application"
10
+ gemspec.description = "Security-Layer for Rails-Application acts like a firewall."
11
+ gemspec.email = "bernd@ledig.info"
12
+ gemspec.homepage = "http://github.com/bledig/tuersteher"
13
+ gemspec.authors = ["Bernd Ledig"]
14
+ end
15
+ rescue LoadError
16
+ puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
17
+ end
18
+
19
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
20
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.6
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require "tuersteher"
data/lib/tuersteher.rb ADDED
@@ -0,0 +1,389 @@
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_accessor :rules_config_file # to set own access_rules-path
37
+
38
+ DEFAULT_RULES_CONFIG_FILE = File.join(Rails.root, 'config', 'access_rules.rb')
39
+
40
+ def initialize
41
+ @path_rules = []
42
+ @model_rules = []
43
+ end
44
+
45
+ def path_rules
46
+ read_rules unless @was_read
47
+ @path_rules
48
+ end
49
+
50
+ def model_rules
51
+ read_rules unless @was_read
52
+ @model_rules
53
+ end
54
+
55
+
56
+ # Laden der AccesRules aus den Dateien
57
+ # config/access_rules.rb
58
+ def read_rules
59
+ config_file = @rules_config_file || DEFAULT_RULES_CONFIG_FILE
60
+ rules_file = File.new config_file
61
+ if @last_mtime.nil? || rules_file.mtime > @last_mtime
62
+ @last_mtime = rules_file.mtime
63
+ content = rules_file.read
64
+ eval content
65
+ Tuersteher::TLogger.logger.info "Tuersteher::AccessRulesStorage: #{@path_rules.size} path-rules and #{@model_rules.size} model-rules"
66
+ end
67
+ rules_file.close
68
+ @was_read = true
69
+ end
70
+
71
+ # definiert HTTP-Pfad-basierende Zugriffsregel
72
+ #
73
+ # path: :all fuer beliebig, sonst String mit der http-path beginnen muss,
74
+ # wird als RegEX-Ausdruck ausgewertet
75
+ # method: http-Methode, es sind hier erlaubt :get, :put, :delete, :post, :all
76
+ # accepted_roles: Aufzaehlung der erfoderlichen Rolen (oder-Verknuepfung), es sind nur Symbole zulaessig
77
+ # hier ist auch ein Array von Symbolen möglich
78
+ def grant_path url_path, http_methode, *accepted_roles
79
+ @path_rules << PathAccessRule.new(url_path, http_methode, *accepted_roles)
80
+ end
81
+
82
+ # definiert HTTP-Pfad-basierende Ablehnungsregel
83
+ #
84
+ # path: :all fuer beliebig, sonst String mit der http-path beginnen muss,
85
+ # wird als RegEX-Ausdruck ausgewertet
86
+ # method: http-Methode, es sind hier erlaubt :get, :put, :delete, :post, :all
87
+ # accepted_roles: Aufzaehlung der erfoderlichen Rolen (oder-Verknuepfung), es sind nur Symbole zulaessig
88
+ # hier ist auch ein Array von Symbolen möglich
89
+ def deny_path url_path, http_methode, *accepted_roles
90
+ rule = PathAccessRule.new(url_path, http_methode, *accepted_roles)
91
+ rule.deny = true
92
+ @path_rules << rule
93
+ end
94
+
95
+ # definiert Model-basierende Zugriffsregel
96
+ #
97
+ # model_class: Model-Klassenname oder :all fuer alle
98
+ # access_type: Zugriffsart (:create, :update, :destroy, :all o.A. selbst definierte Typen)
99
+ # roles Aufzählung der erforderliche Rolen (:all für ist egal),
100
+ # hier ist auch ein Array von Symbolen möglich
101
+ # block optionaler Block, wird mit model und user aufgerufen und muss true oder false liefern
102
+ # hier ein Beispiel mit Block:
103
+ # <code>
104
+ # # Regel, in der sich jeder User selbst aendern darf
105
+ # grant_model(User, :update, :all){|model,user| model.id==user.id}
106
+ # </code>
107
+ #
108
+ def grant_model model_class, access_type, *roles, &block
109
+ @model_rules << ModelAccessRule.new(model_class, access_type, *roles, &block)
110
+ end
111
+
112
+ end
113
+
114
+ class AccessRules
115
+
116
+ # Pruefen Zugriff fuer eine Web-action
117
+ # user User, für den der Zugriff geprüft werden soll (muss Methode has_role? haben)
118
+ # path Pfad der Webresource (String)
119
+ # method http-Methode (:get, :put, :delete, :post), default ist :get
120
+ #
121
+ def self.path_access?(user, path, method = :get)
122
+ rule = AccessRulesStorage.instance.path_rules.detect do |r|
123
+ r.fired?(path, method, user)
124
+ end
125
+ if Tuersteher::TLogger.logger.debug?
126
+ if rule.nil?
127
+ s = 'denied'
128
+ elsif rule.deny
129
+ s = "denied with #{rule}"
130
+ else
131
+ s = "granted with #{rule}"
132
+ end
133
+ Tuersteher::TLogger.logger.debug("Tuersteher: path_access?(#{path}, #{method}) => #{s}")
134
+ end
135
+ rule!=nil && !rule.deny
136
+ end
137
+
138
+ # Pruefen Zugriff auf ein Model-Object
139
+ #
140
+ # user User, für den der Zugriff geprüft werden soll (muss Methode has_role? haben)
141
+ # model das Model-Object
142
+ # permission das geforderte Zugriffsrecht (:create, :update, :destroy, :get)
143
+ #
144
+ # liefert true/false
145
+ def self.model_access? user, model, permission
146
+ raise "Wrong call! Use: model_access(model-instance-or-class, permission)" unless permission.is_a? Symbol
147
+ return false unless model
148
+
149
+ access = AccessRulesStorage.instance.model_rules.detect do |rule|
150
+ rule.has_access? model, permission, user
151
+ end
152
+ if Tuersteher::TLogger.logger.debug?
153
+ if model.instance_of?(Class)
154
+ Tuersteher::TLogger.logger.debug("Tuersteher: model_access?(#{model}, #{permission}) => #{access ? access : 'denied'}")
155
+ else
156
+ Tuersteher::TLogger.logger.debug("Tuersteher: model_access?(#{model.class}(#{model.respond_to?(:id) ? model.id : model.object_id }), #{permission}) => #{access ? access : 'denied'}")
157
+ end
158
+ end
159
+ access!=nil
160
+ end
161
+ end
162
+
163
+
164
+
165
+ # Module zum Include in Controllers
166
+ # Dieser muss die folgenden Methoden bereitstellen:
167
+ #
168
+ # current_user : akt. Login-User
169
+ # access_denied : Methode aus dem authenticated_system, welche ein redirect zum login auslöst
170
+ #
171
+ # Der Loginuser muss fuer die hier benoetigte Funktionalitaet
172
+ # die Methode:
173
+ # has_role?(*roles) # roles is Array of Symbols
174
+ # besitzen.
175
+ #
176
+ # Beispiel der Einbindung in den ApplicationController
177
+ # include Tuersteher::ControllerExtensions
178
+ # before_filter :check_access # methode is from Tuersteher::ControllerExtensions
179
+ #
180
+ module ControllerExtensions
181
+
182
+
183
+ # Pruefen Zugriff fuer eine Web-action
184
+ #
185
+ # path Pfad der Webresource (String oder Hash mit Options)
186
+ # method http-Methode (:get, :put, :delete, :post), default ist :get
187
+ #
188
+ def path_access?(path, method = :get)
189
+
190
+ # ist path eine Hash (also der alte Stil mit :controller=> .., :action=>..)
191
+ # dann diese in ein http-path wandeln
192
+ path = url_for(path.merge(:only_path => true)) if path.instance_of?(Hash)
193
+
194
+ AccessRules.path_access? current_user, path, method
195
+ end
196
+
197
+ # Pruefen Zugriff auf ein Model-Object
198
+ #
199
+ # model das Model-Object
200
+ # permission das geforderte Zugriffsrecht (:create, :update, :destroy, :get)
201
+ #
202
+ # liefert true/false
203
+ def model_access? model, permission
204
+ AccessRules.model_access? current_user, model, permission
205
+ end
206
+
207
+ def self.included(base)
208
+ base.class_eval do
209
+ # Methoden path_access? und model_access? auch als Helper fuer die Views bereitstellen
210
+ helper_method :path_access?, :model_access?
211
+ end
212
+ end
213
+
214
+ protected
215
+
216
+ # Pruefen, ob Zugriff des current_user
217
+ # fuer aktullen Request erlaubt ist
218
+ def check_access
219
+
220
+ # im dev-mode rules bei jeden request auf Änderungen prüfen
221
+ AccessRulesStorage.instance.read_rules if Rails.env=='development'
222
+
223
+ unless path_access?(request.request_uri, request.method)
224
+ msg = "Tuersteher#check_access: access denied for #{request.request_uri} :#{request.method}"
225
+ Tuersteher::TLogger.logger.warn msg
226
+ logger.warn msg # log message also for Rails-Default logger
227
+ access_denied # Methode aus dem authenticated_system, welche ein redirect zum login auslöst
228
+ end
229
+ end
230
+
231
+ end
232
+
233
+
234
+ class PathAccessRule
235
+ attr_reader :path, :method, :roles
236
+ attr_accessor :deny
237
+
238
+ METHOD_NAMES = [:get, :edit, :put, :delete, :post, :all].freeze
239
+
240
+
241
+ # Zugriffsregel
242
+ #
243
+ # path :all fuer beliebig, sonst String mit der http-path beginnen muss
244
+ # method http-Methode, es sind hier erlaubt :get, :put, :delete, :post, :all
245
+ # needed_roles Aufzaehlung der erfoderlichen Rolen (oder-Verknuepfung), es sind nur Symbole zulaessig
246
+ #
247
+ def initialize(path, method, *needed_roles)
248
+ raise "wrong path '#{path}'! Must be a String or :all ." unless path==:all or path.is_a?(String)
249
+ raise "wrong method '#{method}'! Must be #{METHOD_NAMES.join(', ')} !" unless METHOD_NAMES.include?(method)
250
+ raise "needed_roles expected!" if needed_roles.empty?
251
+ @roles = needed_roles.flatten
252
+ for r in @roles
253
+ raise "wrong role '#{r}'! Must be a symbol " unless r.is_a?(Symbol)
254
+ end
255
+ @path = path
256
+ if path != :all
257
+ # path in regex ^#{path} wandeln ausser bei "/",
258
+ # dies darf keine Regex mit ^/ werden,
259
+ # da diese ja immer matchen wuerde
260
+ if path == "/"
261
+ @path = /^\/$/
262
+ else
263
+ @path = /^#{path}/
264
+ end
265
+ end
266
+ @method = method
267
+ end
268
+
269
+
270
+ # pruefen, ob Zugriff fuer angegebenen
271
+ # path / method fuer den current_user erlaubt ist
272
+ #
273
+ # user ist ein Object (meist der Loginuser),
274
+ # welcher die Methode 'has_role?(*roles)' besitzen muss.
275
+ # *roles ist dabei eine Array aus Symbolen
276
+ #
277
+ def fired?(path, method, user)
278
+ user = nil if user==:false # manche Authenticate-System setzen den user auf :false
279
+ if @path!=:all && !(@path =~ path)
280
+ return false
281
+ end
282
+
283
+ if @method!=:all && @method != method
284
+ return false
285
+ end
286
+
287
+ # ist jetzt role :all, dann prinzipiell Zugriff erlaubt
288
+ return true if @roles.first == :all
289
+
290
+ if user && user.has_role?(*@roles)
291
+ return true
292
+ end
293
+ false
294
+ end
295
+
296
+
297
+ def to_s
298
+ "PathAccesRule[#{@path}, #{@method}, #{@roles.join(' ')}#{@deny ? ' deny' : ''}]"
299
+ end
300
+
301
+ end
302
+
303
+
304
+
305
+ class ModelAccessRule
306
+ attr_reader :clazz, :access_type, :role, :block
307
+
308
+
309
+ # erzeugt neue Object-Zugriffsregel
310
+ #
311
+ # clazz Model-Klassenname oder :all fuer alle
312
+ # access_type Zugriffsart (:create, :update, :destroy, :all o.A. selbst definierte Typem)
313
+ # roles Aufzählung der erforderliche Rolen (:all für ist egal),
314
+ # hier ist auch ein Array von Symbolen möglich
315
+ # block optionaler Block, wird mit model und user aufgerufen und muss true oder false liefern
316
+ # hier ein Beispiel mit Block:
317
+ # <code>
318
+ # # Regel, in der sich jeder User selbst aendern darf
319
+ # ModelAccessRule.new(User, :update, :all){|model,user| model.id==user.id}
320
+ # </code>
321
+ #
322
+ def initialize(clazz, access_type, *roles, &block)
323
+ raise "wrong clazz '#{clazz}'! Must be a Class or :all ." unless clazz==:all or clazz.is_a?(Class)
324
+ raise "wrong access_type '#{ access_type}'! Must be a Symbol ." unless access_type.is_a?(Symbol)
325
+ @roles = roles.flatten
326
+ for r in @roles
327
+ raise "wrong role '#{r}'! Must be a symbol " unless r.is_a?(Symbol)
328
+ end
329
+ @clazz = clazz.instance_of?(Symbol) ? clazz : clazz.to_s
330
+ @access_type = access_type
331
+ @block = block
332
+ end
333
+
334
+ # liefert true, wenn zugriff fuer das angegebene model mit
335
+ # der Zugriffsart perm für das security_object hat
336
+ #
337
+ # model des zupruefende ModelObject
338
+ # perm gewunschte Zugriffsart (Symbol :create, :update, :destroy)
339
+ #
340
+ # user ist ein User-Object (meist der Loginuser),
341
+ # welcher die Methode 'has_role?(*roles)' besitzen muss.
342
+ # *roles ist dabei eine Array aus Symbolen
343
+ #
344
+ #
345
+ def has_access? model, perm, user
346
+ user = nil if user==:false # manche Authenticate-System setzen den user auf :false
347
+ m_class = model.instance_of?(Class) ? model : model.class
348
+ if @clazz!=m_class.to_s && @clazz!=:all
349
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why #{@clazz}!=#{model.class.to_s} && #{@clazz}!=:all")
350
+ return false
351
+ end
352
+
353
+ if @access_type!=:all && @access_type!=perm
354
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why #{@access_type}!=:all && #{@access_type}!=#{perm}")
355
+ return false
356
+ end
357
+
358
+ if @roles.first!=:all && (user.nil? || !user.has_role?(*@roles))
359
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why #{@roles.first}!=:all && #{!user.has_role?(*@roles)}")
360
+ return false
361
+ end
362
+
363
+ if @block
364
+ unless @block.call(model, user)
365
+ #Tuersteher::TLogger.logger.debug("#{to_s}.has_access? => false why block return false")
366
+ return false
367
+ end
368
+ end
369
+ true
370
+ end
371
+
372
+ def to_s
373
+ "ModelAccessRule[#{@clazz}, #{@access_type}, #{@roles.join(' ')}]"
374
+ end
375
+
376
+ end
377
+
378
+
379
+ # ActiveRecord erweitern mit
380
+ # Sicherheits-Check
381
+ #
382
+ # class ActiveRecord::Base
383
+ # before_create {|model| SecurityModule::SecurityService.check_model_access model, :create }
384
+ # before_update {|model| SecurityModule::SecurityService.check_model_access model, :update }
385
+ # before_destroy{|model| SecurityModule::SecurityService.check_model_access model, :destroy }
386
+ # end
387
+
388
+
389
+ end
data/license.txt ADDED
@@ -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
+ deny_path '/user/lock', :user
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,47 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{tuersteher}
8
+ s.version = "0.0.6"
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{2010-02-20}
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/tuersteher}
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
47
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tuersteher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Bernd Ledig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-20 00:00:00 +01: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: true
37
+ homepage: http://github.com/bledig/tuersteher
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Security-Layer for Rails-Application
64
+ test_files: []
65
+