walruz 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/Rakefile +10 -4
- data/VERSION.yml +1 -1
- data/lib/walruz/config.rb +19 -0
- data/lib/walruz/exceptions.rb +42 -0
- data/lib/walruz/manager.rb +1 -1
- data/lib/walruz.rb +12 -63
- data/spec/walruz/manager_spec.rb +29 -0
- data/walruz.gemspec +15 -3
- metadata +27 -6
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
* 0.0.10 (Aug 26, 2009) Walruz wanted to be an actor too...
|
2
|
+
* Fixed bug related to Walruz::NotAuthorized info, the actor was Walruz
|
3
|
+
instead of the current actor, when the authorization was being called from
|
4
|
+
the Walruz.authorize! method
|
5
|
+
* Removed all the exceptions declaration from the walruz main file, and put
|
6
|
+
them on a specific file called lib/exceptions.rb
|
7
|
+
* Removed the Config class from the walruz main file, and put it on a specific
|
8
|
+
file called lib/config.rb
|
9
|
+
|
10
|
+
|
1
11
|
* 0.0.9 (Aug 24, 2009) Policies deserve some love too
|
2
12
|
* Renamed the Walruz::Manager.check_authorization to
|
3
13
|
Walruz::Manager.check_action_authorization
|
data/Rakefile
CHANGED
@@ -5,19 +5,25 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "walruz"
|
8
|
-
gem.summary = %Q{Walruz is a gem that provides an easy
|
8
|
+
gem.summary = %Q{Walruz is a gem that provides an easy yet powerful way to implement authorization policies in a system, relying on the composition of simple policies to create more complex ones.}
|
9
|
+
gem.description = %Q{
|
10
|
+
Walruz provides an easy to use DSL to do composition of basic authorization policies to create
|
11
|
+
more complex ones, and then register this composed policies on actions performed to the model begin accessed
|
12
|
+
}
|
9
13
|
gem.email = "roman@noomi.com"
|
10
14
|
gem.homepage = "http://github.com/noomii/walruz"
|
11
15
|
gem.authors = ["Roman Gonzalez"]
|
12
16
|
gem.rubyforge_project = "walruz"
|
13
17
|
gem.has_rdoc = 'yard'
|
18
|
+
|
19
|
+
gem.add_development_dependency("rspec")
|
20
|
+
gem.add_development_dependency("yard")
|
14
21
|
|
15
22
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
23
|
end
|
17
24
|
|
18
|
-
Jeweler::
|
19
|
-
|
20
|
-
end
|
25
|
+
Jeweler::GemcutterTasks.new
|
26
|
+
Jeweler::RubyforgeTasks.new
|
21
27
|
|
22
28
|
rescue LoadError
|
23
29
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION.yml
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Walruz
|
2
|
+
|
3
|
+
class Config
|
4
|
+
|
5
|
+
def actors=(actors)
|
6
|
+
Array(actors).each do |actor|
|
7
|
+
actor.send(:include, Actor)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def subjects=(subjects)
|
12
|
+
Array(subjects).each do |subject|
|
13
|
+
subject.send(:include, Subject)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Walruz
|
2
|
+
|
3
|
+
class NotAuthorized < Exception
|
4
|
+
|
5
|
+
attr_reader :actor
|
6
|
+
attr_reader :subject
|
7
|
+
attr_reader :action
|
8
|
+
|
9
|
+
def initialize(actor, subject, action, error_message = nil)
|
10
|
+
@actor = actor
|
11
|
+
@subject = subject
|
12
|
+
@action = action
|
13
|
+
|
14
|
+
if error_message.nil?
|
15
|
+
super
|
16
|
+
else
|
17
|
+
super(error_message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
class PolicyHalted < Exception
|
24
|
+
end
|
25
|
+
|
26
|
+
class AuthorizationActionsNotDefined < Exception
|
27
|
+
end
|
28
|
+
|
29
|
+
class ActionNotFound < Exception
|
30
|
+
|
31
|
+
def initialize(failure, params = {})
|
32
|
+
case failure
|
33
|
+
when :subject_action
|
34
|
+
super("%s class doesn't have an authorization action called :%s nor a :default policy" % [params[:subject].class.name, params[:action]])
|
35
|
+
when :policy_label
|
36
|
+
super("There is no Policy with the label %s" % params[:label])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/walruz/manager.rb
CHANGED
@@ -19,7 +19,7 @@ module Walruz
|
|
19
19
|
else
|
20
20
|
response_params = result[1]
|
21
21
|
error_message = response_params[:error_message] || "You are not authorized to access this content"
|
22
|
-
raise NotAuthorized.new(
|
22
|
+
raise NotAuthorized.new(actor, subject, action, error_message)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/walruz.rb
CHANGED
@@ -1,45 +1,8 @@
|
|
1
1
|
module Walruz
|
2
2
|
|
3
|
-
class NotAuthorized < Exception
|
4
|
-
|
5
|
-
attr_reader :actor
|
6
|
-
attr_reader :subject
|
7
|
-
attr_reader :action
|
8
|
-
|
9
|
-
def initialize(actor, subject, action, error_message = nil)
|
10
|
-
@actor = actor
|
11
|
-
@subject = subject
|
12
|
-
@action = action
|
13
|
-
|
14
|
-
if error_message.nil?
|
15
|
-
super
|
16
|
-
else
|
17
|
-
super(error_message)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
class PolicyHalted < Exception
|
24
|
-
end
|
25
|
-
|
26
|
-
class AuthorizationActionsNotDefined < Exception
|
27
|
-
end
|
28
|
-
|
29
|
-
class ActionNotFound < Exception
|
30
|
-
|
31
|
-
def initialize(failure, params = {})
|
32
|
-
case failure
|
33
|
-
when :subject_action
|
34
|
-
super("%s class doesn't have an authorization action called :%s nor a :default policy" % [params[:subject].class.name, params[:action]])
|
35
|
-
when :policy_label
|
36
|
-
super("There is no Policy with the label %s" % params[:label])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
3
|
base_path = File.dirname(__FILE__)
|
4
|
+
require base_path + '/walruz/exceptions'
|
5
|
+
autoload :Config, base_path + '/walruz/config'
|
43
6
|
autoload :Memoization, base_path + '/walruz/core_ext/memoization'
|
44
7
|
autoload :Manager, base_path + '/walruz/manager'
|
45
8
|
autoload :Actor, base_path + '/walruz/actor'
|
@@ -47,6 +10,16 @@ module Walruz
|
|
47
10
|
autoload :Policy, base_path + '/walruz/policy'
|
48
11
|
autoload :Utils, base_path + '/walruz/utils'
|
49
12
|
|
13
|
+
# including the Walruz::Manager::AuthorizationQuery methods
|
14
|
+
extend Manager::AuthorizationQuery
|
15
|
+
class << self
|
16
|
+
include Memoization
|
17
|
+
walruz_memoize :can?, :authorize, :satisfies?, :satisfies
|
18
|
+
end
|
19
|
+
|
20
|
+
#############################
|
21
|
+
### Global Walruz Methods ###
|
22
|
+
#############################
|
50
23
|
|
51
24
|
def self.version
|
52
25
|
require "yaml"
|
@@ -80,30 +53,6 @@ module Walruz
|
|
80
53
|
policy_clz
|
81
54
|
end
|
82
55
|
|
83
|
-
class Config
|
84
|
-
|
85
|
-
def actors=(actors)
|
86
|
-
Array(actors).each do |actor|
|
87
|
-
actor.send(:include, Actor)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def subjects=(subjects)
|
92
|
-
Array(subjects).each do |subject|
|
93
|
-
subject.send(:include, Subject)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
# including the Walruz::Manager::AuthorizationQuery methods
|
100
|
-
|
101
|
-
extend Manager::AuthorizationQuery
|
102
|
-
class << self
|
103
|
-
include Memoization
|
104
|
-
walruz_memoize :can?, :authorize, :satisfies?, :satisfies
|
105
|
-
end
|
106
|
-
|
107
56
|
end
|
108
57
|
|
109
58
|
require File.dirname(__FILE__) + '/walruz/core_ext/array'
|
data/spec/walruz/manager_spec.rb
CHANGED
@@ -21,5 +21,34 @@ describe Walruz::Manager do
|
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
|
+
describe "::AuthorizationQuery" do
|
25
|
+
|
26
|
+
describe "when excuting the authorize! method" do
|
27
|
+
|
28
|
+
describe "and the actor is not authorized" do
|
29
|
+
|
30
|
+
it "should raise a Walruz::NotAuthorized exception" do
|
31
|
+
lambda do
|
32
|
+
Walruz.authorize!(Beatle::RINGO, :sing, Song::YESTERDAY)
|
33
|
+
end.should raise_error(Walruz::NotAuthorized)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should raise a Walruz::NotAuthorized exception with info about the actor, subject and action" do
|
37
|
+
begin
|
38
|
+
Walruz.authorize!(Beatle::RINGO, :sing, Song::YESTERDAY)
|
39
|
+
rescue Walruz::NotAuthorized => e
|
40
|
+
e.actor.should == Beatle::RINGO
|
41
|
+
e.subject.should == Song::YESTERDAY
|
42
|
+
e.action.should == :sing
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
24
53
|
|
25
54
|
end
|
data/walruz.gemspec
CHANGED
@@ -5,11 +5,15 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{walruz}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Roman Gonzalez"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-03-11}
|
13
|
+
s.description = %q{
|
14
|
+
Walruz provides an easy to use DSL to do composition of basic authorization policies to create
|
15
|
+
more complex ones, and then register this composed policies on actions performed to the model begin accessed
|
16
|
+
}
|
13
17
|
s.email = %q{roman@noomi.com}
|
14
18
|
s.extra_rdoc_files = [
|
15
19
|
"LICENSE",
|
@@ -25,8 +29,10 @@ Gem::Specification.new do |s|
|
|
25
29
|
"VERSION.yml",
|
26
30
|
"lib/walruz.rb",
|
27
31
|
"lib/walruz/actor.rb",
|
32
|
+
"lib/walruz/config.rb",
|
28
33
|
"lib/walruz/core_ext/array.rb",
|
29
34
|
"lib/walruz/core_ext/memoization.rb",
|
35
|
+
"lib/walruz/exceptions.rb",
|
30
36
|
"lib/walruz/manager.rb",
|
31
37
|
"lib/walruz/policy.rb",
|
32
38
|
"lib/walruz/subject.rb",
|
@@ -50,7 +56,7 @@ Gem::Specification.new do |s|
|
|
50
56
|
s.require_paths = ["lib"]
|
51
57
|
s.rubyforge_project = %q{walruz}
|
52
58
|
s.rubygems_version = %q{1.3.5}
|
53
|
-
s.summary = %q{Walruz is a gem that provides an easy
|
59
|
+
s.summary = %q{Walruz is a gem that provides an easy yet powerful way to implement authorization policies in a system, relying on the composition of simple policies to create more complex ones.}
|
54
60
|
s.test_files = [
|
55
61
|
"spec/scenario.rb",
|
56
62
|
"spec/spec_helper.rb",
|
@@ -69,8 +75,14 @@ Gem::Specification.new do |s|
|
|
69
75
|
s.specification_version = 3
|
70
76
|
|
71
77
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
78
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
79
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
72
80
|
else
|
81
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
82
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
73
83
|
end
|
74
84
|
else
|
85
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
86
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
75
87
|
end
|
76
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: walruz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Gonzalez
|
@@ -9,11 +9,30 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-11 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: "\n Walruz provides an easy to use DSL to do composition of basic authorization policies to create\n more complex ones, and then register this composed policies on actions performed to the model begin accessed\n "
|
17
36
|
email: roman@noomi.com
|
18
37
|
executables: []
|
19
38
|
|
@@ -32,8 +51,10 @@ files:
|
|
32
51
|
- VERSION.yml
|
33
52
|
- lib/walruz.rb
|
34
53
|
- lib/walruz/actor.rb
|
54
|
+
- lib/walruz/config.rb
|
35
55
|
- lib/walruz/core_ext/array.rb
|
36
56
|
- lib/walruz/core_ext/memoization.rb
|
57
|
+
- lib/walruz/exceptions.rb
|
37
58
|
- lib/walruz/manager.rb
|
38
59
|
- lib/walruz/policy.rb
|
39
60
|
- lib/walruz/subject.rb
|
@@ -77,7 +98,7 @@ rubyforge_project: walruz
|
|
77
98
|
rubygems_version: 1.3.5
|
78
99
|
signing_key:
|
79
100
|
specification_version: 3
|
80
|
-
summary: Walruz is a gem that provides an easy
|
101
|
+
summary: Walruz is a gem that provides an easy yet powerful way to implement authorization policies in a system, relying on the composition of simple policies to create more complex ones.
|
81
102
|
test_files:
|
82
103
|
- spec/scenario.rb
|
83
104
|
- spec/spec_helper.rb
|