Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.lutris.appserver.server.session
Class StandardSessionManager  view StandardSessionManager download StandardSessionManager.java

java.lang.Object
  extended bycom.lutris.appserver.server.session.StandardSessionManager
All Implemented Interfaces:
SessionManager, StandardSessionIdleHandler

public class StandardSessionManager
extends java.lang.Object
implements SessionManager, StandardSessionIdleHandler

This session manager maintains the mapping between session keys and sessions. It generates secure session keys that are safe to use as cookie values in web applications. It also manages the life of a session. If a session is not used (touched) for a preconfigured amount of time, then it is expired and removed from the session manager. The following parameters can be used to configure the session manager. They should be grouped together in a section, normally SessionManager, which is specified to the constructor.

Version:
$Revision: 1.42.2.4.4.1 $

Field Summary
(package private)  com.lutris.appserver.server.Application app
          The application using this session manager.
private static java.lang.String BASIC
          The supported session home types.
static java.lang.String CFG_ENCODE_URL_STATE
          The name of the config variable for the url encoding state
static java.lang.String CFG_IDLE
          The name of the config variable for the max session idle time.
static java.lang.String CFG_LIFE
          The name of the config variable for the max session lifetime.
static java.lang.String CFG_NOUSER_IDLE
          The name of the config variable for the max idle time for sessions with no user.
static java.lang.String CFG_RANDOM
          The name of the config variable for the interval between introduction of randomness to the session key generator.
static java.lang.String CFG_SCAN
          The name of the config variable for the interval between scans for idle sessions.
static java.lang.String CFG_SESSION_HOME
          The name of the config variable for the session home settings.
static java.lang.String CFG_SESSION_HOME_TYPE
          The name of the config variable for the session home type.
(package private)  java.lang.ClassLoader classLoader
          The class loader used by this app/context.
private static java.lang.String CUSTOM
           
protected static java.lang.String defaultEncodeUrlState
          Indicates url encoding status.
protected static long defaultIdleScanInterval
          Default interval, in seconds, to scan for sessions to expire.
protected static long defaultMaxSessionIdleTime
          Default maximum session idle time, in seconds.
protected static long defaultMaxSessionLifeTime
          Default maximum session life time, in seconds.
protected static long[] defaultRandomizerIntervals
          Default list of randomize key generator time intervals, in seconds.
static java.lang.String ENCODE_URL_ALWAYS
          Indicates that url encoding of session ids is always preformed.
static java.lang.String ENCODE_URL_AUTO
          Indicates that url encoding of session ids is preformed only when cookies are disabled on the client browser.
static java.lang.String ENCODE_URL_NEVER
          Indicates that url encoding of session ids is never preformed.
protected  java.lang.String encodeUrlState
          The url encoding state.
private  StandardSessionIdleTimer idleTimer
          Background thread that keeps track of session idle time.
private  StandardSessionKeyGen keyGenerator
          Object that generates random session keys.
(package private)  com.lutris.logging.LogChannel logChannel
          Log channel for debugging messages.
protected  long maxNoUserSessionIdleTime
          Maximum session idle time, in seconds for sessions that don't have a User object associated with them.
protected  long maxSessionIdleTime
          Maximum session idle time, in seconds.
private  long maxSessionLifeTime
          Maximum session life time, in seconds.
private  int maxSessions
           
private  java.util.Date maxSessionsDate
           
protected  int mode
          Represents the current session management mode.
static int MODE_BASIC
          Indicates that the session manager is using the basic session home interface to manage sessions.
static int MODE_CUSTOM
          Indicates that the session manager is using the custom home interface to manage sessions.
static int MODE_PAGE_TO_DB
          Indicates that the session manager is using the page to database home interface to manage sessions.
static int MODE_PAGE_TO_DISK
          Indicates that the session manager is using the page to disk home interface to manage sessions.
private static java.lang.String PAGE_TO_DB
           
private static java.lang.String PAGE_TO_DISK
           
