Return-Path: Delivered-To: apmail-incubator-jspwiki-commits-archive@minotaur.apache.org Received: (qmail 19368 invoked from network); 13 Sep 2009 17:44:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Sep 2009 17:44:08 -0000 Received: (qmail 54332 invoked by uid 500); 13 Sep 2009 17:44:08 -0000 Delivered-To: apmail-incubator-jspwiki-commits-archive@incubator.apache.org Received: (qmail 54314 invoked by uid 500); 13 Sep 2009 17:44:08 -0000 Mailing-List: contact jspwiki-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jspwiki-dev@incubator.apache.org Delivered-To: mailing list jspwiki-commits@incubator.apache.org Received: (qmail 54305 invoked by uid 99); 13 Sep 2009 17:44:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Sep 2009 17:44:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Sep 2009 17:43:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0F998238888D; Sun, 13 Sep 2009 17:43:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r814354 - in /incubator/jspwiki/trunk/src/java/org/apache/wiki: WikiSession.java auth/SessionMonitor.java Date: Sun, 13 Sep 2009 17:43:38 -0000 To: jspwiki-commits@incubator.apache.org From: ajaquith@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090913174339.0F998238888D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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. *

*/ -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 ); + } + } + } + } /** *

Looks up the wiki session associated with a user's Http session * and adds it to the session cache. This method will return the