You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2006/02/04 22:20:23 UTC
svn commit: r374928 - in /geronimo/branches/1.0/modules/tomcat/src:
java/org/apache/geronimo/tomcat/ java/org/apache/geronimo/tomcat/interceptor/
java/org/apache/geronimo/tomcat/listener/
java/org/apache/geronimo/tomcat/realm/ java/org/apache/geronimo/...
Author: jgenender
Date: Sat Feb 4 13:20:17 2006
New Revision: 374928
URL: http://svn.apache.org/viewcvs?rev=374928&view=rev
Log:
Fix for GERONIMO-1480
Added:
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
Removed:
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/ComponentContextValve.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/InstanceContextValve.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/PolicyContextValve.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/TransactionContextValve.java
Modified:
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java
geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java
Modified: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java?rev=374928&r1=374927&r2=374928&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java Sat Feb 4 13:20:17 2006
@@ -88,15 +88,16 @@
//Set the parameters
setParameters(engine, initParams);
+ //Set realm (must be before Hosts)
+ if (realmGBean != null){
+ engine.setRealm((Realm)realmGBean.getInternalObject());
+ }
+
//Set the default Host
final String defaultHostName = ((Host)defaultHost.getInternalObject()).getName();
engine.setDefaultHost(defaultHostName);
addHost(defaultHost);
- if (realmGBean != null){
- engine.setRealm((Realm)realmGBean.getInternalObject());
- }
-
if (manager != null)
engine.setManager((Manager)manager.getInternalObject());
Modified: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=374928&r1=374927&r2=374928&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java Sat Feb 4 13:20:17 2006
@@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+
import javax.naming.NamingException;
import javax.security.auth.Subject;
import javax.security.jacc.PolicyContext;
@@ -34,27 +35,28 @@
import org.apache.catalina.cluster.CatalinaCluster;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
-import org.apache.catalina.valves.ValveBase;
import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.valves.ValveBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.geronimo.common.DeploymentException;
import org.apache.geronimo.kernel.StoredObject;
+import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
import org.apache.geronimo.naming.reference.ClassLoaderAwareReference;
import org.apache.geronimo.naming.reference.KernelAwareReference;
-import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
import org.apache.geronimo.security.ContextManager;
import org.apache.geronimo.security.IdentificationPrincipal;
import org.apache.geronimo.security.SubjectId;
import org.apache.geronimo.security.deploy.DefaultPrincipal;
import org.apache.geronimo.security.util.ConfigurationUtil;
+import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
+import org.apache.geronimo.tomcat.interceptor.ComponentContextBeforeAfter;
+import org.apache.geronimo.tomcat.interceptor.InstanceContextBeforeAfter;
+import org.apache.geronimo.tomcat.interceptor.PolicyContextBeforeAfter;
+import org.apache.geronimo.tomcat.interceptor.TransactionContextBeforeAfter;
import org.apache.geronimo.tomcat.util.SecurityHolder;
-import org.apache.geronimo.tomcat.valve.ComponentContextValve;
import org.apache.geronimo.tomcat.valve.DefaultSubjectValve;
-import org.apache.geronimo.tomcat.valve.InstanceContextValve;
-import org.apache.geronimo.tomcat.valve.PolicyContextValve;
-import org.apache.geronimo.tomcat.valve.TransactionContextValve;
+import org.apache.geronimo.tomcat.valve.GeronimoBeforeAfterValve;
import org.apache.geronimo.transaction.context.TransactionContextManager;
import org.apache.geronimo.webservices.POJOWebServiceServlet;
import org.apache.geronimo.webservices.WebServiceContainer;
@@ -72,7 +74,10 @@
private Map webServiceMap = null;
private boolean pipelineInitialized;
-
+
+ private BeforeAfter beforeAfter = null;
+ private int contextCount = 0;
+
public void setContextProperties(TomcatContext ctx) throws DeploymentException {
// Create ReadOnlyContext
javax.naming.Context enc = null;
@@ -93,28 +98,25 @@
} catch (NamingException ne) {
log.error(ne);
}
+
+ int index = 0;
+ BeforeAfter interceptor = new InstanceContextBeforeAfter(null, index++,
+ ctx.getUnshareableResources(),
+ ctx.getApplicationManagedSecurityResources(),
+ ctx.getTrackedConnectionAssociator());
- //Set the InstanceContextValve
- InstanceContextValve instanceContextValve =
- new InstanceContextValve(ctx.getUnshareableResources(),
- ctx.getApplicationManagedSecurityResources(),
- ctx.getTrackedConnectionAssociator());
- addValve(instanceContextValve);
-
- // Set ComponentContext valve
+ // Set ComponentContext BeforeAfter
if (enc != null) {
- ComponentContextValve contextValve = new ComponentContextValve(enc);
- addValve(contextValve);
+ interceptor = new ComponentContextBeforeAfter(interceptor, index++, enc);
}
- // Set TransactionContextValve
+ // Set TransactionContext BeforeAfter
TransactionContextManager transactionContextManager = ctx.getTransactionContextManager();
if (transactionContextManager != null) {
- TransactionContextValve transactionValve = new TransactionContextValve(transactionContextManager);
- addValve(transactionValve);
+ interceptor = new TransactionContextBeforeAfter(interceptor, index++, transactionContextManager);
}
- //Set a PolicyContext Valve
+ //Set a PolicyContext BeforeAfter
SecurityHolder securityHolder = ctx.getSecurityHolder();
if (securityHolder != null) {
if (securityHolder.getPolicyContextID() != null) {
@@ -132,11 +134,16 @@
defaultSubject.getPrincipals().add(new IdentificationPrincipal(id));
}
- PolicyContextValve policyValve = new PolicyContextValve(securityHolder.getPolicyContextID());
- addValve(policyValve);
+ interceptor = new PolicyContextBeforeAfter(interceptor, index++, securityHolder.getPolicyContextID());
}
}
-
+
+ //Set the BeforeAfters as a valve
+ GeronimoBeforeAfterValve geronimoBAValve = new GeronimoBeforeAfterValve(interceptor, index);
+ addValve(geronimoBAValve);
+ beforeAfter = interceptor;
+ contextCount = index;
+
//Not clear if user defined valves should be involved in init processing. Probably not since
//request and response are null.
@@ -164,6 +171,9 @@
this.webServiceMap = ctx.getWebServices();
this.setCrossContext(ctx.isCrossContext());
+
+ //Set the Dispatch listener
+ this.addInstanceListener("org.apache.geronimo.tomcat.listener.DispatchListener");
}
public synchronized void start() throws LifecycleException {
@@ -173,6 +183,7 @@
valve.invoke(null, null);
//Install the DefaultSubjectValve after the authentication valve so the default subject is supplied
//only if no real subject is authenticated.
+
Valve defaultSubjectValve = new DefaultSubjectValve(defaultSubject);
addValve(defaultSubjectValve);
} catch (IOException e) {
@@ -264,4 +275,14 @@
}
}
+
+
+ public BeforeAfter getBeforeAfter() {
+ return beforeAfter;
+ }
+
+ public int getContextCount() {
+ return contextCount;
+ }
+
}
Added: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java?rev=374928&view=auto
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java (added)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/BeforeAfter.java Sat Feb 4 13:20:17 2006
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * 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 org.apache.geronimo.tomcat.interceptor;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public interface BeforeAfter {
+
+ void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse);
+
+ void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse);
+
+}
Added: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java?rev=374928&view=auto
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java (added)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/ComponentContextBeforeAfter.java Sat Feb 4 13:20:17 2006
@@ -0,0 +1,51 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ * 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 org.apache.geronimo.tomcat.interceptor;
+
+import javax.naming.Context;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.geronimo.naming.java.RootContext;
+
+public class ComponentContextBeforeAfter implements BeforeAfter{
+ private final BeforeAfter next;
+ private final int index;
+ private final Context componentContext;
+
+ public ComponentContextBeforeAfter(BeforeAfter next, int index, Context componentContext) {
+ this.next = next;
+ this.index = index;
+ this.componentContext = componentContext;
+ }
+
+ public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) {
+ context[index] = RootContext.getComponentContext();
+ RootContext.setComponentContext(componentContext);
+ if (next != null) {
+ next.before(context, httpRequest, httpResponse);
+ }
+ }
+
+ public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) {
+ if (next != null) {
+ next.after(context, httpRequest, httpResponse);
+ }
+ RootContext.setComponentContext((Context) context[index]);
+ }
+
+}
Added: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java?rev=374928&view=auto
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java (added)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/InstanceContextBeforeAfter.java Sat Feb 4 13:20:17 2006
@@ -0,0 +1,66 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ * 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 org.apache.geronimo.tomcat.interceptor;
+
+import java.util.Set;
+
+import javax.resource.ResourceException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.geronimo.transaction.DefaultInstanceContext;
+import org.apache.geronimo.transaction.InstanceContext;
+import org.apache.geronimo.transaction.TrackedConnectionAssociator;
+
+public class InstanceContextBeforeAfter implements BeforeAfter{
+
+ private final BeforeAfter next;
+ private final int index;
+ private final Set unshareableResources;
+ private final Set applicationManagedSecurityResources;
+ private final TrackedConnectionAssociator trackedConnectionAssociator;
+
+ public InstanceContextBeforeAfter(BeforeAfter next, int index, Set unshareableResources, Set applicationManagedSecurityResources, TrackedConnectionAssociator trackedConnectionAssociator) {
+ this.next = next;
+ this.index = index;
+ this.unshareableResources = unshareableResources;
+ this.applicationManagedSecurityResources = applicationManagedSecurityResources;
+ this.trackedConnectionAssociator = trackedConnectionAssociator;
+ }
+
+ public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) {
+ try {
+ context[index] = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources));
+ } catch (ResourceException e) {
+ throw new RuntimeException(e);
+ }
+ if (next != null) {
+ next.before(context, httpRequest, httpResponse);
+ }
+ }
+
+ public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) {
+ if (next != null) {
+ next.after(context, httpRequest, httpResponse);
+ }
+ try {
+ trackedConnectionAssociator.exit((InstanceContext) context[index]);
+ } catch (ResourceException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Added: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java?rev=374928&view=auto
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java (added)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java Sat Feb 4 13:20:17 2006
@@ -0,0 +1,89 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ * 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 org.apache.geronimo.tomcat.interceptor;
+
+import javax.security.auth.Subject;
+import javax.security.jacc.PolicyContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.catalina.connector.Request;
+import org.apache.geronimo.tomcat.realm.TomcatGeronimoRealm;
+
+public class PolicyContextBeforeAfter implements BeforeAfter{
+
+ private final BeforeAfter next;
+ private final String policyContextID;
+ private final int policyContextIDIndex;
+
+ public PolicyContextBeforeAfter(BeforeAfter next, int policyContextIDIndex, String policyContextID) {
+ this.next = next;
+ this.policyContextIDIndex = policyContextIDIndex;
+ this.policyContextID = policyContextID;
+ }
+
+ public void before(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) {
+
+ //Save the old
+ PolicyObject policyObject = new PolicyObject();
+ policyObject.setContextId(PolicyContext.getContextID());
+ //Save the old Request object in case it gets changed
+ //with a x-context Dispatch
+ policyObject.setRequest(TomcatGeronimoRealm.getRequest());
+
+ context[policyContextIDIndex] = policyObject;
+
+ //Set the new
+ PolicyContext.setContextID(policyContextID);
+ PolicyContext.setHandlerData(httpRequest);
+
+ if (next != null) {
+ next.before(context, httpRequest, httpResponse);
+ }
+ }
+
+ public void after(Object[] context, ServletRequest httpRequest, ServletResponse httpResponse) {
+ if (next != null) {
+ next.after(context, httpRequest, httpResponse);
+ }
+
+ //Replace the old
+ PolicyObject policyObject = (PolicyObject)context[policyContextIDIndex];
+
+ PolicyContext.setContextID(policyObject.getContextId());
+ TomcatGeronimoRealm.setRequest(policyObject.getRequest());
+ }
+
+ class PolicyObject{
+ private String contextId = null;
+ private Request request = null;
+
+ public String getContextId() {
+ return contextId;
+ }
+ public void setContextId(String contextId) {
+ this.contextId = contextId;
+ }
+ public Request getRequest() {
+ return request;
+ }
+ public void setRequest(Request request) {
+ this.request = request;
+ }
+ }
+
+}
Added: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java?rev=374928&view=auto
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java (added)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/TransactionContextBeforeAfter.java Sat Feb 4 13:20:17 2006
@@ -0,0 +1,132 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ * 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 org.apache.geronimo.tomcat.interceptor;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import org.apache.geronimo.transaction.context.TransactionContext;
+import org.apache.geronimo.transaction.context.TransactionContextManager;
+
+public class TransactionContextBeforeAfter implements BeforeAfter {
+ private final BeforeAfter next;
+
+ private final int txIndex;
+
+ private final TransactionContextManager transactionContextManager;
+
+ public TransactionContextBeforeAfter(BeforeAfter next, int txIndex,
+ TransactionContextManager transactionContextManager) {
+ this.next = next;
+ this.txIndex = txIndex;
+ this.transactionContextManager = transactionContextManager;
+ }
+
+ public void before(Object[] context, ServletRequest httpRequest,
+ ServletResponse httpResponse) {
+ TransactionContextHolder tch = new TransactionContextHolder();
+ TransactionContext oldTransactionContext = transactionContextManager
+ .getContext();
+ TransactionContext newTransactionContext = null;
+ if (oldTransactionContext == null
+ || !oldTransactionContext.isInheritable()) {
+ newTransactionContext = transactionContextManager
+ .newUnspecifiedTransactionContext();
+ }
+
+ tch.setOldContext(oldTransactionContext);
+ tch.setNewContext(newTransactionContext);
+ context[txIndex] = tch;
+
+ if (next != null) {
+ next.before(context, httpRequest, httpResponse);
+ }
+ }
+
+ public void after(Object[] context, ServletRequest httpRequest,
+ ServletResponse httpResponse) {
+ try {
+ if (next != null) {
+ next.after(context, httpRequest, httpResponse);
+ }
+ } finally {
+ TransactionContextHolder tch = (TransactionContextHolder) context[txIndex];
+ TransactionContext oldTransactionContext = tch.getOldContext();
+ TransactionContext newTransactionContext = tch.getNewContext();
+ try {
+ if (newTransactionContext != null) {
+ if (newTransactionContext != transactionContextManager
+ .getContext()) {
+ transactionContextManager.getContext().rollback();
+ newTransactionContext.rollback();
+ throw new RuntimeException(
+ "WRONG EXCEPTION! returned from servlet call with wrong tx context");
+ }
+ newTransactionContext.commit();
+
+ } else {
+ if (oldTransactionContext != transactionContextManager
+ .getContext()) {
+ if (transactionContextManager.getContext() != null) {
+ transactionContextManager.getContext().rollback();
+ }
+ throw new RuntimeException(
+ "WRONG EXCEPTION! returned from servlet call with wrong tx context");
+ }
+ }
+ } catch (SystemException e) {
+ throw new RuntimeException("WRONG EXCEPTION!", e);
+ } catch (HeuristicMixedException e) {
+ throw new RuntimeException("WRONG EXCEPTION!", e);
+ } catch (HeuristicRollbackException e) {
+ throw new RuntimeException("WRONG EXCEPTION!", e);
+ } catch (RollbackException e) {
+ throw new RuntimeException("WRONG EXCEPTION!", e);
+ } finally {
+ // this is redundant when we enter with an inheritable context
+ // and nothing goes wrong.
+ transactionContextManager.setContext(oldTransactionContext);
+ }
+ }
+ }
+
+ class TransactionContextHolder {
+ private TransactionContext oldContext;
+
+ private TransactionContext newContext;
+
+ public TransactionContext getNewContext() {
+ return newContext;
+ }
+
+ public void setNewContext(TransactionContext newContext) {
+ this.newContext = newContext;
+ }
+
+ public TransactionContext getOldContext() {
+ return oldContext;
+ }
+
+ public void setOldContext(TransactionContext oldContext) {
+ this.oldContext = oldContext;
+ }
+ }
+}
Added: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java?rev=374928&view=auto
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java (added)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java Sat Feb 4 13:20:17 2006
@@ -0,0 +1,80 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ * 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 org.apache.geronimo.tomcat.listener;
+
+import java.util.Stack;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.InstanceEvent;
+import org.apache.catalina.InstanceListener;
+import org.apache.geronimo.tomcat.GeronimoStandardContext;
+import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
+
+public class DispatchListener implements InstanceListener {
+
+ //private static StackThreadLocal currentContext = new ThreadLocal();
+ private static ThreadLocal currentContext = new ThreadLocal() {
+ protected Object initialValue() {
+ return new Stack();
+ }
+ };
+
+ public void instanceEvent(InstanceEvent event) {
+
+ if (event.getType().equals(InstanceEvent.BEFORE_DISPATCH_EVENT)) {
+
+ Container parent = event.getWrapper().getParent();
+ if (parent instanceof GeronimoStandardContext) {
+ beforeDispatch((GeronimoStandardContext) parent, event
+ .getRequest(), event.getResponse());
+ }
+ }
+
+ if (event.getType().equals(InstanceEvent.AFTER_DISPATCH_EVENT)) {
+ Container parent = event.getWrapper().getParent();
+ if (parent instanceof GeronimoStandardContext) {
+ afterDispatch((GeronimoStandardContext) parent, event
+ .getRequest(), event.getResponse());
+ }
+ }
+ }
+
+ private void beforeDispatch(GeronimoStandardContext webContext,
+ ServletRequest request, ServletResponse response) {
+ BeforeAfter beforeAfter = webContext.getBeforeAfter();
+ if (beforeAfter != null) {
+ Stack stack = (Stack) currentContext.get();
+ Object context[] = new Object[webContext.getContextCount()];
+ beforeAfter.before(context, request, response);
+ stack.push(context);
+ }
+ }
+
+ private void afterDispatch(GeronimoStandardContext webContext,
+ ServletRequest request, ServletResponse response) {
+ BeforeAfter beforeAfter = webContext.getBeforeAfter();
+ if (beforeAfter != null) {
+ Stack stack = (Stack) currentContext.get();
+ Object context[] = (Object[]) stack.pop();
+ beforeAfter.after(context, request, response);
+ }
+ }
+
+}
Modified: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java?rev=374928&r1=374927&r2=374928&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java Sat Feb 4 13:20:17 2006
@@ -44,6 +44,8 @@
import javax.security.jacc.WebResourcePermission;
import javax.security.jacc.WebRoleRefPermission;
import javax.security.jacc.WebUserDataPermission;
+import javax.servlet.ServletRequest;
+
import java.io.IOException;
import java.security.AccessControlContext;
import java.security.AccessControlException;
@@ -71,6 +73,10 @@
}
+ public static Request getRequest() {
+ return (Request) currentRequest.get();
+ }
+
public static Request setRequest(Request request) {
Request old = (Request) currentRequest.get();
currentRequest.set(request);
@@ -178,6 +184,8 @@
return (true);
}
}
+
+ currentRequest.set(request);
// Which user principal have we already authenticated?
Principal principal = request.getUserPrincipal();
Added: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java?rev=374928&view=auto
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java (added)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/valve/GeronimoBeforeAfterValve.java Sat Feb 4 13:20:17 2006
@@ -0,0 +1,39 @@
+package org.apache.geronimo.tomcat.valve;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import org.apache.catalina.Valve;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.valves.ValveBase;
+import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
+
+public class GeronimoBeforeAfterValve extends ValveBase{
+
+ private final BeforeAfter beforeAfter;
+ private final int contextIndexCount;
+
+ public GeronimoBeforeAfterValve(BeforeAfter beforeAfter, int contextIndexCount) {
+ this.beforeAfter = beforeAfter;
+ this.contextIndexCount = contextIndexCount;
+ }
+
+ public void invoke(Request request, Response response) throws IOException, ServletException {
+ Object context[] = new Object[contextIndexCount];
+
+ if (beforeAfter != null){
+ beforeAfter.before(context, request, response);
+ }
+
+ // Pass this request on to the next valve in our pipeline
+ getNext().invoke(request, response);
+
+ if (beforeAfter != null){
+ beforeAfter.after(context, request, response);
+ }
+
+ }
+
+}
Modified: geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java?rev=374928&r1=374927&r2=374928&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ApplicationTest.java Sat Feb 4 13:20:17 2006
@@ -27,7 +27,7 @@
*/
public class ApplicationTest extends AbstractWebModuleTest {
- public void DavidJencksPleaseVisitMetestApplication() throws Exception {
+ public void testApplication() throws Exception {
setUpInsecureAppContext();
HttpURLConnection connection = (HttpURLConnection) new URL("http://localhost:8181/test/hello.txt")
Modified: geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java?rev=374928&r1=374927&r2=374928&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/JACCSecurityTest.java Sat Feb 4 13:20:17 2006
@@ -54,7 +54,7 @@
*
* @throws Exception thrown if an error in the test occurs
*/
- public void DavidJencksPleaseVisitMetestExplicitMapping() throws Exception {
+ public void testExplicitMapping() throws Exception {
Security securityConfig = new Security();
securityConfig.setUseContextHandler(false);
@@ -110,6 +110,7 @@
connection = (HttpURLConnection) new URL(location).openConnection();
connection.setRequestMethod("POST");
+ connection.setRequestProperty("Referer","http://localhost:8181/securetest/auth/logon.html?param=test");
connection.setRequestProperty("Cookie", cookie);
connection.setInstanceFollowRedirects(false);
assertEquals(HttpURLConnection.HTTP_MOVED_TEMP, connection.getResponseCode());