protected  long scanInterval
          The time in seconds between scans for idle sessions to expire.
static int SESSION_ACTIVE
          Indicates that a sesson is still active.
static int SESSION_EXPLICT_DELETE
          Indicates that a sesson was explictly deleted.
static int SESSION_IDLE_EXPIRE
          Indicates that a sesson was deleted due to idle time being exceeded.
static int SESSION_MAX_TIME
          Indicates that a sesson was deleted due to max time being exceeded.
private  StandardSessionHome sessionHome
          Table of currently active user sessions is managed by the session home.
(package private)  java.lang.String sessionHomeType
          The session home interface type being used.
private  StandardSessionUserTable sessionUserTable
          Table of users objects.
 
Constructor Summary
StandardSessionManager(com.lutris.appserver.server.Application application, com.lutris.util.Config config, com.lutris.logging.LogChannel sessionMgrLogChannel)
          Creates a new SessionManager object.
StandardSessionManager(java.lang.ClassLoader classLoader, com.lutris.util.Config config, com.lutris.logging.LogChannel sessionMgrLogChannel)
           
 
Method Summary
 int activeSessionCount()
          Gets the number of currently active sessions.
 void cleanUpIdleSessions()
          Scans session table to determine if any sessions need to be expired.
 Session createSession()
          Create a new Session object and associate a unique random key.
 Session createSession(java.lang.String ipPortToken)
          Create a new Session object and associate a unique random key.
private  void debug(int level, java.lang.String msg)
          Prints debug information under Logger.DEBUG.
private  void debug(java.lang.String msg)
          Prints debug information under Logger.DEBUG.
 void deleteSession(Session session)
          Removes a session from the Session Table.
 void deleteSession(java.lang.String sessionKey)
          Removes a session from the Session Table.
private  void doDeleteSession(StandardSession session, int reason)
          Does the actual work of deleting an entry from the session table.
 java.lang.String getEncodeUrlState()
          Returns the url encoding state.
 long getMaxNoUserSessionIdleTime()
          Returns the maximum no-user session idle time, in seconds.
 long getMaxSessionIdleTime()
          Returns the maximum session idle time, in seconds.
 long getMaxSessionLifeTime()
          Returns the maximum session life time, in seconds.
 int getMode()
          Returns the current mode for the session manager.
 Session getSession(java.lang.String sessionKey)
          Lookup the Session object associated with the specified session key.
 Session getSession(java.lang.Thread thread, java.lang.String sessionKey)
          Lookup the Session object associated with the specified session key.
 java.util.Enumeration getSessionKeys()
          Get all of the active sessions.
 java.util.Enumeration getSessionKeys(com.lutris.appserver.server.user.User user)
          Lookup the keys for the active sessions for a user.
protected  int isSessionExpired(StandardSession session)
          Determine if a session should be expired based on the idle time.
protected  StandardSessionHome loadSessionHome(com.lutris.util.Config config)
          Loads the StandardSessionHome used by this session manager.
protected  StandardSessionUserTable loadSessionUserTable(com.lutris.util.Config config)
          Loads the StandardSessiondUserTable used by this session manager.
private  void logConfig()
          Log configuration information.
private  void logRegisterUser(Session session, java.lang.String which)
          Log a user being registered or unregistered.
 int maxSessionCount()
          Gets the maximum number of concurent sessions that existed at any time since this object was created, or resetMaxSessionCount() was called.
 java.util.Date maxSessionCountDate()
          Gets the time when the maximum refered to by maxSessionCount() occured.
protected  StandardSession newSession(java.lang.String sessionKey)
          Deprecated. The instance of StandardSessionHome should be replaced instead of extending this method.
 int pagedSessionCount()
          Gets the number of session that are paged to persistent store.
 void passivateSession(java.lang.Thread thread, java.lang.String sessionKey)
          Puts a session into the 'passive' state.
protected  void registerUser(Session session)
          Adds a session's user to the session-to-user table.
 void resetMaxSessionCount()
          Reset the maximum session count.
