geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r376068 - in /geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat: interceptor/PolicyContextBeforeAfter.java listener/DispatchListener.java realm/TomcatGeronimoRealm.java
Date Wed, 08 Feb 2006 21:21:33 GMT
Author: jgenender
Date: Wed Feb  8 13:21:26 2006
New Revision: 376068

URL: http://svn.apache.org/viewcvs?rev=376068&view=rev
Log:
GERONIMO-1480 - set and get servlet wrapper name during dispatch

Modified:
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java?rev=376068&r1=376067&r2=376068&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/interceptor/PolicyContextBeforeAfter.java
Wed Feb  8 13:21:26 2006
@@ -16,14 +16,10 @@
  */
 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;
@@ -39,13 +35,7 @@
     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;
+        context[policyContextIDIndex] = PolicyContext.getContextID();
         
         //Set the new
         PolicyContext.setContextID(policyContextID);
@@ -62,28 +52,7 @@
         }
         
         //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;
-        }
+        PolicyContext.setContextID((String)context[policyContextIDIndex]);
     }
 
 }

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java?rev=376068&r1=376067&r2=376068&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/listener/DispatchListener.java
Wed Feb  8 13:21:26 2006
@@ -22,14 +22,20 @@
 import javax.servlet.ServletResponse;
 
 import org.apache.catalina.Container;
+import org.apache.catalina.Globals;
 import org.apache.catalina.InstanceEvent;
 import org.apache.catalina.InstanceListener;
+import org.apache.catalina.core.StandardWrapper;
 import org.apache.geronimo.tomcat.GeronimoStandardContext;
 import org.apache.geronimo.tomcat.interceptor.BeforeAfter;
+import org.apache.geronimo.tomcat.realm.TomcatGeronimoRealm;
+import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.http.mapper.Mapper;
+import org.apache.tomcat.util.http.mapper.MappingData;
 
 public class DispatchListener implements InstanceListener {
 
-    //private static StackThreadLocal currentContext = new ThreadLocal();
+    // private static StackThreadLocal currentContext = new ThreadLocal();
     private static ThreadLocal currentContext = new ThreadLocal() {
         protected Object initialValue() {
             return new Stack();
@@ -58,10 +64,14 @@
 
     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()];
+            Object context[] = new Object[webContext.getContextCount() + 1];
+            String wrapperName = getWrapperName(request, webContext);
+            context[webContext.getContextCount()] = TomcatGeronimoRealm
+                    .setRequestWrapperName(wrapperName);
             beforeAfter.before(context, request, response);
             stack.push(context);
         }
@@ -74,7 +84,33 @@
             Stack stack = (Stack) currentContext.get();
             Object context[] = (Object[]) stack.pop();
             beforeAfter.after(context, request, response);
+            TomcatGeronimoRealm
+                    .setRequestWrapperName((String) context[webContext
+                            .getContextCount()]);
         }
     }
 
+    private String getWrapperName(ServletRequest request,
+            GeronimoStandardContext webContext) {
+        
+        MappingData mappingData = new MappingData();
+        Mapper mapper = webContext.getMapper();
+        MessageBytes mb = MessageBytes.newInstance();
+        
+        String dispatchPath = null;
+        dispatchPath = 
+            (String) request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR);
+        mb.setString(dispatchPath);
+        
+        try {
+            mapper.map(mb, mappingData);
+            StandardWrapper wrapper = (StandardWrapper) mappingData.wrapper;
+            return wrapper.getName();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+        return null;
+    }
 }

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java?rev=376068&r1=376067&r2=376068&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
(original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/realm/TomcatGeronimoRealm.java
Wed Feb  8 13:21:26 2006
@@ -57,7 +57,7 @@
 
     private static final Log log = LogFactory.getLog(TomcatGeronimoRealm.class);
 
-    private static ThreadLocal currentRequest = new ThreadLocal();
+    private static ThreadLocal currentRequestWrapperName = new ThreadLocal();
 
     /**
      * Descriptive information about this <code>Realm</code> implementation.
@@ -72,14 +72,10 @@
     public TomcatGeronimoRealm() {
 
      }
-
-    public static Request getRequest() {
-        return (Request) currentRequest.get();
-    }
     
-    public static Request setRequest(Request request) {
-        Request old = (Request) currentRequest.get();
-        currentRequest.set(request);
+    public static String setRequestWrapperName(String requestWrapperName) {
+        String old = (String) currentRequestWrapperName.get();
+        currentRequestWrapperName.set(requestWrapperName);
         return old;
     }
 
@@ -185,7 +181,9 @@
             }
         }
         
-        currentRequest.set(request);
+        Wrapper servletWrapper = request.getWrapper();
+        String name = servletWrapper.getName();
+        currentRequestWrapperName.set(name);
 
         // Which user principal have we already authenticated?
         Principal principal = request.getUserPrincipal();
@@ -231,11 +229,7 @@
             return false;
         }
 
-        Request request = (Request) currentRequest.get();
-        assert request != null;
-
-        Wrapper servletWrapper = request.getWrapper();
-        String name = servletWrapper.getName();
+        String name = (String)currentRequestWrapperName.get();
 
         /**
          * JACC v1.0 secion B.19



Mime
View raw message