Add container session listener that will destroy IdP sessions if the container sessio...
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 31 Dec 2007 09:28:40 +0000 (09:28 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 31 Dec 2007 09:28:40 +0000 (09:28 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2508 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

resources/WEB-INF/web.xml
src/edu/internet2/middleware/shibboleth/idp/session/ContainerSessionListener.java [new file with mode: 0644]

index 8059ed4..a38feee 100644 (file)
         <param-value>file://$IDP_HOME$/conf/internal.xml; file://$IDP_HOME$/conf/service.xml;</param-value>
     </context-param>
 
-    <!-- 
-        Spring 2.0 listener used to load up the configuration
-    -->
+    <!-- Spring 2.0 listener used to load up the configuration -->
     <listener>
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
 
+    <!-- Hook IdP sessions into HTTP servlet container sessions. -->
+    <listener>
+        <listener-class>edu.internet2.middleware.shibboleth.idp.session.ContainerSessionListener</listener-class>
+    </listener>
+    
     <!-- 
         Session time inactivity timeout, in minutes.
         
diff --git a/src/edu/internet2/middleware/shibboleth/idp/session/ContainerSessionListener.java b/src/edu/internet2/middleware/shibboleth/idp/session/ContainerSessionListener.java
new file mode 100644 (file)
index 0000000..875669b
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package edu.internet2.middleware.shibboleth.idp.session;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+import edu.internet2.middleware.shibboleth.common.session.SessionManager;
+
+/**
+ * A listener that listens for the destruction of {@link HttpSession}s. This allows the {@link SessionManager} to
+ * appropriately destroy a shibboleth session whether the HTTP session is destroyed explicitly or through inactivity.
+ */
+public class ContainerSessionListener implements HttpSessionListener {
+
+    /**
+     * A no-op operation.
+     */
+    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
+        // we don't care about session creations
+    }
+
+    /** {@inheritDoc} */
+    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
+        HttpSession httpSession = httpSessionEvent.getSession();
+        SessionManager<Session> sessionManager = (SessionManager<Session>) httpSession.getServletContext()
+                .getAttribute("sessionManager");
+
+        sessionManager.destroySession((String) httpSession.getAttribute(Session.HTTP_SESSION_BINDING_ATTRIBUTE));
+    }
+}
\ No newline at end of file