arsecurity 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Rakefile +1 -1
- data/lib/arsecurity.rb +1 -0
- data/lib/arsecurity_default.rb +10 -2
- data/lib/arsecurity_permission.rb +3 -3
- data/lib/arsecurity_util.rb +12 -12
- metadata +2 -2
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
data/lib/arsecurity.rb
CHANGED
data/lib/arsecurity_default.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'arsecurity'
|
2
|
+
require 'arsecurity_handler'
|
3
3
|
module ArsecurityDefault
|
4
4
|
#value can be regexp, symbol or string
|
5
5
|
CLASS_READ_METHOD = ["find_every", "count"]
|
@@ -22,6 +22,14 @@ end
|
|
22
22
|
|
23
23
|
class DefaultArsecurityHandler < ArsecurityHandler
|
24
24
|
class << self
|
25
|
+
#for customize logic, such as for administrator
|
26
|
+
def accept?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
#for customize logic, such as for time restriction
|
30
|
+
def reject?
|
31
|
+
false
|
32
|
+
end
|
25
33
|
def get_conditions(invocation)
|
26
34
|
case invocation.method
|
27
35
|
when *ArsecurityDefault::CLASS_READ_METHOD
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class ArsecurityPermission
|
2
|
-
attr_accessor :
|
2
|
+
attr_accessor :target_class_name, :operation, :instance_condition, :sql_condition
|
3
3
|
def initialize(permission)
|
4
|
-
@
|
5
|
-
@
|
4
|
+
@target_class_name = permission[:target_class_name]
|
5
|
+
@operation = permission[:operation]
|
6
6
|
@instance_condition = permission[:instance_condition]
|
7
7
|
@sql_condition = permission[:sql_condition]
|
8
8
|
end
|
data/lib/arsecurity_util.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
class ArsecurityUtil
|
2
2
|
class << self
|
3
3
|
attr_accessor :handler
|
4
|
-
def authorized?(
|
4
|
+
def authorized?(operation, target_class_name, instance, invocation)
|
5
5
|
return true if handler.accept?
|
6
6
|
return false if handler.reject?
|
7
7
|
result = false
|
8
8
|
permissions = handler.permissions
|
9
9
|
|
10
10
|
unless permissions.nil? || permissions.empty?
|
11
|
-
result = check_permissions(permissions,
|
11
|
+
result = check_permissions(permissions, operation, target_class_name, instance, invocation)
|
12
12
|
end
|
13
13
|
result
|
14
14
|
end
|
15
15
|
|
16
|
-
def check_permissions(permissions,
|
16
|
+
def check_permissions(permissions, operation, target_class_name, instance, invocation)
|
17
17
|
|
18
18
|
permissions.each do |permission|
|
19
19
|
permission = ArsecurityPermission.new(permission) if permission.is_a?(Hash)
|
20
|
-
next if permission.
|
21
|
-
unless permission.
|
22
|
-
next if permission.
|
20
|
+
next if permission.target_class_name != target_class_name
|
21
|
+
unless permission.operation.nil?
|
22
|
+
next if permission.operation != operation
|
23
23
|
end
|
24
24
|
#instance not nil mean persist
|
25
25
|
|
@@ -27,7 +27,7 @@ class ArsecurityUtil
|
|
27
27
|
if permission.instance_condition.nil? || permission.instance_condition.empty?
|
28
28
|
return true
|
29
29
|
else
|
30
|
-
result = ERB.new("<% result = (#{permission.instance_condition}) ? true : false %><%= result %>").result(
|
30
|
+
result = ERB.new("<% result = (#{permission.instance_condition}) ? true : false %><%= result %>").result(instance.send(:binding))
|
31
31
|
return true if result == 'true'
|
32
32
|
end
|
33
33
|
else
|
@@ -63,17 +63,17 @@ class ArsecurityUtil
|
|
63
63
|
false
|
64
64
|
end
|
65
65
|
|
66
|
-
def has_permission(permission,
|
67
|
-
return false if permission.
|
66
|
+
def has_permission(permission, operation, target_class_name, instance)
|
67
|
+
return false if permission.target_class_name != target_class_name
|
68
68
|
|
69
|
-
unless permission.
|
70
|
-
return false if permission.
|
69
|
+
unless permission.operation.nil?
|
70
|
+
return false if permission.operation != operation
|
71
71
|
end
|
72
72
|
|
73
73
|
if permission.instance_condition.blank?
|
74
74
|
return true
|
75
75
|
else
|
76
|
-
result = ERB.new("<% result = (#{permission.instance_condition}) ? true : false %><%= result %>").result(
|
76
|
+
result = ERB.new("<% result = (#{permission.instance_condition}) ? true : false %><%= result %>").result(instance.send(:binding))
|
77
77
|
return result == 'true'
|
78
78
|
end
|
79
79
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arsecurity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Li
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-28 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|