Class: Monorail::Session

Inherits:
Hash
  • Object
show all
Defined in:
lib/monorail/monorail_webd.rb

Overview

class Session

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

initialize



159
160
161
162
163
164
165
# File 'lib/monorail/monorail_webd.rb', line 159

def initialize
  super()
  @session_name = SessionManager.instance.generate_key
  @first_use = true
  @created_at = Time.now
  @last_retrieved = nil
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



154
155
156
# File 'lib/monorail/monorail_webd.rb', line 154

def password
  @password
end

#session_nameObject (readonly)

Returns the value of attribute session_name.



152
153
154
# File 'lib/monorail/monorail_webd.rb', line 152

def session_name
  @session_name
end

#usernameObject (readonly)

Returns the value of attribute username.



153
154
155
# File 'lib/monorail/monorail_webd.rb', line 153

def username
  @username
end

Instance Method Details

#authorizeObject

authorize



200
201
202
# File 'lib/monorail/monorail_webd.rb', line 200

def authorize
  @last_authorized = Time.now
end

#authorized?Boolean

authorized?

Returns:

  • (Boolean)


221
222
223
# File 'lib/monorail/monorail_webd.rb', line 221

def authorized?
  @last_authorized and ((Time.now - @last_authorized) < SessionManager::AuthorizationTimeout)
end

#first_use?Boolean

first_use?

Returns:

  • (Boolean)


170
171
172
# File 'lib/monorail/monorail_webd.rb', line 170

def first_use?
  @last_retrieved == nil
end

#is_expired?Boolean

is_expired?

Returns:

  • (Boolean)


177
178
179
180
# File 'lib/monorail/monorail_webd.rb', line 177

def is_expired?
  last_touch = (@last_retrieved or @created_at)
  (Time.now - last_touch) > SessionManager::SessionTimeout
end

#set_credential(user, psw) ⇒ Object

set_credential



192
193
194
# File 'lib/monorail/monorail_webd.rb', line 192

def set_credential user, psw
  @username,@password = user,psw
end

#touchObject

touch



185
186
187
# File 'lib/monorail/monorail_webd.rb', line 185

def touch
  @last_retrieved = Time.now
end

#unauthorizeObject

unauthorize Used to implement a logout function. Must null out the stored credential, otherwise the authorizer will just go back to the system function and try again. Security risk: Must make sure somehow that these session objects never get swapped out.



212
213
214
215
216
# File 'lib/monorail/monorail_webd.rb', line 212

def unauthorize
  @last_authorized = nil
  @username = nil
  @password = nil
end