geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r474478 - in /geronimo/sandbox/javaee5/modules-jee5: geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/ geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/
Date Mon, 13 Nov 2006 20:08:04 GMT
Author: djencks
Date: Mon Nov 13 12:08:03 2006
New Revision: 474478

URL: http://svn.apache.org/viewvc?view=rev&rev=474478
Log:
Fix problems with context root handling, filter holder start order, and JAASRealm

Modified:
    geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
    geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJAASJettyRealm.java
    geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
    geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyPOJOWebServiceHolder.java
    geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java
    geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java

Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java?view=diff&rev=474478&r1=474477&r2=474478
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6-builder/src/main/java/org/apache/geronimo/jetty6/deployment/JettyModuleBuilder.java
Mon Nov 13 12:08:03 2006
@@ -373,7 +373,14 @@
             //TODO fix this for javaee 5 !!!
             resourceEnvironmentSetter.setResourceEnvironment(rebuilder, webApp.getResourceRefArray(),
jettyWebApp.getResourceRefArray());
 
-            webModuleData.setAttribute("contextPath", webModule.getContextRoot());
+            String contextPath = webModule.getContextRoot();
+            if (contextPath == null) {
+                throw new DeploymentException("null contextPath");
+            }
+            if (!contextPath.startsWith("/")) {
+                contextPath = "/" + contextPath;
+            }
+            webModuleData.setAttribute("contextPath", contextPath);
 
             webModuleData.setReferencePattern("TransactionManager", moduleContext.getTransactionManagerName());
             webModuleData.setReferencePattern("TrackedConnectionAssociator", moduleContext.getConnectionTrackerName());
@@ -604,6 +611,7 @@
                     String servletName = filterMappingType.getServletNameArray(j).getStringValue().trim();
                     AbstractName abstractServletName = earContext.getNaming().createChildName(moduleName,
servletName, NameFactory.SERVLET);
                     servletNameSet.add(abstractServletName);
+                    filterMappingData.addDependency(abstractServletName);
                 }
 
                 filterMappingData.setReferencePatterns("Servlets", servletNameSet);

Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJAASJettyRealm.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJAASJettyRealm.java?view=diff&rev=474478&r1=474477&r2=474478
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJAASJettyRealm.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJAASJettyRealm.java
Mon Nov 13 12:08:03 2006
@@ -43,7 +43,7 @@
     private static Log log = LogFactory.getLog(InternalJAASJettyRealm.class);
 
     private final String securityRealmName;
