Author: mstruk
Date: 2011-02-17 05:45:12 -0500 (Thu, 17 Feb 2011)
New Revision: 5907
Added:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainerVisitor.java
Modified:
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6WebAppContext.java
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6WebAppContext.java
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/WebAppContextImpl.java
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6WebAppContext.java
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/WebApp.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericWebAppContext.java
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/WebAppContext.java
Log:
Cross-context session invalidation on logout - initial implementation
Modified:
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6ServletContainerContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -35,6 +35,8 @@
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.ServletContainerVisitor;
+import org.gatein.wci.WebApp;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.authentication.GenericAuthenticationResult;
@@ -49,6 +51,7 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -128,8 +131,21 @@
public void logout(HttpServletRequest request, HttpServletResponse response) throws
ServletException
{
+ HttpSession sess = request.getSession(false);
request.logout();
- request.getSession().invalidate();
+
+ if (sess == null)
+ return;
+
+ final String sessId = sess.getId();
+
+ DefaultServletContainerFactory.getInstance().getServletContainer().visit(new
ServletContainerVisitor()
+ {
+ public void accept(WebApp webApp)
+ {
+ webApp.invalidateSession(sessId);
+ }
+ });
}
public synchronized void containerEvent(ContainerEvent event)
Modified:
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6WebAppContext.java
===================================================================
---
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6WebAppContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/jboss/jboss6/src/main/java/org/gatein/wci/jboss/JB6WebAppContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -28,6 +28,8 @@
import javax.servlet.ServletContext;
import org.apache.catalina.Context;
+import org.apache.catalina.Manager;
+import org.apache.catalina.Session;
import org.apache.catalina.Wrapper;
import org.gatein.wci.command.CommandServlet;
import org.gatein.wci.spi.WebAppContext;
@@ -125,4 +127,25 @@
{
return false;
}
+
+ public boolean invalidateSession(String sessId)
+ {
+ Manager mgr = context.getManager();
+ if (mgr != null)
+ {
+ try
+ {
+ Session sess = mgr.findSession(sessId);
+ if (sess != null)
+ {
+ sess.expire();
+ return true;
+ }
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+ return false;
+ }
}
Modified:
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6WebAppContext.java
===================================================================
---
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6WebAppContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/jetty/src/main/java/org/gatein/wci/jetty/Jetty6WebAppContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -119,4 +119,9 @@
{
return false;
}
+
+ public boolean invalidateSession(String sessId)
+ {
+ return false;
+ }
}
Modified:
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/WebAppContextImpl.java
===================================================================
---
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/WebAppContextImpl.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/test/core/src/main/java/org/gatein/wci/container/WebAppContextImpl.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -76,4 +76,9 @@
{
throw new UnsupportedOperationException();
}
+
+ public boolean invalidateSession(String sessId)
+ {
+ return false;
+ }
}
Modified:
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6ServletContainerContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -34,6 +34,8 @@
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.ServletContainerVisitor;
+import org.gatein.wci.WebApp;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.command.CommandDispatcher;
@@ -45,6 +47,7 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -106,7 +109,21 @@
public void logout(HttpServletRequest request, HttpServletResponse response)
{
- GenericAuthentication.getInstance().logout(request, response);
+ HttpSession sess = request.getSession(false);
+
+ if (sess == null)
+ return;
+
+ sess.invalidate();
+ final String sessId = sess.getId();
+
+ DefaultServletContainerFactory.getInstance().getServletContainer().visit(new
ServletContainerVisitor()
+ {
+ public void accept(WebApp webApp)
+ {
+ webApp.invalidateSession(sessId);
+ }
+ });
}
public synchronized void containerEvent(ContainerEvent event)
Modified:
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6WebAppContext.java
===================================================================
---
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6WebAppContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/tomcat/tomcat6/src/main/java/org/gatein/wci/tomcat/TC6WebAppContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.gatein.wci.tomcat;
+import org.apache.catalina.Manager;
+import org.apache.catalina.Session;
import org.w3c.dom.Document;
import org.apache.catalina.Context;
import org.apache.catalina.Wrapper;
@@ -124,4 +126,25 @@
{
return false;
}
+
+ public boolean invalidateSession(String sessId)
+ {
+ Manager mgr = context.getManager();
+ if (mgr != null)
+ {
+ try
+ {
+ Session sess = mgr.findSession(sessId);
+ if (sess != null)
+ {
+ sess.expire();
+ return true;
+ }
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+ return false;
+ }
}
Modified:
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java
===================================================================
---
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7ServletContainerContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -36,6 +36,8 @@
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.gatein.wci.RequestDispatchCallback;
+import org.gatein.wci.ServletContainerVisitor;
+import org.gatein.wci.WebApp;
import org.gatein.wci.authentication.AuthenticationResult;
import org.gatein.wci.authentication.GenericAuthentication;
import org.gatein.wci.authentication.GenericAuthenticationResult;
@@ -50,6 +52,7 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -130,8 +133,21 @@
public void logout(HttpServletRequest request, HttpServletResponse response) throws
ServletException
{
+ HttpSession sess = request.getSession(false);
request.logout();
- request.getSession().invalidate();
+
+ if (sess == null)
+ return;
+
+ final String sessId = sess.getId();
+
+ DefaultServletContainerFactory.getInstance().getServletContainer().visit(new
ServletContainerVisitor()
+ {
+ public void accept(WebApp webApp)
+ {
+ webApp.invalidateSession(sessId);
+ }
+ });
}
public synchronized void containerEvent(ContainerEvent event)
Modified:
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java
===================================================================
---
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/tomcat/tomcat7/src/main/java/org/gatein/wci/tomcat/TC7WebAppContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -23,6 +23,8 @@
package org.gatein.wci.tomcat;
import org.apache.catalina.Context;
+import org.apache.catalina.Manager;
+import org.apache.catalina.Session;
import org.apache.catalina.Wrapper;
import org.gatein.wci.command.CommandServlet;
import org.gatein.wci.spi.WebAppContext;
@@ -124,4 +126,25 @@
{
return false;
}
+
+ public boolean invalidateSession(String sessId)
+ {
+ Manager mgr = context.getManager();
+ if (mgr != null)
+ {
+ try
+ {
+ Session sess = mgr.findSession(sessId);
+ if (sess != null)
+ {
+ sess.expire();
+ return true;
+ }
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+ return false;
+ }
}
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainer.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -125,4 +125,11 @@
* @param listener AuthenticationListener to remove
*/
void removeAuthenticationlistener(AuthenticationListener listener);
+
+ /**
+ * Visit the registered WebApps
+ *
+ * @param visitor ServletContainerVisitor instance
+ */
+ void visit(ServletContainerVisitor visitor);
}
Added:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainerVisitor.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainerVisitor.java
(rev 0)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/ServletContainerVisitor.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2011, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.gatein.wci;
+
+/**
+ * @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
+ */
+public interface ServletContainerVisitor
+{
+ /**
+ * During visitation get reference to current WebApp
+ *
+ * @param webApp Currently visited WebApp
+ */
+ public void accept(WebApp webApp);
+}
Modified: components/wci/branches/logout/wci/src/main/java/org/gatein/wci/WebApp.java
===================================================================
--- components/wci/branches/logout/wci/src/main/java/org/gatein/wci/WebApp.java 2011-02-17
10:20:48 UTC (rev 5906)
+++ components/wci/branches/logout/wci/src/main/java/org/gatein/wci/WebApp.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -72,4 +72,12 @@
* @throws IOException if the file cannot be created
*/
boolean importFile(String parentDirRelativePath, String name, InputStream source,
boolean overwrite) throws IOException;
+
+ /**
+ * Invalidate session for the specified id.
+ *
+ * @param sessId Session id
+ * @return true if session was found, false otherwise
+ */
+ public boolean invalidateSession(String sessId);
}
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/DefaultServletContainer.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.gatein.wci.impl;
+import org.gatein.wci.ServletContainerVisitor;
import org.gatein.wci.authentication.AuthenticationEvent;
import org.gatein.wci.authentication.AuthenticationListener;
import org.gatein.wci.authentication.AuthenticationResult;
@@ -266,6 +267,17 @@
return registration.context.include(targetServletContext, request, response,
callback, handback);
}
+ public void visit(ServletContainerVisitor visitor)
+ {
+ synchronized (lock)
+ {
+ for (WebApp webApp: webAppMap.values())
+ {
+ visitor.accept(webApp);
+ }
+ }
+ }
+
public static enum EventType {
LOGIN, LOGOUT
}
@@ -429,5 +441,10 @@
{
return context.importFile(parentDirRelativePath, name, source, overwrite);
}
+
+ public boolean invalidateSession(String sessId)
+ {
+ return context.invalidateSession(sessId);
+ }
}
}
\ No newline at end of file
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericWebAppContext.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericWebAppContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/impl/generic/GenericWebAppContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -78,4 +78,9 @@
{
return false;
}
+
+ public boolean invalidateSession(String sessId)
+ {
+ return false;
+ }
}
\ No newline at end of file
Modified:
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/WebAppContext.java
===================================================================
---
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/WebAppContext.java 2011-02-17
10:20:48 UTC (rev 5906)
+++
components/wci/branches/logout/wci/src/main/java/org/gatein/wci/spi/WebAppContext.java 2011-02-17
10:45:12 UTC (rev 5907)
@@ -86,4 +86,12 @@
* @throws java.io.IOException if the file cannot be created
*/
boolean importFile(String parentDirRelativePath, String name, InputStream source,
boolean overwrite) throws IOException;
+
+ /**
+ * Invalidate session for the specified id.
+ *
+ * @param sessId Session id
+ * @return true if session was found, false otherwise
+ */
+ boolean invalidateSession(String sessId);
}