org.olat.core.util
Class UserSession

java.lang.Object
  extended by org.olat.core.util.UserSession
All Implemented Interfaces:
java.util.EventListener, javax.servlet.http.HttpSessionBindingListener, GenericEventListener

public class UserSession
extends java.lang.Object
implements javax.servlet.http.HttpSessionBindingListener, GenericEventListener

Description:
the httpsession contains an instance of this class. the UserSession is either authenticated or not; and if it is, then it also contains things like the Identity, the locale etc. of the current user.

Author:
Felix Jost

Field Summary
static OLATResourceable ORES_USERSESSION
           
static java.lang.String STORE_KEY_KILLED_EXISTING_SESSION
           
 
Method Summary
 void event(Event event)
          only for SignOffEvents - Usersession keeps book about usernames - WindowManager responsible to dispose controller chain
static java.util.Set getAuthenticatedUserSessions()
           
 java.lang.Object getEntry(java.lang.String key)
           
 Preferences getGuiPreferences()
           
 Identity getIdentity()
           
 IdentityEnvironment getIdentityEnvironment()
           
 java.util.Locale getLocale()
           
 Roles getRoles()
           
 java.lang.Object getServiceInstance(java.lang.Class serviceInterfaceName)
           
 SessionInfo getSessionInfo()
          may be null
static Identity getSignedOnIdentity(java.lang.String userName)
           
 EventBus getSingleUserEventCenter()
          This is the olatsystembus to broadcast event amongst controllers of a single user only (the one whom this usersession belongs to)
static UserSession getUserSession(javax.servlet.http.HttpServletRequest hreq)
           
static UserSession getUserSession(javax.servlet.http.HttpSession session)
           
static UserSession getUserSessionIfAlreadySet(javax.servlet.http.HttpServletRequest hreq)
          Return the UserSession of the given request if it is already set or null otherwise
static int getUserSessionsCnt()
           
static int invalidateAllSessions()
          Invalidate all sessions except admin-sessions.
static int invalidateOldestSessions(int nbrSessions)
          Invalidate a given number of oldest (last-click-time) sessions except admin-sessions.
 boolean isAuthenticated()
           
 void putEntry(java.lang.String key, java.lang.Object o)
           
 void putEntryInNonClearedStore(java.lang.Object key, java.lang.Object o)
          put an entry in the usersession that even survives login/logouts from the users.
 java.lang.Object removeEntry(java.lang.Object key)
           
 java.lang.Object removeEntryFromNonClearedStore(java.lang.Object key)
           
static void setGlobalSessionTimeout(int sessionTimeoutInSec)
          set session timeout on http session -
 void setIdentity(Identity identity)
          Sets the identity.
 void setLocale(java.util.Locale locale)
          Sets the locale.
 void setRoles(Roles roles)
          Sets the roles.
 void setSessionInfo(SessionInfo sessionInfo)
           
 void signOffAndClear()
          called to make sure the current authenticated user (if there is one at all) is cleared and signed off.
 void signOn()
          prior to calling this method, all instance vars must be set.
 java.lang.String toString()
           
 void valueBound(javax.servlet.http.HttpSessionBindingEvent be)
           
 void valueUnbound(javax.servlet.http.HttpSessionBindingEvent be)
          called when the session is invalidated either by app.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ORES_USERSESSION

public static final OLATResourceable ORES_USERSESSION

STORE_KEY_KILLED_EXISTING_SESSION

public static final java.lang.String STORE_KEY_KILLED_EXISTING_SESSION
See Also:
Constant Field Values
Method Detail

getServiceInstance

public java.lang.Object getServiceInstance(java.lang.Class serviceInterfaceName)
Parameters:
serviceInterfaceName -
Returns:
an instance of the service which belongs to exactly this usersession (= user scope)

getUserSession

public static UserSession getUserSession(javax.servlet.http.HttpSession session)
Parameters:
session -
Returns:
associated user session

getUserSession

public static UserSession getUserSession(javax.servlet.http.HttpServletRequest hreq)
Parameters:
hreq -
Returns:
associated user session

getUserSessionIfAlreadySet

public static UserSession getUserSessionIfAlreadySet(javax.servlet.http.HttpServletRequest hreq)
Return the UserSession of the given request if it is already set or null otherwise

Parameters:
hreq -
Returns:

isAuthenticated

public boolean isAuthenticated()
Returns:
true if is authenticated

putEntry

public void putEntry(java.lang.String key,
                     java.lang.Object o)
Parameters:
key -
o -

getEntry

public java.lang.Object getEntry(java.lang.String key)
Parameters:
key -
Returns:
entry

removeEntry

public java.lang.Object removeEntry(java.lang.Object key)
Parameters:
key -
Returns:
removed entry

putEntryInNonClearedStore

public void putEntryInNonClearedStore(java.lang.Object key,
                                      java.lang.Object o)
put an entry in the usersession that even survives login/logouts from the users. needed e.g. for a direct jump url, when the url is remembered in the dmz, but used in auth. since a login occurs, all data from the previous user will be cleared, that is why we introduced this store.

Parameters:
key -
o -

removeEntryFromNonClearedStore

public java.lang.Object removeEntryFromNonClearedStore(java.lang.Object key)
Parameters:
key -
Returns:
removed entry

getLocale

public java.util.Locale getLocale()
Returns:
Locale

getIdentity

public Identity getIdentity()
Returns:
Identity

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale.

Parameters:
locale - The locale to set

setIdentity

public void setIdentity(Identity identity)
Sets the identity.

Parameters:
identity - The identity to set

getRoles

public Roles getRoles()
Returns:
Roles

setRoles

public void setRoles(Roles roles)
Sets the roles.

Parameters:
roles - The roles to set

valueBound

public void valueBound(javax.servlet.http.HttpSessionBindingEvent be)
Specified by:
valueBound in interface javax.servlet.http.HttpSessionBindingListener
See Also:
HttpSessionBindingListener.valueBound(javax.servlet.http.HttpSessionBindingEvent)

valueUnbound

public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent be)
called when the session is invalidated either by app. server timeout or manual session.invalidate (logout)

Specified by:
valueUnbound in interface javax.servlet.http.HttpSessionBindingListener
See Also:
HttpSessionBindingListener.valueUnbound(javax.servlet.http.HttpSessionBindingEvent)

signOffAndClear

public void signOffAndClear()
called to make sure the current authenticated user (if there is one at all) is cleared and signed off. This method is firing the SignOnOffEvent Multiuserevent.


signOn

public void signOn()
prior to calling this method, all instance vars must be set.


getSignedOnIdentity

public static Identity getSignedOnIdentity(java.lang.String userName)
Parameters:
userName -
Returns:
the identity or null if no user with userName is currently logged on

getAuthenticatedUserSessions

public static java.util.Set getAuthenticatedUserSessions()
Returns:
set of authenticated active user sessions

toString

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

getIdentityEnvironment

public IdentityEnvironment getIdentityEnvironment()
Returns:
identity environment

getSessionInfo

public SessionInfo getSessionInfo()
may be null

Returns:
session info object

setSessionInfo

public void setSessionInfo(SessionInfo sessionInfo)
Parameters:
sessionInfo -

getUserSessionsCnt

public static int getUserSessionsCnt()
Returns:
Returns the userSessionsCnt.

getGuiPreferences

public Preferences getGuiPreferences()
Returns:
Returns the guiPreferences.

getSingleUserEventCenter

public EventBus getSingleUserEventCenter()
This is the olatsystembus to broadcast event amongst controllers of a single user only (the one whom this usersession belongs to)

Returns:
the olatsystembus for the local user

event

public void event(Event event)
only for SignOffEvents - Usersession keeps book about usernames - WindowManager responsible to dispose controller chain

Specified by:
event in interface GenericEventListener
See Also:
GenericEventListener.event(org.olat.core.gui.control.Event)

invalidateAllSessions

public static int invalidateAllSessions()
Invalidate all sessions except admin-sessions.

Returns:
Number of invalidated sessions.

invalidateOldestSessions

public static int invalidateOldestSessions(int nbrSessions)
Invalidate a given number of oldest (last-click-time) sessions except admin-sessions.

Parameters:
nbrSessions - number of sessions whisch will be invalidated
Returns:
Number of invalidated sessions.

setGlobalSessionTimeout

public static void setGlobalSessionTimeout(int sessionTimeoutInSec)
set session timeout on http session -

Parameters:
sessionTimeoutInSec -