Author: struberg
Date: Wed Mar 11 13:18:16 2015
New Revision: 1665868
URL: http://svn.apache.org/r1665868
Log:
OWB-1041 provide a sessionId change listener for tomcat
Thanks to Sebastian Gebhardt for porting this over from Apache TomEE.
Added:
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
(with props)
Modified:
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java
Modified:
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java?rev=1665868&r1=1665867&r2=1665868&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java
(original)
+++
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/ContextLifecycleListener.java
Wed Mar 11 13:18:16 2015
@@ -71,6 +71,8 @@ public class ContextLifecycleListener im
context.addApplicationListener(TomcatSecurityFilter.class.getName());
context.addApplicationEventListener(this);
+
+ context.addContainerListener(new
TomcatContainerListener());
}
}
}
Added:
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java?rev=1665868&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
(added)
+++
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
Wed Mar 11 13:18:16 2015
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.webbeans.web.tomcat7;
+
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.SessionContext;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.web.context.SessionContextManager;
+import org.apache.webbeans.web.context.WebContextsService;
+
+/**
+ * Container listener that propagates the change of a session id (e. g. during
an authentication through the container)
+ * to the session context manager. Otherwise a new session context for the
same session is created, because the session
+ * id is used to identify the session context. <br/> Adapted from OpenEJB
tomee/tomee-catalina and updated.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TomcatContainerListener implements ContainerListener
+{
+
+ @Override
+ public void containerEvent(ContainerEvent containerEvent)
+ {
+ if (Context.CHANGE_SESSION_ID_EVENT.equals(containerEvent.getType())
+ && (containerEvent.getData() instanceof String[]))
+ {
+ String[] ids = (String[]) containerEvent.getData();
+
+ if (ids.length >= 2)
+ {
+ WebBeansContext webBeansContext =
WebBeansContext.currentInstance();
+ ContextsService contextsService =
webBeansContext.getContextsService();
+
+ if (contextsService instanceof WebContextsService)
+ {
+ WebContextsService webContextsService =
(WebContextsService) contextsService;
+ SessionContextManager sessionContextManager =
webContextsService.getSessionContextManager();
+
+ SessionContext sessionContext =
sessionContextManager.getSessionContextWithSessionId(ids[0]);
+ if (sessionContext != null)
+ {
+
sessionContextManager.removeSessionContextWithSessionId(ids[0]);
+ sessionContextManager.addNewSessionContext(ids[1],
sessionContext);
+ }
+ }
+ }
+ }
+ }
+}
Propchange:
openwebbeans/trunk/webbeans-tomcat7/src/main/java/org/apache/webbeans/web/tomcat7/TomcatContainerListener.java
------------------------------------------------------------------------------
svn:eol-style = native