protected  void sessionDeleted(Session session, int reason)
          Method called when a session is deleted.
 boolean sessionExists(java.lang.String sessionKey)
          Returns whether the Session object associated with the specified session key exists.
 void setMaxSessionIdleTime(long maxSessionIdleTime)
          Sets the maximum session idle time, in seconds.
 void shutdown()
          Shutdown this session manager, stopping threads that are associated with it.
protected  void unregisterUser(Session session)
          Removes a session's user from the session-to-user table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mode

protected int mode
Represents the current session management mode.


MODE_BASIC

public static final int MODE_BASIC
Indicates that the session manager is using the basic session home interface to manage sessions.

See Also:
getMode() 55 , BasicSessionHome, Constant Field Values

MODE_PAGE_TO_DISK

public static final int MODE_PAGE_TO_DISK
Indicates that the session manager is using the page to disk home interface to manage sessions.

See Also:
getMode() 55 , DiskPagedSessionHome, Constant Field Values

MODE_PAGE_TO_DB

public static final int MODE_PAGE_TO_DB
Indicates that the session manager is using the page to database home interface to manage sessions.

See Also:
getMode() 55 , com.lutris.appserver.server.session.persistent.PersistentSessionHome, Constant Field Values

MODE_CUSTOM

public static final int MODE_CUSTOM
Indicates that the session manager is using the custom home interface to manage sessions.

See Also:
getMode() 55 , Constant Field Values

ENCODE_URL_NEVER

public static final java.lang.String ENCODE_URL_NEVER
Indicates that url encoding of session ids is never preformed.

See Also:
getEncodeUrlState() 55 , Constant Field Values

ENCODE_URL_ALWAYS

public static final java.lang.String ENCODE_URL_ALWAYS
Indicates that url encoding of session ids is always preformed.

See Also:
getEncodeUrlState() 55 , Constant Field Values

ENCODE_URL_AUTO

public static final java.lang.String ENCODE_URL_AUTO
Indicates that url encoding of session ids is preformed only when cookies are disabled on the client browser. This is automatically detected.

See Also:
getEncodeUrlState() 55 , Constant Field Values

defaultMaxSessionLifeTime

protected static long defaultMaxSessionLifeTime
Default maximum session life time, in seconds. Zero if there is no limit. A derived SessionManager may override this value to use the default expiration logic or override isSessionExpired to define custom expiration logic.

See Also:
lutris.session.StandardSessionManager#getMaxSessionLifeTime

defaultMaxSessionIdleTime

protected static long defaultMaxSessionIdleTime
Default maximum session idle time, in seconds. A derived SessionManager may override this value to use the default expiration logic or override isSessionExpired to define custom expiration logic. A value less-than or equal to zero disables idle checking. Default value is 30 minutes.

See Also:
getMaxSessionIdleTime() 55

defaultEncodeUrlState

protected static java.lang.String defaultEncodeUrlState
Indicates url encoding status. Assumes that comms.response.writeHTML(HTMLDocument doc) is used to commit the response to the client. The default is to Auto.
Never indicates urls are never encoded with session keys. This indicates that session cookies have to be used or no session state can be maintained.
Always indicates that urls are always encoded with session keys. Session cookies are never used.
Auto indicates that session cookies will be if available. If not, urls will automatically be encoded.

See Also:
getEncodeUrlState() 55

defaultIdleScanInterval

protected static long defaultIdleScanInterval
Default interval, in seconds, to scan for sessions to expire. A derived SessionManager may override this value. Default value is 30 seconds.


defaultRandomizerIntervals

protected static long[] defaultRandomizerIntervals
Default list of randomize key generator time intervals, in seconds. A list of prime numbers is recommended. A derived SessionManager may override this value.


CFG_LIFE

public static final java.lang.String CFG_LIFE
The name of the config variable for the max session lifetime.

See Also:
Constant Field Values

CFG_IDLE