-    private final HashMap userMap = new HashMap();
+    private final HashMap<String, Principal> userMap = new HashMap<String, Principal>();
     private int count = 1;
 
     public InternalJAASJettyRealm(String geronimoRealmName) {
@@ -55,7 +55,7 @@
     }
 
     public Principal getPrincipal(String username) {
-        return (Principal) userMap.get(username);
+        return userMap.get(username);
     }
 
     public Principal authenticate(String username, Object credentials, Request request) {
@@ -145,7 +145,7 @@
         AccessControlContext acc = ContextManager.getCurrentContext();
         try {
             // JACC v1.0 secion B.19
-            String servletName = JettyServletHolder.getCurrentServletName();
+            String servletName = InternalJettyServletHolder.getCurrentServletName();
             if (servletName.equals("jsp")) {
                 servletName = "";
             }

Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java?view=diff&rev=474478&r1=474477&r2=474478
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/InternalJettyServletHolder.java
Mon Nov 13 12:08:03 2006
@@ -20,19 +20,73 @@
 
 package org.apache.geronimo.jetty6;
 
+import java.io.IOException;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+import javax.security.auth.Subject;
+
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.apache.geronimo.jetty6.handler.AbstractImmutableHandler;
 import org.apache.geronimo.jetty6.handler.LifecycleCommand;
+import org.apache.geronimo.security.Callers;
+import org.apache.geronimo.security.ContextManager;
 
 /**
- * @version $Rev:$ $Date:$
+ * @version $Rev$ $Date$
  */
 public class InternalJettyServletHolder extends ServletHolder {
 
+    private static final ThreadLocal<String> currentServletName = new ThreadLocal<String>();
+
     private final AbstractImmutableHandler lifecycleChain;
+    private final Subject runAsSubject;
 
-    public InternalJettyServletHolder(AbstractImmutableHandler lifecycleChain) {
+    public InternalJettyServletHolder(AbstractImmutableHandler lifecycleChain, Subject runAsSubject)
{
         this.lifecycleChain = lifecycleChain;
+        this.runAsSubject = runAsSubject;
+    }
+
+    //TODO probably need to override init and destroy (?) to handle runAsSubject since we
are not setting it in the superclass any more.
+
+    /**
+     * Service a request with this servlet.  Set the ThreadLocal to hold the
+     * current JettyServletHolder.
+     */
+    public void handle(ServletRequest request, ServletResponse response)
+            throws ServletException, UnavailableException, IOException {
+        String oldServletName = getCurrentServletName();
+        setCurrentServletName(getName());
+        try {
+            if (runAsSubject == null) {
+                super.handle(request, response);
+            } else {
+                Callers oldCallers = ContextManager.pushNextCaller(runAsSubject);
+                try {
+                    super.handle(request, response);
+                } finally {
+                    ContextManager.popCallers(oldCallers);
+                }
+            }
+        } finally {
+            setCurrentServletName(oldServletName);
+        }
+    }
+
+    /**
+     * Provide the thread's current JettyServletHolder
+     *
+     * @return the thread's current JettyServletHolder
+     * @see org.apache.geronimo.jetty6.JAASJettyRealm#isUserInRole(java.security.Principal,
java.lang.String)
+     */
+    static String getCurrentServletName() {
+        return currentServletName.get();
+    }
+
+    static void setCurrentServletName(String servletName) {
+        currentServletName.set(servletName);
     }
 
     public void doStart() throws Exception {

Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyPOJOWebServiceHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyPOJOWebServiceHolder.java?view=diff&rev=474478&r1=474477&r2=474478
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyPOJOWebServiceHolder.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyPOJOWebServiceHolder.java
Mon Nov 13 12:08:03 2006
@@ -94,6 +94,7 @@
     }
 
     /**
+     * TODO THIS IS NOT CALLED!!! only the ServletHolder is!!
      * Service a request with this servlet.  Set the ThreadLocal to hold the
      * current JettyServletHolder.
      */
@@ -103,7 +104,7 @@
         //  TODO There has to be some way to get this in on the Servlet's init method.
 //        request.setAttribute(POJOWebServiceServlet.WEBSERVICE_CONTAINER, webServiceContainer);
 
-        JettyServletHolder.setCurrentServletName(getServletName());
+        InternalJettyServletHolder.setCurrentServletName(getServletName());
         PolicyContext.setHandlerData(Request.getRequest((HttpServletRequest) request));
 
         servletHolder.handle(request, response);

Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java?view=diff&rev=474478&r1=474477&r2=474478
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyServletHolder.java
Mon Nov 13 12:08:03 2006
@@ -16,23 +16,16 @@
  */
 package org.apache.geronimo.jetty6;
 
-import java.io.IOException;
 import java.util.Map;
 import java.util.Set;
 
 import javax.security.auth.Subject;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.UnavailableException;
 
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.management.Servlet;
-import org.apache.geronimo.security.Callers;
-import org.apache.geronimo.security.ContextManager;
 import org.mortbay.jetty.servlet.ServletHolder;
 
 
@@ -48,11 +41,9 @@
  */
 public class JettyServletHolder implements Servlet, GBeanLifecycle {
 
-    private static final ThreadLocal currentServletName = new ThreadLocal();
 
     private final JettyServletRegistration servletRegistration;
     private final ServletHolder servletHolder;
-    private final Subject runAsSubject;
     private final String objectName;
 
     //todo consider interface instead of this constructor for endpoint use.
@@ -60,7 +51,6 @@
         servletRegistration = null;
         servletHolder = null;
         objectName = null;
-        runAsSubject = null;
     }
 
     public JettyServletHolder(String objectName,
@@ -73,7 +63,7 @@
             Subject runAsSubject,
             JettyServletRegistration context) throws Exception {
         servletRegistration = context;
-        servletHolder = new InternalJettyServletHolder(context == null? null: context.getLifecycleChain());
+        servletHolder = new InternalJettyServletHolder(context == null? null: context.getLifecycleChain(),
runAsSubject);
         servletHolder.setName(servletName);
         servletHolder.setClassName(servletClassName);
         //context will be null only for use as "default servlet info holder" in deployer.
@@ -88,48 +78,11 @@
             //this now starts the servlet in the appropriate context
             context.registerServletHolder(servletHolder, servletName, servletMappings, objectName);
         }
-        this.runAsSubject = runAsSubject;
         this.objectName = objectName;
     }
 
     public String getServletName() {
         return servletHolder.getName();
-    }
-
-    //TODO probably need to override init and destroy (?) to handle runAsSubject since we
are not setting it in the superclass any more.
-
-    /**
-     * Service a request with this servlet.  Set the ThreadLocal to hold the
-     * current JettyServletHolder.
-     */
-    public void handle(ServletRequest request, ServletResponse response)
-            throws ServletException, UnavailableException, IOException {
-
-        setCurrentServletName(getServletName());
-        if (runAsSubject == null) {
-            servletHolder.handle(request, response);
-        } else {
-            Callers oldCallers = ContextManager.pushNextCaller(runAsSubject);
-            try {
-                servletHolder.handle(request, response);
-            } finally {
-                ContextManager.popCallers(oldCallers);
-            }
-        }
-    }
-
-    /**
-     * Provide the thread's current JettyServletHolder
-     *
-     * @return the thread's current JettyServletHolder
-     * @see org.apache.geronimo.jetty6.JAASJettyRealm#isUserInRole(java.security.Principal,
java.lang.String)
-     */
-    static String getCurrentServletName() {
-        return (String) currentServletName.get();
-    }
-
-    static void setCurrentServletName(String servletName) {
-        currentServletName.set(servletName);
     }
 
     public String getObjectName() {

Modified: geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java?view=diff&rev=474478&r1=474477&r2=474478
==============================================================================
--- geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
(original)
+++ geronimo/sandbox/javaee5/modules-jee5/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyWebAppContext.java
Mon Nov 13 12:08:03 2006
@@ -66,6 +66,7 @@
 import org.mortbay.jetty.servlet.ServletMapping;
 import org.mortbay.jetty.servlet.SessionHandler;
 import org.mortbay.jetty.webapp.WebAppContext;
+import org.mortbay.jetty.MimeTypes;
 
 /**
  * Wrapper for a WebApplicationContext that sets up its J2EE environment.
@@ -166,11 +167,11 @@
 
             securityHandler.init(policyContextID, defaultPrincipal, checkedPermissions, excludedPermissions,
classLoader);
         }
-        
+
         PreHandler preHandler = null == preHandlerFactory ? null : preHandlerFactory.createHandler();
         ServletHandler servletHandler = new JettyServletHandler(preHandler);
-        
-        this.webAppContext = new WebAppContext(securityHandler, sessionHandler, servletHandler,
null);
+
+        webAppContext = new WebAppContext(securityHandler, sessionHandler, servletHandler,
null);
         AbstractHandler next = sessionHandler;
         next = new ThreadClassloaderHandler(next, classLoader);
 
@@ -181,6 +182,10 @@
         lifecycleChain = (AbstractImmutableHandler) next;
         webAppContext.setHandler(next);
 
+        MimeTypes mimeTypes = new MimeTypes();
+        mimeTypes.setMimeMap(mimeMap);
+        webAppContext.setMimeTypes(mimeTypes);
+        
         this.server = server;
         this.application = application;
         this.objectName = objectName;
@@ -273,8 +278,14 @@
         if (urlPrefix == null) {
             return null;
         }
+        StringBuffer buf = new StringBuffer(urlPrefix);
+        String contextPath = getContextPath();
+        if (!contextPath.startsWith("/")) {
+            buf.append("/");
+        }
+        buf.append(contextPath);
         try {
-            return new URL(urlPrefix + getContextPath());
+            return new URL(buf.toString());
         } catch (MalformedURLException e) {
             log.error("Bad URL to connect to web app", e);
             return null;
@@ -282,6 +293,9 @@
     }
 
     public void setContextPath(String path) {
+        if (path == null || !path.startsWith("/")) {
+            throw new IllegalArgumentException("context path must be non-null and start with
'/', not " + path);
+        }
         this.webAppContext.setContextPath(path);
     }
 
@@ -491,9 +505,9 @@
     }
 
     public static final GBeanInfo GBEAN_INFO;
-    
+
     public static final String GBEAN_ATTR_SESSION_TIMEOUT = "sessionTimeoutSeconds";
-    
+
     public static final String GBEAN_REF_SESSION_HANDLER_FACTORY = "SessionHandlerFactory";
     public static final String GBEAN_REF_PRE_HANDLER_FACTORY = "PreHandlerFactory";
 



Mime
View raw message