global_session 1.0.17 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'global_session'
10
- s.version = '1.0.17'
11
- s.date = '2012-10-30'
10
+ s.version = '1.1.0'
11
+ s.date = '2012-11-01'
12
12
 
13
13
  s.authors = ['Tony Spataro']
14
14
  s.email = 'support@rightscale.com'
@@ -158,7 +158,9 @@ module GlobalSession
158
158
  # current global_session object. This callback could help application to get data related
159
159
  # to the previous global session (old_global_session_id), and put it to new global session
160
160
  # (new_global_sesion_id)
161
-
161
+ #
162
+ # @deprecated this method will be removed with GlobalSession 2.0; do not use!
163
+ #
162
164
  # invalidated_uuid(String):: Invalidated Global session UUID
163
165
  # new_uuid(String):: Newly created Global session UUID
164
166
  # === Return
@@ -27,6 +27,8 @@ module GlobalSession
27
27
  # Global session middleware. Note: this class relies on
28
28
  # Rack::Cookies being used higher up in the chain.
29
29
  class Middleware
30
+ LOCAL_SESSION_KEY = "rack.session".freeze
31
+
30
32
  # Make a new global session.
31
33
  #
32
34
  # The optional block here controls an alternate ticket retrieval
@@ -146,29 +148,30 @@ module GlobalSession
146
148
  return unless env['global_session'].directory.local_authority_name
147
149
  return if env['global_session.req.update'] == false
148
150
 
149
- begin
150
- domain = @configuration['cookie']['domain'] || env['SERVER_NAME']
151
- if env['global_session']
152
- global_session = env['global_session']
153
- unless global_session.valid?
154
- invalidated_uuid = global_session.id
155
- global_session = @directory.create_session
156
- @directory.session_invalidated(invalidated_uuid, global_session.id)
157
- end
158
- value = global_session.to_s
159
- expires = @configuration['ephemeral'] ? nil : global_session.expired_at
160
- unless env['rack.cookies'].has_key?(@cookie_name) && env['rack.cookies'][@cookie_name] == value
161
- env['rack.cookies'][@cookie_name] =
162
- {:value => value, :domain => domain, :expires => expires, :httponly=>true}
163
- end
164
- else
165
- # write an empty cookie
166
- env['rack.cookies'][@cookie_name] = {:value => nil, :domain => domain, :expires => Time.at(0)}
151
+ domain = @configuration['cookie']['domain'] || env['SERVER_NAME']
152
+ session = env['global_session']
153
+
154
+ if session
155
+ unless session.valid?
156
+ old_session = session
157
+ session = @directory.create_session
158
+ perform_invalidation_callbacks(env, old_session, session)
159
+ env['global_session'] = session
167
160
  end
168
- rescue Exception => e
169
- wipe_cookie(env)
170
- raise e
161
+
162
+ value = session.to_s
163
+ expires = @configuration['ephemeral'] ? nil : session.expired_at
164
+ unless env['rack.cookies'][@cookie_name] == value
165
+ env['rack.cookies'][@cookie_name] =
166
+ {:value => value, :domain => domain, :expires => expires, :httponly=>true}
167
+ end
168
+ else
169
+ # write an empty cookie
170
+ env['rack.cookies'][@cookie_name] = {:value => nil, :domain => domain, :expires => Time.at(0)}
171
171
  end
172
+ rescue Exception => e
173
+ wipe_cookie(env)
174
+ raise e
172
175
  end
173
176
 
174
177
  # Delete the global session cookie from the cookie jar.
@@ -207,6 +210,22 @@ module GlobalSession
207
210
  raise e
208
211
  end
209
212
  end
213
+
214
+ # Perform callbacks to directory and/or local session
215
+ # informing them that this session has been invalidated.
216
+ #
217
+ # === Parameters
218
+ # env(Hash):: the rack environment
219
+ # old_session(GlobalSession):: the now-invalidated session
220
+ # new_session(GlobalSession):: the new session that will be sent to the client
221
+ def perform_invalidation_callbacks(env, old_session, new_session)
222
+ @directory.session_invalidated(old_session.id, new_session.id)
223
+ if (local_session = env[LOCAL_SESSION_KEY]) && local_session.respond_to?(:rename!)
224
+ local_session.rename!(old_session, new_session)
225
+ end
226
+
227
+ true
228
+ end
210
229
  end
211
230
  end
212
231
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global_session
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 17
10
- version: 1.0.17
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-10-30 00:00:00 -07:00
18
+ date: 2012-11-01 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency