public class SessionMonitor extends java.lang.Object implements javax.servlet.http.HttpSessionListener
Manages Sessions for different Engines.
The Sessions are stored both in the remote user HttpSession and in the SessionMonitor for the Engine. This class must be configured as a session listener in the web.xml for the wiki web application.
| Constructor and Description |
|---|
SessionMonitor()
Construct the SessionListener
|
| Modifier and Type | Method and Description |
|---|---|
void |
addWikiEventListener(WikiEventListener listener)
Registers a WikiEventListener with this instance.
|
Session |
find(javax.servlet.http.HttpSession session)
Looks up the wiki session associated with a user's Http session and adds it to the session cache.
|
Session |
find(java.lang.String sessionId)
Looks up the wiki session associated with a user's Http session and adds it to the session cache.
|
protected void |
fireEvent(int type,
java.security.Principal principal,
Session session)
Fires a WikiSecurityEvent to all registered listeners.
|
static SessionMonitor |
getInstance(Engine engine)
Returns the instance of the SessionMonitor for this wiki.
|
void |
remove(javax.servlet.http.HttpServletRequest request)
Removes the wiki session associated with the user's HttpRequest from the session cache.
|
void |
remove(javax.servlet.http.HttpSession session)
Removes the wiki session associated with the user's HttpSession from the session cache.
|
void |
removeWikiEventListener(WikiEventListener listener)
Un-registers a WikiEventListener with this instance.
|
void |
sessionCreated(javax.servlet.http.HttpSessionEvent se)
Fires when the web container creates a new HTTP session.
|
void |
sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
Removes the user's WikiSession from the internal session cache when the web
container destroys an HTTP session.
|
int |
sessions()
Returns the current number of active wiki sessions.
|
java.security.Principal[] |
userPrincipals()
Returns the current wiki users as a sorted array of Principal objects.
|
public SessionMonitor()
public static SessionMonitor getInstance(Engine engine)
engine - the wiki enginepublic final Session find(javax.servlet.http.HttpSession session)
Looks up the wiki session associated with a user's Http session and adds it to the session cache. This method will return the
"guest session" as constructed by SessionSPI.guest(Engine) if the HttpSession is not currently
associated with a WikiSession. This method is guaranteed to return a non-null WikiSession.
Internally, the session is stored in a HashMap; keys are the HttpSession objects, while the values are
WeakReference-wrapped WikiSessions.
session - the HTTP sessionpublic final Session find(java.lang.String sessionId)
Looks up the wiki session associated with a user's Http session and adds it to the session cache. This method will return the
"guest session" as constructed by SessionSPI.guest(Engine) if the HttpSession is not currently
associated with a WikiSession. This method is guaranteed to return a non-null WikiSession.
Internally, the session is stored in a HashMap; keys are the HttpSession objects, while the values are
WeakReference-wrapped WikiSessions.
sessionId - the HTTP sessionpublic final void remove(javax.servlet.http.HttpServletRequest request)
request - the user's HTTP requestpublic final void remove(javax.servlet.http.HttpSession session)
session - the user's HTTP sessionpublic final int sessions()
public final java.security.Principal[] userPrincipals()
Returns the current wiki users as a sorted array of Principal objects. The principals are those returned by
each WikiSession's Session.getUserPrincipal()'s method.
To obtain the list of current WikiSessions, we iterate through our session Map and obtain the list of values,
which are WikiSessions wrapped in WeakReference objects. Those WeakReferences
whose get() method returns non-null values are valid sessions.
public final void addWikiEventListener(WikiEventListener listener)
listener - the event listenerpublic final void removeWikiEventListener(WikiEventListener listener)
listener - the event listenerprotected final void fireEvent(int type, java.security.Principal principal, Session session)
type - the event typeprincipal - the user principal associated with this sessionsession - the wiki sessionpublic void sessionCreated(javax.servlet.http.HttpSessionEvent se)
sessionCreated in interface javax.servlet.http.HttpSessionListenerse - the HTTP session eventpublic void sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
sessionDestroyed in interface javax.servlet.http.HttpSessionListenerse - the HTTP session eventCopyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.