You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@apache.org on 2001/05/12 05:04:12 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup Bootstrap.java

craigmcc    01/05/11 20:04:12

  Modified:    catalina/src/share/org/apache/catalina/core
                        ApplicationContext.java
               catalina/src/share/org/apache/catalina/startup
                        Bootstrap.java
  Log:
  Make ServletContext.getResourcePaths() work under a security manager.
  
  Revision  Changes    Path
  1.24      +45 -35    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
  
  Index: ApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ApplicationContext.java	2001/04/26 17:23:35	1.23
  +++ ApplicationContext.java	2001/05/12 03:04:08	1.24
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.23 2001/04/26 17:23:35 craigmcc Exp $
  - * $Revision: 1.23 $
  - * $Date: 2001/04/26 17:23:35 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.24 2001/05/12 03:04:08 craigmcc Exp $
  + * $Revision: 1.24 $
  + * $Date: 2001/05/12 03:04:08 $
    *
    * ====================================================================
    *
  @@ -75,6 +75,7 @@
   import java.security.PrivilegedActionException;
   import java.util.ArrayList;
   import java.util.Arrays;
  +import java.util.Collections;
   import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.HashSet;
  @@ -111,10 +112,10 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.23 $ $Date: 2001/04/26 17:23:35 $
  + * @version $Revision: 1.24 $ $Date: 2001/05/12 03:04:08 $
    */
   
  -public final class ApplicationContext
  +public class ApplicationContext
       implements ServletContext {
   
   
  @@ -176,6 +177,25 @@
           
       }
   
  +
  +    protected class PrivilegedGetResourcePaths
  +        implements PrivilegedAction {
  +
  +        private String path;
  +        private DirContext resources;
  +
  +        PrivilegedGetResourcePaths(DirContext resources, String path) {
  +            this.resources = resources;
  +            this.path = path;
  +        }
  +
  +        public Object run() {
  +            return (getResourcePathsInternal(resources, path));
  +        }
  +
  +    }
  +
  +
       protected class PrivilegedLogMessage
           implements PrivilegedAction {
                                                 
  @@ -625,53 +645,43 @@
   
   
       /**
  -     * Return a Set containing the resource paths of all resources defined
  -     * within this web application.  Each path will be a String starting with
  -     * a "/" character.  The returned set is immutable.
  +     * Return a Set containing the resource paths of resources member of the
  +     * specified collection. Each path will be a String starting with
  +     * a "/" character. The returned set is immutable.
  +     * 
  +     * @param path Collection path
        */
  -    public Set getResourcePaths() {
  +    public Set getResourcePaths(String path) {
   
  -        ResourceSet set = new ResourceSet();
           DirContext resources = context.getResources();
  -        if (resources == null) {
  -            set.setLocked(true);
  -            return (set);
  -        }
  -        
  -        try {
  -            listPaths(set, resources, "");
  -        } catch (NamingException e) {
  -            // Ignore
  +        if (resources != null) {
  +            if (System.getSecurityManager() != null) {
  +                PrivilegedAction dp =
  +                    new PrivilegedGetResourcePaths(resources, path);
  +                return ((Set) AccessController.doPrivileged(dp));
  +            } else {
  +                return (getResourcePathsInternal(resources, path));
  +            }
           }
  -        
  -        set.setLocked(true);
  -        return (set);
  +        return (null);
   
       }
   
   
       /**
  -     * Return a Set containing the resource paths of resources member of the
  -     * specified collection. Each path will be a String starting with
  -     * a "/" character. The returned set is immutable.
  -     * 
  +     * Internal implementation of getResourcesPath() logic.
  +     *
  +     * @param resources Directory context to search
        * @param path Collection path
        */
  -    public Set getResourcePaths(String path) {
  +    private Set getResourcePathsInternal(DirContext resources, String path) {
   
           ResourceSet set = new ResourceSet();
  -        DirContext resources = context.getResources();
  -        if (resources == null) {
  -            set.setLocked(true);
  -            return (set);
  -        }
  -        
           try {
               listCollectionPaths(set, resources, path);
           } catch (NamingException e) {
  -            // Ignore
  +            ; // Ignore
           }
  -        
           set.setLocked(true);
           return (set);
   
  
  
  
  1.18      +10 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Bootstrap.java
  
  Index: Bootstrap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Bootstrap.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Bootstrap.java	2001/04/26 12:31:07	1.17
  +++ Bootstrap.java	2001/05/12 03:04:10	1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Bootstrap.java,v 1.17 2001/04/26 12:31:07 glenn Exp $
  - * $Revision: 1.17 $
  - * $Date: 2001/04/26 12:31:07 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Bootstrap.java,v 1.18 2001/05/12 03:04:10 craigmcc Exp $
  + * $Revision: 1.18 $
  + * $Date: 2001/05/12 03:04:10 $
    *
    * ====================================================================
    *
  @@ -85,7 +85,7 @@
    * class path and therefore not visible to application level classes.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.17 $ $Date: 2001/04/26 12:31:07 $
  + * @version $Revision: 1.18 $ $Date: 2001/05/12 03:04:10 $
    */
   
   public final class Bootstrap {
  @@ -134,6 +134,12 @@
                   catalinaLoader.loadClass
                       (basePackage +
                        "core.ApplicationContext$PrivilegedGetRequestDispatcher");
  +                catalinaLoader.loadClass
  +                    (basePackage +
  +                     "core.ApplicationContext$PrivilegedGetResource");
  +                catalinaLoader.loadClass
  +                    (basePackage +
  +                     "core.ApplicationContext$PrivilegedGetResourcePaths");
                   catalinaLoader.loadClass
                       (basePackage +      
                        "core.ApplicationContext$PrivilegedLogMessage");