You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2009/09/13 19:43:38 UTC

svn commit: r814354 - in /incubator/jspwiki/trunk/src/java/org/apache/wiki: WikiSession.java auth/SessionMonitor.java

Author: ajaquith
Date: Sun Sep 13 17:43:38 2009
New Revision: 814354

URL: http://svn.apache.org/viewvc?rev=814354&view=rev
Log:
Fixed WikiSession/SessionMonitor caching problem that was preventing logins after "instant install" WikiEngine restarts.

Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiSession.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/SessionMonitor.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiSession.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiSession.java?rev=814354&r1=814353&r2=814354&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiSession.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiSession.java Sun Sep 13 17:43:38 2009
@@ -604,6 +604,8 @@
     /**
      * Invalidates the WikiSession and resets its Subject's
      * Principals to the equivalent of a "guest session".
+     * This method also adds the session as a listener
+     * for GroupManager, AuthenticationManager and UserManager events.
      */
     public final void invalidate()
     {
@@ -613,6 +615,14 @@
         m_subject.getPrincipals().add( Role.ALL );
         m_userPrincipal = WikiPrincipal.GUEST;
         m_loginPrincipal = WikiPrincipal.GUEST;
+        
+        // Add the session as listener for GroupManager, AuthManager, UserManager events
+        GroupManager groupMgr = m_engine.getGroupManager();
+        AuthenticationManager authMgr = m_engine.getAuthenticationManager();
+        UserManager userMgr = m_engine.getUserManager();
+        groupMgr.addWikiEventListener( this );
+        authMgr.addWikiEventListener( this );
+        userMgr.addWikiEventListener( this );
     }
 
     /**
@@ -755,8 +765,8 @@
      * Static factory method that creates a new "guest" session containing a single
      * user Principal {@link org.apache.wiki.auth.WikiPrincipal#GUEST},
      * plus the role principals {@link Role#ALL} and
-     * {@link Role#ANONYMOUS}. This method also adds the session as a listener
-     * for GroupManager, AuthenticationManager and UserManager events.
+     * {@link Role#ANONYMOUS}. This method also calls {{@link #invalidate()}
+     * to ensure the session principals and listeners are properly set up.
      * @param engine the wiki engine
      * @return the guest wiki session
      */
@@ -765,15 +775,6 @@
         WikiSession session = new WikiSession();
         session.m_engine = engine;
         session.invalidate();
-
-        // Add the session as listener for GroupManager, AuthManager, UserManager events
-        GroupManager groupMgr = engine.getGroupManager();
-        AuthenticationManager authMgr = engine.getAuthenticationManager();
-        UserManager userMgr = engine.getUserManager();
-        groupMgr.addWikiEventListener( session );
-        authMgr.addWikiEventListener( session );
-        userMgr.addWikiEventListener( session );
-
         return session;
     }
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/SessionMonitor.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/SessionMonitor.java?rev=814354&r1=814353&r2=814354&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/SessionMonitor.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/SessionMonitor.java Sun Sep 13 17:43:38 2009
@@ -32,9 +32,7 @@
 
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiSession;
-import org.apache.wiki.event.WikiEventListener;
-import org.apache.wiki.event.WikiEventManager;
-import org.apache.wiki.event.WikiSecurityEvent;
+import org.apache.wiki.event.*;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
 import org.apache.wiki.rpc.json.JSONRPCManager;
@@ -49,7 +47,7 @@
  *  web.xml for the wiki web application.
  *  </p>
  */
-public class SessionMonitor implements HttpSessionListener, ServletContextListener
+public class SessionMonitor implements HttpSessionListener, ServletContextListener, WikiEventListener
 {
     private static Logger log = LoggerFactory.getLogger( SessionMonitor.class );
 
@@ -83,7 +81,7 @@
             if( monitor == null )
             {
                 monitor = new SessionMonitor(engine);
-
+                engine.addWikiEventListener( monitor );
                 c_monitors.put( engine, monitor );
             }
         }
@@ -128,6 +126,33 @@
 
         return wikiSession;
     }
+    
+    /**
+     * Listens for the WikiEngine shutdown event, and
+     * when received, flushes the session cache and removes
+     * the SessionMonitor instance from the global map.
+     * 
+     * @param event The wiki event to inspect.
+     */
+    public void actionPerformed( WikiEvent event )
+    {
+
+        if( event instanceof WikiEngineEvent )
+        {
+            if( event.getType() == WikiEngineEvent.SHUTDOWN )
+            {
+                log.info( "SessionMonitor detected wiki engine shutdown: flushing session cache and killing self." );
+                synchronized( m_sessions )
+                {
+                    m_sessions.clear();
+                }
+                synchronized( c_monitors )
+                {
+                    c_monitors.remove( m_engine );
+                }
+            }
+        }
+    }
     /**
      * <p>Looks up the wiki session associated with a user's Http session
      * and adds it to the session cache. This method will return the