Class: HubSsoLib::SessionFactory
- Inherits:
-
Object
- Object
- HubSsoLib::SessionFactory
- Defined in:
- lib/hub_sso_lib.rb
Overview
Class: SessionFactory #
(C) Hipposoft 2006 #
#
Purpose: Build Session objects for DRb server clients. Maintains a #
hash of Session objects. #
#
Author: A.D.Hodgkinson #
#
History: 26-Oct-2006 (ADH): Created. #
Instance Method Summary collapse
- #enumerate_hub_sessions ⇒ Object
-
#get_hub_session_proxy(key, remote_ip) ⇒ Object
Get a session using a given key (a UUID).
-
#initialize ⇒ SessionFactory
constructor
A new instance of SessionFactory.
Constructor Details
#initialize ⇒ SessionFactory
Returns a new instance of SessionFactory.
431 432 433 434 435 436 |
# File 'lib/hub_sso_lib.rb', line 431 def initialize @hub_be_quiet = ! ENV['HUB_QUIET_SERVER'].nil? @hub_sessions = {} puts "Session factory: Awaken" unless @hub_be_quiet end |
Instance Method Details
#enumerate_hub_sessions ⇒ Object
486 487 488 |
# File 'lib/hub_sso_lib.rb', line 486 def enumerate_hub_sessions() @hub_sessions end |
#get_hub_session_proxy(key, remote_ip) ⇒ Object
Get a session using a given key (a UUID). Generates a new session if the key is unrecognised or if the IP address given mismatches the one recorded in existing session data.
Whether new or pre-existing, the returned session will have changed key as a result of being read; check the #session_key_rotation property to find out the new key. If you fail to do this, you’ll lose access to the session data as you won’t know which key it lies under.
The returned object is proxied via DRb - it is shared between processes.
key-
Session key; lazy-initialises a new session under this key if none is found, then immediately rotates it.
remote_ip-
Request’s remote IP address. If there is an existing session which matches this, it’s returned. If there is an existing session but the IP mismatches, it’s treated as invalid and discarded.
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/hub_sso_lib.rb', line 457 def get_hub_session_proxy(key, remote_ip) hub_session = @hub_sessions[key] = hub_session.nil? ? 'Created' : 'Retrieving' new_key = SecureRandom.uuid unless @hub_be_quiet puts "#{ message } session for key #{ key } and rotating to #{ new_key }" end unless hub_session.nil? || hub_session.session_ip == remote_ip unless @hub_be_quiet puts "WARNING: IP address changed from #{ hub_session.session_ip } to #{ remote_ip } -> discarding session" end hub_session = nil end if hub_session.nil? hub_session = HubSsoLib::Session.new hub_session.session_ip = remote_ip end @hub_sessions.delete(key) @hub_sessions[new_key] = hub_session hub_session.session_key_rotation = new_key return hub_session end |