warden 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,18 @@ module Warden
29
29
 
30
30
  self
31
31
  end
32
+
33
+ # Get the default scope for Warden. By default this is :default
34
+ # @api public
35
+ def self.default_scope
36
+ @default_scope
37
+ end
38
+
39
+ # Set the default scope for Warden.
40
+ def self.default_scope=(scope)
41
+ @default_scope = scope
42
+ end
43
+ @default_scope = :default
32
44
 
33
45
  # Do not raise an error if a missing strategy is given by default.
34
46
  # :api: plugin
@@ -26,7 +26,7 @@ module Warden
26
26
  end
27
27
 
28
28
  # Check to see if there is an authenticated user for the given scope.
29
- # When scope is not specified, :default is assumed.
29
+ # When scope is not specified, Warden::Manager.default_scope is assumed.
30
30
  # This will not try to reconstitute the user from the session and will simply check for the
31
31
  # existance of a session key
32
32
  #
@@ -37,7 +37,7 @@ module Warden
37
37
  # env['warden'].authenticated?(:admin)
38
38
  #
39
39
  # :api: public
40
- def authenticated?(scope = :default)
40
+ def authenticated?(scope = Warden::Manager.default_scope)
41
41
  result = user(scope) || false
42
42
  yield if block_given? && result
43
43
  result
@@ -45,7 +45,7 @@ module Warden
45
45
 
46
46
  # Same API as authenticated, but returns false when authenticated.
47
47
  # :api: public
48
- def unauthenticated?(scope = :default)
48
+ def unauthenticated?(scope = Warden::Manager.default_scope)
49
49
  result = !authenticated?(scope)
50
50
  yield if block_given? && result
51
51
  result
@@ -54,7 +54,7 @@ module Warden
54
54
  # Run the authentiation strategies for the given strategies.
55
55
  # If there is already a user logged in for a given scope, the strategies are not run
56
56
  # This does not halt the flow of control and is a passive attempt to authenticate only
57
- # When scope is not specified, :default is assumed.
57
+ # When scope is not specified, Warden::Manager.default_scope is assumed.
58
58
  #
59
59
  # Parameters:
60
60
  # args - a list of symbols (labels) that name the strategies to attempt
@@ -93,7 +93,7 @@ module Warden
93
93
  # env['warden'].stored?(:default, :cookie) #=> false
94
94
  #
95
95
  # :api: public
96
- def stored?(scope = :default, serializer = nil)
96
+ def stored?(scope = Warden::Manager.default_scope, serializer = nil)
97
97
  if serializer
98
98
  find_serializer(serializer).stored?(scope)
99
99
  else
@@ -109,7 +109,7 @@ module Warden
109
109
  #
110
110
  # :api: public
111
111
  def set_user(user, opts = {})
112
- scope = (opts[:scope] ||= :default)
112
+ scope = (opts[:scope] ||= Warden::Manager.default_scope)
113
113
  _store_user(user, scope) unless opts[:store] == false
114
114
  @users[scope] = user
115
115
 
@@ -129,7 +129,7 @@ module Warden
129
129
  # env['warden'].user(:admin)
130
130
  #
131
131
  # :api: public
132
- def user(scope = :default)
132
+ def user(scope = Warden::Manager.default_scope)
133
133
  @users[scope] ||= set_user(_fetch_user(scope), :scope => scope)
134
134
  end
135
135
 
@@ -144,7 +144,7 @@ module Warden
144
144
  # env['warden'].session(:sudo)[:foo] = "bar"
145
145
  #
146
146
  # :api: public
147
- def session(scope = :default)
147
+ def session(scope = Warden::Manager.default_scope)
148
148
  raise NotAuthenticated, "#{scope.inspect} user is not logged in" unless authenticated?(scope)
149
149
  raw_session["warden.user.#{scope}.session"] ||= {}
150
150
  end
@@ -264,7 +264,7 @@ module Warden
264
264
 
265
265
  # :api: private
266
266
  def scope_from_args(args) # :nodoc:
267
- Hash === args.last ? args.last.fetch(:scope, :default) : :default
267
+ Hash === args.last ? args.last.fetch(:scope, Warden::Manager.default_scope) : Warden::Manager.default_scope
268
268
  end
269
269
 
270
270
  # :api: private
@@ -284,14 +284,14 @@ module Warden
284
284
 
285
285
  # Does the work of storing the user in stores.
286
286
  # :api: private
287
- def _store_user(user, scope = :default) # :nodoc:
287
+ def _store_user(user, scope = Warden::Manager.default_scope) # :nodoc:
288
288
  return unless user
289
289
  serializers.each { |s| s.store(user, scope) }
290
290
  end
291
291
 
292
292
  # Does the work of fetching the user from the first store.
293
293
  # :api: private
294
- def _fetch_user(scope = :default) # :nodoc:
294
+ def _fetch_user(scope = Warden::Manager.default_scope) # :nodoc:
295
295
  serializers.each do |s|
296
296
  user = s.fetch(scope)
297
297
  return user if user
@@ -301,7 +301,7 @@ module Warden
301
301
 
302
302
  # Does the work of deleteing the user in all stores.
303
303
  # :api: private
304
- def _delete_user(user, scope = :default) # :nodoc:
304
+ def _delete_user(user, scope = Warden::Manager.default_scope) # :nodoc:
305
305
  serializers.each { |s| s.delete(scope, user) }
306
306
  end
307
307
 
@@ -1,3 +1,3 @@
1
1
  module Warden
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -207,5 +207,11 @@ describe Warden::Manager do
207
207
  end
208
208
  end
209
209
  end # integrated strategies
210
-
210
+
211
+ it "Should allow me to set a different default scope for warden" do
212
+ Warden::Manager.default_scope.should == :default
213
+ Warden::Manager.default_scope = :other_scope
214
+ Warden::Manager.default_scope.should == :other_scope
215
+ Warden::Manager.default_scope = :default
216
+ end
211
217
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{warden}
8
- s.version = "0.6.2"
8
+ s.version = "0.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Neighman"]
@@ -65,24 +65,24 @@ Gem::Specification.new do |s|
65
65
  s.rubygems_version = %q{1.3.5}
66
66
  s.summary = %q{Rack middleware that provides authentication for rack applications}
67
67
  s.test_files = [
68
- "spec/helpers/request_helper.rb",
69
- "spec/helpers/strategies/failz.rb",
68
+ "spec/warden_spec.rb",
70
69
  "spec/helpers/strategies/invalid.rb",
70
+ "spec/helpers/strategies/failz.rb",
71
71
  "spec/helpers/strategies/pass.rb",
72
- "spec/helpers/strategies/pass_without_user.rb",
73
72
  "spec/helpers/strategies/password.rb",
73
+ "spec/helpers/strategies/pass_without_user.rb",
74
+ "spec/helpers/request_helper.rb",
74
75
  "spec/spec_helper.rb",
75
- "spec/warden/authenticated_data_store_spec.rb",
76
- "spec/warden/errors_spec.rb",
76
+ "spec/warden/strategies/base_spec.rb",
77
77
  "spec/warden/hooks_spec.rb",
78
78
  "spec/warden/manager_spec.rb",
79
- "spec/warden/proxy_spec.rb",
79
+ "spec/warden/authenticated_data_store_spec.rb",
80
+ "spec/warden/errors_spec.rb",
80
81
  "spec/warden/serializers/cookie_spec.rb",
81
82
  "spec/warden/serializers/session_spec.rb",
82
83
  "spec/warden/serializers_spec.rb",
83
- "spec/warden/strategies/base_spec.rb",
84
- "spec/warden/strategies_spec.rb",
85
- "spec/warden_spec.rb"
84
+ "spec/warden/proxy_spec.rb",
85
+ "spec/warden/strategies_spec.rb"
86
86
  ]
87
87
 
88
88
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Neighman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-19 00:00:00 +11:00
12
+ date: 2009-11-19 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -102,21 +102,21 @@ signing_key:
102
102
  specification_version: 3
103
103
  summary: Rack middleware that provides authentication for rack applications
104
104
  test_files:
105
- - spec/helpers/request_helper.rb
106
- - spec/helpers/strategies/failz.rb
105
+ - spec/warden_spec.rb
107
106
  - spec/helpers/strategies/invalid.rb
107
+ - spec/helpers/strategies/failz.rb
108
108
  - spec/helpers/strategies/pass.rb
109
- - spec/helpers/strategies/pass_without_user.rb
110
109
  - spec/helpers/strategies/password.rb
110
+ - spec/helpers/strategies/pass_without_user.rb
111
+ - spec/helpers/request_helper.rb
111
112
  - spec/spec_helper.rb
112
- - spec/warden/authenticated_data_store_spec.rb
113
- - spec/warden/errors_spec.rb
113
+ - spec/warden/strategies/base_spec.rb
114
114
  - spec/warden/hooks_spec.rb
115
115
  - spec/warden/manager_spec.rb
116
- - spec/warden/proxy_spec.rb
116
+ - spec/warden/authenticated_data_store_spec.rb
117
+ - spec/warden/errors_spec.rb
117
118
  - spec/warden/serializers/cookie_spec.rb
118
119
  - spec/warden/serializers/session_spec.rb
119
120
  - spec/warden/serializers_spec.rb
120
- - spec/warden/strategies/base_spec.rb
121
+ - spec/warden/proxy_spec.rb
121
122
  - spec/warden/strategies_spec.rb
122
- - spec/warden_spec.rb