public static final java.lang.String CFG_IDLE
The name of the config variable for the max session idle time.

See Also:
Constant Field Values

CFG_ENCODE_URL_STATE

public static final java.lang.String CFG_ENCODE_URL_STATE
The name of the config variable for the url encoding state

See Also:
Constant Field Values

CFG_NOUSER_IDLE

public static final java.lang.String CFG_NOUSER_IDLE
The name of the config variable for the max idle time for sessions with no user.

See Also:
Constant Field Values

CFG_SCAN

public static final java.lang.String CFG_SCAN
The name of the config variable for the interval between scans for idle sessions.

See Also:
Constant Field Values

CFG_RANDOM

public static final java.lang.String CFG_RANDOM
The name of the config variable for the interval between introduction of randomness to the session key generator.

See Also:
Constant Field Values

CFG_SESSION_HOME

public static final java.lang.String CFG_SESSION_HOME
The name of the config variable for the session home settings.

See Also:
Constant Field Values

CFG_SESSION_HOME_TYPE

public static final java.lang.String CFG_SESSION_HOME_TYPE
The name of the config variable for the session home type.

See Also:
Constant Field Values

SESSION_ACTIVE

public static final int SESSION_ACTIVE
Indicates that a sesson is still active.

See Also:
sessionDeleted(com.lutris.appserver.server.session.Session, int) 55 , Constant Field Values

SESSION_MAX_TIME

public static final int SESSION_MAX_TIME
Indicates that a sesson was deleted due to max time being exceeded.

See Also:
sessionDeleted(com.lutris.appserver.server.session.Session, int) 55 , Constant Field Values

SESSION_IDLE_EXPIRE

public static final int SESSION_IDLE_EXPIRE
Indicates that a sesson was deleted due to idle time being exceeded.

See Also:
sessionDeleted(com.lutris.appserver.server.session.Session, int) 55 , Constant Field Values

SESSION_EXPLICT_DELETE

public static final int SESSION_EXPLICT_DELETE
Indicates that a sesson was explictly deleted.

See Also:
sessionDeleted(com.lutris.appserver.server.session.Session, int) 55 , Constant Field Values

sessionHome

private StandardSessionHome sessionHome
Table of currently active user sessions is managed by the session home. Different implementations of StandardSessionHome can be loaded by this manager. A specific implementation can manage failover persistence, paging, etc.


sessionUserTable

private StandardSessionUserTable sessionUserTable
Table of users objects. This table tracks the number of simultaneous sessions a user currently has active. Table entries are of type Vector, constaining Session objects, keyed by User object reference.


maxSessions

private int maxSessions

maxSessionsDate

private java.util.Date maxSessionsDate

keyGenerator

private StandardSessionKeyGen keyGenerator
Object that generates random session keys. Manages a thread to for increase randomization.

See Also:
StandardSessionKeyGen

maxSessionLifeTime

private long maxSessionLifeTime
Maximum session life time, in seconds. Zero if there is no limit.

See Also:
lutris.session.StandardSessionManager#getMaxSessionLifeTime

maxSessionIdleTime

protected long maxSessionIdleTime
Maximum session idle time, in seconds. A value less-than or equal to zero disables idle checking.

See Also:
getMaxSessionIdleTime() 55

encodeUrlState

protected java.lang.String encodeUrlState
The url encoding state. Either Never Always Auto.


idleTimer

private StandardSessionIdleTimer idleTimer
Background thread that keeps track of session idle time. Sessions that have been idle for more than a configurable time limit are terminated by this thread.

See Also:
StandardSessionIdleTimer

maxNoUserSessionIdleTime

protected long maxNoUserSessionIdleTime
Maximum session idle time, in seconds for sessions that don't have a User object associated with them. A value less-than or equal to zero disables idle checking.

See Also:
getMaxNoUserSessionIdleTime() 55

scanInterval

protected long scanInterval
The time in seconds between scans for idle sessions to expire.


logChannel

