Class: HubSsoLib::SessionFactory

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeSessionFactory

Returns a new instance of SessionFactory.



411
412
413
414
415
416
# File 'lib/hub_sso_lib.rb', line 411

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_sessionsObject



466
467
468
# File 'lib/hub_sso_lib.rb', line 466

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 immeediately 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.



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/hub_sso_lib.rb', line 437

def get_hub_session_proxy(key, remote_ip)
  hub_session = @hub_sessions[key]
  message     = 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