org.opencms.main
Class CmsSessionManager

java.lang.Object
  extended byorg.opencms.main.CmsSessionManager

public class CmsSessionManager
extends java.lang.Object

Keeps track of the sessions running on the OpenCms server and provides a session info storage which is used to get an overview about currently authenticated OpenCms users, as well as sending broadcasts between users.

For each authenticated OpenCms user, a CmsSessionInfo object holds the information about the users status.

When a user session is invalidated, the user info will be removed. This happens when a user log out, or when his session times out.

Please Note: The current implementation does not provide any permission checking, so all users can access the methods of this manager. Permission checking based on the current users OpenCms context may be added in a future OpenCms release.

Since:
6.0.0
Version:
$Revision: 1.12 $
Author:
Alexander Kandzior

Constructor Summary
protected CmsSessionManager()
          Creates a new instance of the OpenCms session manager.
 
Method Summary
protected  void addSessionInfo(CmsSessionInfo sessionInfo)
          Adds a new session info into the session storage.
 org.apache.commons.collections.Buffer getBroadcastQueue(java.lang.String sessionId)
          Returns the broadcast queue for the given session id.
 int getSessionCountAuthenticated()
          Returns the number of sessions currently authenticated in the OpenCms security system.
 int getSessionCountCurrent()
          Returns the number of current sessions, including the sessions of not authenticated guest users.
 int getSessionCountTotal()
          Returns the number of total sessions generated so far, including already destroyed sessions.
 CmsSessionInfo getSessionInfo(java.lang.String sessionId)
          Returns the complete user session info of a user from the session storage, or null if this session id has no session info attached.
 java.util.List getSessionInfos()
          Returns all current session info objects.
 java.util.List getSessionInfos(CmsUUID userId)
          Returns a list of all active session info objects for the specified user.
 void sendBroadcast(CmsObject cms, java.lang.String message)
          Sends a broadcast to all sessions of all currently authenticated users.
 void sendBroadcast(CmsObject cms, java.lang.String message, CmsUser user)
          Sends a broadcast to all sessions of a given user.
 void sendBroadcast(CmsObject cms, java.lang.String message, java.lang.String sessionId)
          Sends a broadcast to the specified user session.
protected  void sessionCreated(javax.servlet.http.HttpSessionEvent event)
          Called by the OpenCmsListener when a http session is created.
protected  void sessionDestroyed(javax.servlet.http.HttpSessionEvent event)
          Called by the OpenCmsListener when a http session is destroyed.
 java.lang.String toString()
           
protected  void validateSessionInfos()
          Validates the sessions stored in this manager and removes any sessions that have become invalidated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmsSessionManager

protected CmsSessionManager()
Creates a new instance of the OpenCms session manager.

Method Detail

getBroadcastQueue

public org.apache.commons.collections.Buffer getBroadcastQueue(java.lang.String sessionId)
Returns the broadcast queue for the given session id.

Parameters:
sessionId - the session id to get the broadcast queue for
Returns:
the broadcast queue for the given session id

getSessionCountAuthenticated

public int getSessionCountAuthenticated()
Returns the number of sessions currently authenticated in the OpenCms security system.

Returns:
the number of sessions currently authenticated in the OpenCms security system

getSessionCountCurrent

public int getSessionCountCurrent()
Returns the number of current sessions, including the sessions of not authenticated guest users.

Returns:
the number of current sessions, including the sessions of not authenticated guest users

getSessionCountTotal

public int getSessionCountTotal()
Returns the number of total sessions generated so far, including already destroyed sessions.

Returns:
the number of total sessions generated so far, including already destroyed sessions

getSessionInfo

public CmsSessionInfo getSessionInfo(java.lang.String sessionId)
Returns the complete user session info of a user from the session storage, or null if this session id has no session info attached.

Parameters:
sessionId - the session id to return the session info for
Returns:
the complete user session info of a user from the session storage

getSessionInfos

public java.util.List getSessionInfos()
Returns all current session info objects.

Returns:
all current session info objects

getSessionInfos

public java.util.List getSessionInfos(CmsUUID userId)
Returns a list of all active session info objects for the specified user.

An OpenCms user can have many active sessions. This is e.g. possible when two people have logged in to the system using the same username. Even one person can have multiple sessions if he is logged in to OpenCms with several browser windows at the same time.

Parameters:
userId - the id of the user
Returns:
a list of all active session info objects for the specified user

sendBroadcast

public void sendBroadcast(CmsObject cms,
                          java.lang.String message)
Sends a broadcast to all sessions of all currently authenticated users.

Parameters:
cms - the OpenCms user context of the user sending the broadcast
message - the message to broadcast

sendBroadcast

public void sendBroadcast(CmsObject cms,
                          java.lang.String message,
                          CmsUser user)
Sends a broadcast to all sessions of a given user.

Parameters:
cms - the OpenCms user context of the user sending the broadcast
message - the message to broadcast
user - the target (reciever) of the broadcast

sendBroadcast

public void sendBroadcast(CmsObject cms,
                          java.lang.String message,
                          java.lang.String sessionId)
Sends a broadcast to the specified user session.

Parameters:
cms - the OpenCms user context of the user sending the broadcast
message - the message to broadcast
sessionId - the session id target (reciever) of the broadcast

toString

public java.lang.String toString()
See Also:
Object.toString()

addSessionInfo

protected void addSessionInfo(CmsSessionInfo sessionInfo)
Adds a new session info into the session storage.

Parameters:
sessionInfo - the session info to store for the id

sessionCreated

protected void sessionCreated(javax.servlet.http.HttpSessionEvent event)
Called by the OpenCmsListener when a http session is created.

Parameters:
event - the http session event
See Also:
HttpSessionListener.sessionCreated(javax.servlet.http.HttpSessionEvent), OpenCmsListener.sessionCreated(HttpSessionEvent)

sessionDestroyed

protected void sessionDestroyed(javax.servlet.http.HttpSessionEvent event)
Called by the OpenCmsListener when a http session is destroyed.

Parameters:
event - the http session event
See Also:
HttpSessionListener.sessionDestroyed(javax.servlet.http.HttpSessionEvent), OpenCmsListener.sessionDestroyed(HttpSessionEvent)

validateSessionInfos

protected void validateSessionInfos()
Validates the sessions stored in this manager and removes any sessions that have become invalidated.