com.lutris.logging.LogChannel logChannel
Log channel for debugging messages.


app

com.lutris.appserver.server.Application app
The application using this session manager.


classLoader

java.lang.ClassLoader classLoader
The class loader used by this app/context.


BASIC

private static final java.lang.String BASIC
The supported session home types.

See Also:
Constant Field Values

PAGE_TO_DISK

private static final java.lang.String PAGE_TO_DISK
See Also:
Constant Field Values

PAGE_TO_DB

private static final java.lang.String PAGE_TO_DB
See Also:
Constant Field Values

CUSTOM

private static final java.lang.String CUSTOM
See Also:
Constant Field Values

sessionHomeType

java.lang.String sessionHomeType
The session home interface type being used.

Constructor Detail

StandardSessionManager

public StandardSessionManager(com.lutris.appserver.server.Application application,
                              com.lutris.util.Config config,
                              com.lutris.logging.LogChannel sessionMgrLogChannel)
                       throws com.lutris.util.ConfigException,
                              SessionException
Creates a new SessionManager object. This constructor will first looks for the session manager configuration parameters that have the specified configuration prefix prepended to the standard session manager configuration option.


StandardSessionManager

public StandardSessionManager(java.lang.ClassLoader classLoader,
                              com.lutris.util.Config config,
                              com.lutris.logging.LogChannel sessionMgrLogChannel)
                       throws com.lutris.util.ConfigException,
                              SessionException
Method Detail

logConfig

private void logConfig()
Log configuration information.


loadSessionHome

protected StandardSessionHome loadSessionHome(com.lutris.util.Config config)
                                       throws com.lutris.util.ConfigException,
                                              SessionException
Loads the StandardSessionHome used by this session manager.


loadSessionUserTable

protected StandardSessionUserTable loadSessionUserTable(com.lutris.util.Config config)
                                                 throws com.lutris.util.ConfigException,
                                                        SessionException
Loads the StandardSessiondUserTable used by this session manager.


shutdown

public void shutdown()
Shutdown this session manager, stopping threads that are associated with it.

Specified by:
shutdown in interface SessionManager

newSession

protected StandardSession newSession(java.lang.String sessionKey)
                              throws CreateSessionException,
                                     SessionException
Deprecated. The instance of StandardSessionHome should be replaced instead of extending this method.

Allocate a new StandardSession object. This maybe overridden by derived session managers to allocated a Session object derived from StandardSession. This is called by createSession.


createSession

public Session createSession()
                      throws SessionException
