org.apache.wiki.auth
Class SessionMonitor

java.lang.Object
  extended by org.apache.wiki.auth.SessionMonitor
All Implemented Interfaces:
EventListener, javax.servlet.http.HttpSessionListener

public class SessionMonitor
extends Object
implements javax.servlet.http.HttpSessionListener

Manages WikiSession's for different WikiEngine's.

The WikiSession's are stored both in the remote user HttpSession and in the SessionMonitor for the WikeEngine. This class must be configured as a session listener in the web.xml for the wiki web application.


Constructor Summary
SessionMonitor()
          Construct the SessionListener
 
Method Summary
 void addWikiEventListener(WikiEventListener listener)
          Registers a WikiEventListener with this instance.
 WikiSession 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  void fireEvent(int type, Principal principal, WikiSession session)
          Fires a WikiSecurityEvent to all registered listeners.
static SessionMonitor getInstance(WikiEngine engine)
          Returns the instance of the SessionMonitor for this wiki.
 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 destoys an HTTP session.
 int sessions()
          Returns the current number of active wiki sessions.
 Principal[] userPrincipals()
          Returns the current wiki users as a sorted array of Principal objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionMonitor

public SessionMonitor()
Construct the SessionListener

Method Detail

getInstance

public static final SessionMonitor getInstance(WikiEngine engine)
Returns the instance of the SessionMonitor for this wiki. Only one SessionMonitor exists per WikiEngine.

Parameters:
engine - the wiki engine
Returns:
the session monitor

find

public final WikiSession 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 WikiSession.guestSession(WikiEngine) 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

remove

public final void remove(javax.servlet.http.HttpSession session)
Removes the wiki session associated with the user's HttpSession from the session cache.

Parameters:
session - the user's HTTP session

sessions

public final int sessions()
Returns the current number of active wiki sessions.

Returns:
the number of sessions

userPrincipals

public final Principal[] userPrincipals()

Returns the current wiki users as a sorted array of Principal objects. The principals are those returned by each WikiSession's WikiSession.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.

Returns:
the array of user principals

addWikiEventListener

public final void addWikiEventListener(WikiEventListener listener)
Registers a WikiEventListener with this instance.

Parameters:
listener - the event listener
Since:
2.4.75

removeWikiEventListener

public final void removeWikiEventListener(WikiEventListener listener)
Un-registers a WikiEventListener with this instance.

Parameters:
listener - the event listener
Since:
2.4.75

fireEvent

protected final void fireEvent(int type,
                               Principal principal,
                               WikiSession session)
Fires a WikiSecurityEvent to all registered listeners.

Parameters:
type - the event type
principal - the user principal associated with this session
session - the wiki session
Since:
2.4.75

sessionCreated

public void sessionCreated(javax.servlet.http.HttpSessionEvent se)
Fires when the web container creates a new HTTP session.

Specified by:
sessionCreated in interface javax.servlet.http.HttpSessionListener
Parameters:
se - the HTTP session event

sessionDestroyed

public void sessionDestroyed(javax.servlet.http.HttpSessionEvent se)
Removes the user's WikiSession from the internal session cache when the web container destoys an HTTP session.

Specified by:
sessionDestroyed in interface javax.servlet.http.HttpSessionListener
Parameters:
se - the HTTP session event


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.