public class CmsSessionManager extends java.lang.Object
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.
Modifier | Constructor and Description |
---|---|
protected |
CmsSessionManager()
Creates a new instance of the OpenCms session manager.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addSessionInfo(CmsSessionInfo sessionInfo)
Adds a new session info into the session storage.
|
void |
checkCreateSessionForUser(CmsUser user)
Checks whether a new session can be created for the user, and throws an exception if not.
|
org.apache.commons.collections.Buffer |
getBroadcastQueue(java.lang.String sessionId)
Returns the broadcast queue for the given OpenCms 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(CmsUUID 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. |
CmsSessionInfo |
getSessionInfo(javax.servlet.http.HttpServletRequest req)
Returns the OpenCms user session info for the given request,
or
null if no user session is available. |
CmsSessionInfo |
getSessionInfo(javax.servlet.http.HttpSession session)
Returns the OpenCms user session info for the given http session,
or
null if no user session is available. |
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<CmsSessionInfo> |
getSessionInfos()
Returns all current session info objects.
|
java.util.List<CmsSessionInfo> |
getSessionInfos(CmsUUID userId)
Returns a list of all active session info objects for the specified user.
|
protected CmsUUID |
getSessionUUID(java.lang.String sessionId)
Returns the UUID representation for the given session id String.
|
CmsSystemConfiguration.UserSessionMode |
getUserSessionMode()
Gets the user session mode.
|
protected void |
initialize(I_CmsSessionStorageProvider sessionStorageProvider)
Sets the storage provider.
|
void |
killSession(CmsObject cms,
CmsUser user)
Kills all sessions for the given user.
|
void |
killSession(CmsObject cms,
CmsUUID sessionid)
Destroys a session given the session id.
|
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,
java.lang.String sessionId)
Sends a broadcast to the specified user session.
|
void |
sendBroadcast(CmsUser fromUser,
java.lang.String message,
CmsUser toUser)
Sends a broadcast to all sessions of a given user.
|
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. |
protected void |
setUserSessionMode(CmsSystemConfiguration.UserSessionMode userSessionMode)
Sets the user session mode.
|
protected void |
shutdown()
Removes all stored session info objects.
|
void |
switchUser(CmsObject cms,
javax.servlet.http.HttpServletRequest req,
CmsUser user)
Switches the current user to the given user.
|
java.lang.String |
toString() |
void |
updateSessionInfo(CmsObject cms,
javax.servlet.http.HttpServletRequest req)
Updates the the OpenCms session data used for quick authentication of users.
|
void |
updateSessionInfo(CmsObject cms,
javax.servlet.http.HttpSession session)
Updates the the OpenCms session data used for quick authentication of users.
|
void |
updateSessionInfos(CmsObject cms)
Updates all session info objects, so that invalid projects
are replaced by the Online project.
|
protected void |
validateSessionInfos()
Validates the sessions stored in this manager and removes
any sessions that have become invalidated.
|
protected CmsSessionManager()
public void checkCreateSessionForUser(CmsUser user) throws CmsException
user
- the user to checkCmsException
- if no new session for the user can't be createdpublic org.apache.commons.collections.Buffer getBroadcastQueue(java.lang.String sessionId)
sessionId
- the OpenCms session id to get the broadcast queue forpublic int getSessionCountAuthenticated()
public int getSessionCountCurrent()
public int getSessionCountTotal()
public CmsSessionInfo getSessionInfo(CmsUUID sessionId)
null
if this session id has no session info attached.sessionId
- the OpenCms session id to return the session info forpublic CmsSessionInfo getSessionInfo(javax.servlet.http.HttpServletRequest req)
null
if no user session is available.req
- the current requestnull
if no user session is availablepublic CmsSessionInfo getSessionInfo(javax.servlet.http.HttpSession session)
null
if no user session is available.session
- the current http sessionnull
if no user session is availablepublic CmsSessionInfo getSessionInfo(java.lang.String sessionId)
null
if this session id has no session info attached.sessionId
- the OpenCms session id to return the session info for,
this must be a String representation of a CmsUUID
getSessionInfo(CmsUUID)
public java.util.List<CmsSessionInfo> getSessionInfos()
public java.util.List<CmsSessionInfo> getSessionInfos(CmsUUID userId)
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.
userId
- the id of the userpublic CmsSystemConfiguration.UserSessionMode getUserSessionMode()
public void killSession(CmsObject cms, CmsUser user) throws CmsException
cms
- the current CMS contextuser
- the user for whom the sessions should be killedCmsException
- if something goes wrongpublic void killSession(CmsObject cms, CmsUUID sessionid) throws CmsException
cms
- the current CMS contextsessionid
- the session idCmsException
- if something goes wrongpublic void sendBroadcast(CmsObject cms, java.lang.String message)
cms
- the OpenCms user context of the user sending the broadcastmessage
- the message to broadcastpublic void sendBroadcast(CmsObject cms, java.lang.String message, java.lang.String sessionId)
cms
- the OpenCms user context of the user sending the broadcastmessage
- the message to broadcastsessionId
- the OpenCms session uuid target (receiver) of the broadcastpublic void sendBroadcast(CmsUser fromUser, java.lang.String message, CmsUser toUser)
The user sending the message may be a real user like
cms.getRequestContext().currentUser()
or
null
for a system message.
fromUser
- the user sending the broadcastmessage
- the message to broadcasttoUser
- the target (receiver) of the broadcastpublic void switchUser(CmsObject cms, javax.servlet.http.HttpServletRequest req, CmsUser user) throws CmsException
cms
- the current CmsObjectreq
- the current requestuser
- the user to switch toCmsException
- if something goes wrongpublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public void updateSessionInfo(CmsObject cms, javax.servlet.http.HttpServletRequest req)
This is required if the user data (current group or project) was changed in the requested document.
The user data is only updated if the user was authenticated to the system.
cms
- the current OpenCms user contextreq
- the current requestpublic void updateSessionInfo(CmsObject cms, javax.servlet.http.HttpSession session)
This is required if the user data (current group or project) was changed in the requested document.
The user data is only updated if the user was authenticated to the system.
cms
- the current OpenCms user contextsession
- the current sessionpublic void updateSessionInfos(CmsObject cms)
cms
- the cms contextprotected void addSessionInfo(CmsSessionInfo sessionInfo)
sessionInfo
- the session info to store for the idprotected CmsUUID getSessionUUID(java.lang.String sessionId)
sessionId
- the session id String to return the UUID representation forprotected void initialize(I_CmsSessionStorageProvider sessionStorageProvider)
sessionStorageProvider
- the storage provider implementationprotected void sessionCreated(javax.servlet.http.HttpSessionEvent event)
OpenCmsListener
when a http session is created.event
- the http session eventHttpSessionListener.sessionCreated(javax.servlet.http.HttpSessionEvent)
,
OpenCmsListener.sessionCreated(HttpSessionEvent)
protected void sessionDestroyed(javax.servlet.http.HttpSessionEvent event)
OpenCmsListener
when a http session is destroyed.event
- the http session eventHttpSessionListener.sessionDestroyed(javax.servlet.http.HttpSessionEvent)
,
OpenCmsListener.sessionDestroyed(HttpSessionEvent)
protected void setUserSessionMode(CmsSystemConfiguration.UserSessionMode userSessionMode)
userSessionMode
- the user session modeprotected void shutdown() throws java.lang.Exception
java.lang.Exception
- if something goes wrongprotected void validateSessionInfos()