Class SessionMonitor
- All Implemented Interfaces:
EventListener
,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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addWikiEventListener
(WikiEventListener listener) Registers a WikiEventListener with this instance.final Session
Looks up the wiki session associated with a user's Http session and adds it to the session cache.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.protected final void
Fires a WikiSecurityEvent to all registered listeners.static SessionMonitor
getInstance
(Engine engine) Returns the instance of the SessionMonitor for this wiki.final void
remove
(javax.servlet.http.HttpServletRequest request) Removes the wiki session associated with the user's HttpRequest from the session cache.final void
remove
(javax.servlet.http.HttpSession session) Removes the wiki session associated with the user's HttpSession from the session cache.final 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.final int
sessions()
Returns the current number of active wiki sessions.final Principal[]
Returns the current wiki users as a sorted array of Principal objects.
-
Constructor Details
-
SessionMonitor
public SessionMonitor()Construct the SessionListener
-
-
Method Details
-
getInstance
Returns the instance of the SessionMonitor for this wiki. Only one SessionMonitor exists per Engine.- Parameters:
engine
- the wiki engine- Returns:
- the session monitor
-
find
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.- Parameters:
session
- the HTTP session- Returns:
- the wiki session
-
find
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.- Parameters:
sessionId
- the HTTP session- Returns:
- the wiki session
-
remove
Removes the wiki session associated with the user's HttpRequest from the session cache.- Parameters:
request
- the user's HTTP request
-
remove
Removes the wiki session associated with the user's HttpSession from the session cache.- Parameters:
session
- the user's HTTP session
-
sessions
Returns the current number of active wiki sessions.- Returns:
- the number of sessions
-
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. ThoseWeakReference
s whoseget()
method returns non-null
values are valid sessions.- Returns:
- the array of user principals
-
addWikiEventListener
Registers a WikiEventListener with this instance.- Parameters:
listener
- the event listener- Since:
- 2.4.75
-
removeWikiEventListener
Un-registers a WikiEventListener with this instance.- Parameters:
listener
- the event listener- Since:
- 2.4.75
-
fireEvent
Fires a WikiSecurityEvent to all registered listeners.- Parameters:
type
- the event typeprincipal
- the user principal associated with this sessionsession
- the wiki session- Since:
- 2.4.75
-
sessionCreated
Fires when the web container creates a new HTTP session.- Specified by:
sessionCreated
in interfacejavax.servlet.http.HttpSessionListener
- Parameters:
se
- the HTTP session event
-
sessionDestroyed
Removes the user's WikiSession from the internal session cache when the web container destroys an HTTP session.- Specified by:
sessionDestroyed
in interfacejavax.servlet.http.HttpSessionListener
- Parameters:
se
- the HTTP session event
-