Create a new Session object and associate a unique random key. No User is initially associated with (Session.getUser() returns null/

Specified by:
createSession in interface SessionManager

createSession

public Session createSession(java.lang.String ipPortToken)
                      throws SessionException
Create a new Session object and associate a unique random key. No User is initially associated with (Session.getUser() returns null/

Specified by:
createSession in interface SessionManager

logRegisterUser

private void logRegisterUser(Session session,
                             java.lang.String which)
Log a user being registered or unregistered.


registerUser

protected void registerUser(Session session)
                     throws SessionException
Adds a session's user to the session-to-user table. This is called by the Session object to associate a session with a user.


unregisterUser

protected void unregisterUser(Session session)
                       throws SessionException
Removes a session's user from the session-to-user table. This is called by the Session object to disassoicate a user from a session.


isSessionExpired

protected int isSessionExpired(StandardSession session)
Determine if a session should be expired based on the idle time. This method is designed to be overriden by derived classes that want to use different idle time checks.


sessionDeleted

protected void sessionDeleted(Session session,
                              int reason)
Method called when a session is deleted. This method is designed to be overriden by derived classes that want need to take specific action, such as saving the sessions state. The default implementation of this method does nothing.


doDeleteSession

private void doDeleteSession(StandardSession session,
                             int reason)
                      throws SessionException
Does the actual work of deleting an entry from the session table.


deleteSession

public void deleteSession(Session session)
                   throws SessionException
Removes a session from the Session Table. This method is used to log a user off the application. Note that sessionDeleted() is called.

Specified by:
deleteSession in interface SessionManager

deleteSession

public void deleteSession(java.lang.String sessionKey)
                   throws SessionException
Removes a session from the Session Table. This method is used to log a user off the application. Note that sessionDeleted() is called.

Specified by:
deleteSession in interface SessionManager

passivateSession

public void passivateSession(java.lang.Thread thread,
                             java.lang.String sessionKey)
                      throws SessionException
Puts a session into the 'passive' state. A 'passive' session may be made persistent.

Specified by:
passivateSession in interface SessionManager

cleanUpIdleSessions

public void cleanUpIdleSessions()
                         throws SessionException
Scans session table to determine if any sessions need to be expired.

Specified by:
cleanUpIdleSessions in interface StandardSessionIdleHandler

sessionExists

public boolean sessionExists(java.lang.String sessionKey)
                      throws SessionException
Returns whether the Session object associated with the specified session key exists.

Specified by:
sessionExists in interface SessionManager

getSession

public Session getSession(java.lang.String sessionKey)
                   throws SessionException
Lookup the Session object associated with the specified session key.

Each time a session is returned via this method, the session's last used (referenced) time is updated to the current time.

Specified by:
getSession in interface SessionManager

getSession

public Session getSession(java.lang.Thread thread,
                          java.lang.String sessionKey)
                   throws SessionException
Lookup the Session object associated with the specified session key.

Each time a session is returned via this method, the session's last used (referenced) time is updated to the current time.

Specified by:
getSession in interface SessionManager

getSessionKeys

public java.util.Enumeration getSessionKeys()
                                     throws SessionException
Get all of the active sessions.

Specified by:
getSessionKeys in interface SessionManager

getSessionKeys

public java.util.Enumeration getSessionKeys(com.lutris.appserver.server.user.User user)
                                     throws SessionException
Lookup the keys for the active sessions for a user. A given user may have multiple sessions associated with it (using FTP as an example, the "anonymous" account).

Specified by:
getSessionKeys in interface SessionManager

activeSessionCount

public int activeSessionCount()
                       throws SessionException
Gets the number of currently active sessions.

Specified by:
activeSessionCount in interface SessionManager

pagedSessionCount

public int pagedSessionCount()
                      throws SessionException
Gets the number of session that are paged to persistent store.


getMode

public int getMode()
            throws SessionException
Returns the current mode for the session manager.


maxSessionCount

public int maxSessionCount()
Gets the maximum number of concurent sessions that existed at any time since this object was created, or resetMaxSessionCount() was called. This is a historical highwater mark.

Specified by:
maxSessionCount in interface SessionManager

maxSessionCountDate

public java.util.Date maxSessionCountDate()
Gets the time when the maximum refered to by maxSessionCount() occured.

Specified by:
maxSessionCountDate in interface SessionManager

resetMaxSessionCount

public void resetMaxSessionCount()
                          throws SessionException
Reset the maximum session count. See maxSessionCount(). The highwater mark should be reset to the current number of sessions.

Specified by:
resetMaxSessionCount in interface SessionManager

getMaxSessionLifeTime

public long getMaxSessionLifeTime()
Returns the maximum session life time, in seconds.


setMaxSessionIdleTime

public void setMaxSessionIdleTime(long maxSessionIdleTime)
Sets the maximum session idle time, in seconds.


getMaxSessionIdleTime

public long getMaxSessionIdleTime()
Returns the maximum session idle time, in seconds.


getEncodeUrlState

public java.lang.String getEncodeUrlState()
Returns the url encoding state. Either Never Always Auto


getMaxNoUserSessionIdleTime

public long getMaxNoUserSessionIdleTime()
Returns the maximum no-user session idle time, in seconds.


debug

private void debug(java.lang.String msg)
Prints debug information under Logger.DEBUG.


debug

private void debug(int level,
                   java.lang.String msg)
Prints debug information under Logger.DEBUG.