tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfarc...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5 CoyoteInputStream.java CoyoteResponseFacade.java
Date Tue, 04 Mar 2003 01:57:06 GMT
jfarcand    2003/03/03 17:57:06

  Modified:    jasper2/src/share/org/apache/jasper/runtime
                        PageContextImpl.java
               catalina/src/share/org/apache/catalina/core
                        ApplicationContext.java
                        ApplicationContextFacade.java
               catalina/src/share/org/apache/catalina/security
                        SecurityClassLoad.java
               coyote/src/java/org/apache/coyote/tomcat5
                        CoyoteInputStream.java CoyoteResponseFacade.java
  Log:
  Re-design the way doPrivileged block are created when the SecurityManager is on.
  
  ApplicationContext no longer have privileged block. Since this class is used via the Facade,
the doPrivileged blocks are now there. To avoid having too many inner classes, I have implemented
a cache where method objects are stored.
  
  Also add some missing doPrivileged blocks in coyote and removed unused jasper one.
  I didn't implement the cache for the coyote classes since it might affect performance.
  
  Please review. I have ran the watchdog test, jsp examples and servlet examples.
  
  Revision  Changes    Path
  1.46      +4 -16     jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/PageContextImpl.java
  
  Index: PageContextImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- PageContextImpl.java	3 Mar 2003 15:56:26 -0000	1.45
  +++ PageContextImpl.java	4 Mar 2003 01:57:05 -0000	1.46
  @@ -552,19 +552,7 @@
           if (includeUri != null)
               request.removeAttribute(Constants.INC_SERVLET_PATH);
           try {
  -            if (System.getSecurityManager() != null){
  -                AccessController.doPrivileged(new PrivilegedExceptionAction(){        
           
  -                    public Object run() throws ServletException, IOException{
  -                        context.getRequestDispatcher(path).forward(frequest, 
  -                                                                   fresponse);
  -                        return (null);
  -                    }                    
  -                });
  -            } else {
  -                context.getRequestDispatcher(path).forward(request, response);
  -            } 
  -        } catch(PrivilegedActionException e){
  -            ;                    
  +            context.getRequestDispatcher(path).forward(request, response);
           } finally {
               if (includeUri != null)
                   request.setAttribute(Constants.INC_SERVLET_PATH, includeUri);
  
  
  
  1.9       +16 -279   jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
  
  Index: ApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ApplicationContext.java	26 Feb 2003 18:37:43 -0000	1.8
  +++ ApplicationContext.java	4 Mar 2003 01:57:05 -0000	1.9
  @@ -133,175 +133,6 @@
   public class ApplicationContext
       implements ServletContext {
   
  -    protected class PrivilegedGetInitParameter
  -        implements PrivilegedAction {
  -            
  -        private String name;
  -
  -        PrivilegedGetInitParameter(String name){
  -            this.name = name;
  -        }
  -        
  -        public Object run(){
  -            return ((String) parameters.get(name));
  -        }
  -    }
  -    
  -    
  -    protected class PrivilegedGetInitParameterNames
  -        implements PrivilegedAction {
  -
  -        PrivilegedGetInitParameterNames(){
  -        }
  -
  -        public Object run() {
  -            return (new Enumerator(parameters.keySet()));
  -        }
  -    }        
  -
  -    protected class PrivilegedGetNamedDispatcher
  -        implements PrivilegedAction {
  -
  -        private Wrapper wrapper;
  -        private String name;
  -        
  -        PrivilegedGetNamedDispatcher(Wrapper wrapper, String name) {
  -            this.wrapper = wrapper;
  -            this.name = name;
  -        }
  -
  -        public Object run() {
  -            return new ApplicationDispatcher(wrapper, null, null, null, name);
  -        }
  -    }
  -    
  -    
  -    protected class PrivilegedGetRequestDispatcher
  -        implements PrivilegedAction {
  -
  -        private String contextPath;
  -        private String relativeURI;
  -        private String queryString;
  -
  -        PrivilegedGetRequestDispatcher(String contextPath, String relativeURI,
  -                                       String queryString) {
  -            this.contextPath = contextPath;
  -            this.relativeURI = relativeURI;
  -            this.queryString = queryString;
  -        }
  -
  -        public Object run() {
  -            HttpRequest request = new DummyRequest
  -                (context.getPath(), contextPath + relativeURI, queryString);
  -            Wrapper wrapper = (Wrapper) context.map(request, true);
  -            if (wrapper == null)
  -                return (null);
  -
  -            // Construct a RequestDispatcher to process this request
  -            HttpServletRequest hrequest =
  -                (HttpServletRequest) request.getRequest();
  -            return (RequestDispatcher) new ApplicationDispatcher
  -                (wrapper,
  -                 hrequest.getServletPath(),
  -                 hrequest.getPathInfo(),
  -                 hrequest.getQueryString(),
  -                 null);
  -        }
  -
  -    }
  -
  -
  -    protected class PrivilegedGetResource
  -        implements PrivilegedExceptionAction {
  -
  -        private String path;
  -        private String host;
  -        private DirContext resources;
  -
  -        PrivilegedGetResource(String host, String path, DirContext resources) {
  -            this.host = host;
  -            this.path = path;
  -            this.resources = resources;
  -        }
  -
  -        public Object run() throws Exception {
  -            return new URL("jndi", null, 0, getJNDIUri(host, path),
  -                           new DirContextURLStreamHandler(resources));
  -        }
  -    }
  -
  -
  -    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 {
  -
  -        private String message;
  -
  -        PrivilegedLogMessage(String message) {
  -            this.message = message;
  -        }
  -
  -        public Object run() {
  -            internalLog(message);
  -            return null;
  -        }
  -
  -    }
  -
  -    protected class PrivilegedLogException
  -        implements PrivilegedAction {
  -
  -        private String message;
  -        private Exception exception;
  -
  -        PrivilegedLogException(Exception exception,String message) {
  -            this.message = message;
  -            this.exception = exception;
  -        }
  -
  -        public Object run() {
  -            internalLog(exception,message);
  -            return null;
  -        }
  -
  -    }
  -
  -    protected class PrivilegedLogThrowable
  -        implements PrivilegedAction {
  -
  -        private String message;
  -        private Throwable throwable;
  -
  -        PrivilegedLogThrowable(String message,Throwable throwable) {
  -            this.message = message;
  -            this.throwable = throwable;
  -        }
  -
  -        public Object run() {
  -            internalLog(message,throwable);
  -            return null;
  -        }
  -
  -    }
  -
  -
       // ----------------------------------------------------------- Constructors
   
   
  @@ -468,14 +299,7 @@
   
           mergeParameters();
           synchronized (parameters) {
  -            if (System.getSecurityManager() != null){
  -                PrivilegedGetInitParameter ip =
  -                    new PrivilegedGetInitParameter(name);
  -                return (String)AccessController.doPrivileged(ip);
  - 
  -            } else {
  -               return ((String) parameters.get(name));
  -            }                   
  +            return ((String) parameters.get(name));
           }
       }
   
  @@ -488,13 +312,7 @@
   
           mergeParameters();
           synchronized (parameters) {
  -            if (System.getSecurityManager() != null){
  -                PrivilegedGetInitParameterNames pn =
  -                    new PrivilegedGetInitParameterNames();
  -                return (Enumeration)AccessController.doPrivileged(pn);
  -            } else {
  -               return (new Enumerator(parameters.keySet()));
  -            }
  +           return (new Enumerator(parameters.keySet()));
           }
   
       }
  @@ -559,14 +377,8 @@
               return (null);
           
           ApplicationDispatcher dispatcher;
  -        if (System.getSecurityManager() != null){
  -            PrivilegedGetNamedDispatcher nd = 
  -                    new PrivilegedGetNamedDispatcher(wrapper, name);
  -            dispatcher = (ApplicationDispatcher)AccessController.doPrivileged(nd);
  -        } else {
  -            dispatcher =
  +        dispatcher =
                 new ApplicationDispatcher(wrapper, null, null, null, name);
  -        }
           
           return ((RequestDispatcher) dispatcher);
   
  @@ -620,13 +432,6 @@
               relativeURI = path.substring(0, question);
               queryString = path.substring(question + 1);
           }
  -        if( System.getSecurityManager() != null ) {
  -            PrivilegedGetRequestDispatcher dp =
  -                new PrivilegedGetRequestDispatcher(contextPath,
  -                        relativeURI,queryString);
  -            return (RequestDispatcher)AccessController.doPrivileged(dp);
  -        }
  -
           // The remaining code is duplicated in PrivilegedGetRequestDispatcher,
           // we need to make sure they stay in sync
           HttpRequest request = new DummyRequest
  @@ -675,20 +480,9 @@
               String hostName = context.getParent().getName();
               try {
                   resources.lookup(path);
  -                if( System.getSecurityManager() != null ) {
  -                    try {
  -                        PrivilegedGetResource dp =
  -                            new PrivilegedGetResource
  -                                (hostName, fullPath, resources);
  -                        return (URL)AccessController.doPrivileged(dp);
  -                    } catch( PrivilegedActionException pe) {
  -                        throw pe.getException();
  -                    }
  -                } else {
  -                    return new URL
  -                        ("jndi", null, 0, getJNDIUri(hostName, fullPath),
  -                         new DirContextURLStreamHandler(resources));
  -                }
  +                return new URL
  +                    ("jndi", null, 0, getJNDIUri(hostName, fullPath),
  +                     new DirContextURLStreamHandler(resources));
               } catch (Exception e) {
                   //e.printStackTrace();
               }
  @@ -741,13 +535,7 @@
   
           DirContext resources = context.getResources();
           if (resources != null) {
  -            if (System.getSecurityManager() != null) {
  -                PrivilegedAction dp =
  -                    new PrivilegedGetResourcePaths(resources, path);
  -                return ((Set) AccessController.doPrivileged(dp));
  -            } else {
  -                return (getResourcePathsInternal(resources, path));
  -            }
  +            return (getResourcePathsInternal(resources, path));
           }
           return (null);
   
  @@ -808,18 +596,7 @@
        * @deprecated As of Java Servlet API 2.1, with no direct replacement.
        */
       public Enumeration getServletNames() {
  -        if (System.getSecurityManager() != null){
  -            return (Enumeration)AccessController.doPrivileged(
  -                new PrivilegedAction(){
  -                    
  -                    public Object run(){
  -                        return (new Enumerator(empty)); 
  -                    }
  -                }
  -            );
  -        } else {
  -            return (new Enumerator(empty));
  -        }
  +        return (new Enumerator(empty));
       }
   
   
  @@ -827,18 +604,7 @@
        * @deprecated As of Java Servlet API 2.1, with no direct replacement.
        */
       public Enumeration getServlets() {
  -        if (System.getSecurityManager() != null){
  -            return (Enumeration)AccessController.doPrivileged(
  -                new PrivilegedAction(){
  -                    
  -                    public Object run(){
  -                        return (new Enumerator(empty)); 
  -                    }
  -                }
  -            );
  -        } else {
  -            return (new Enumerator(empty));
  -        }        
  +        return (new Enumerator(empty));
       }
   
   
  @@ -848,16 +614,6 @@
        * @param message Message to be written
        */
       public void log(String message) {
  -        if( System.getSecurityManager() != null ) {
  -            PrivilegedLogMessage dp =
  -                new PrivilegedLogMessage(message);
  -            AccessController.doPrivileged(dp);
  -        } else {
  -            internalLog(message);
  -        }
  -    }
  -
  -    private void internalLog(String message) {
   
           Logger logger = context.getLogger();
           if (logger != null)
  @@ -876,16 +632,7 @@
        *  <code>log(String, Throwable)</code> instead
        */
       public void log(Exception exception, String message) {
  -        if( System.getSecurityManager() != null ) {
  -            PrivilegedLogException dp =
  -                new PrivilegedLogException(exception,message);
  -            AccessController.doPrivileged(dp);
  -        } else {
  -            internalLog(exception,message);
  -        }
  -    }
  -
  -    private void internalLog(Exception exception, String message) {
  +        
           Logger logger = context.getLogger();
           if (logger != null)
               logger.log(exception, message);
  @@ -900,17 +647,7 @@
        * @param throwable Exception to be reported
        */
       public void log(String message, Throwable throwable) {
  -        if( System.getSecurityManager() != null ) {
  -            PrivilegedLogThrowable dp =
  -                new PrivilegedLogThrowable(message,throwable);
  -            AccessController.doPrivileged(dp);
  -        } else {
  -            internalLog(message,throwable);
  -        }
  -    }
  -
  -    private void internalLog(String message, Throwable throwable) {
  -
  +        
           Logger logger = context.getLogger();
           if (logger != null)
               logger.log(message, throwable);
  @@ -1084,7 +821,7 @@
       /**
        * Return the facade associated with this ApplicationContext.
        */
  -    ServletContext getFacade() {
  +    protected ServletContext getFacade() {
   
           return (this.facade);
   
  
  
  
  1.2       +157 -30   jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationContextFacade.java
  
  Index: ApplicationContextFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationContextFacade.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApplicationContextFacade.java	18 Jul 2002 16:48:05 -0000	1.1
  +++ ApplicationContextFacade.java	4 Mar 2003 01:57:05 -0000	1.2
  @@ -67,6 +67,8 @@
   
   import java.io.InputStream;
   import java.io.File;
  +import java.lang.reflect.Method;
  +import java.lang.reflect.InvocationTargetException;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.security.AccessController;
  @@ -96,6 +98,7 @@
    * object from the web application.
    *
    * @author Remy Maucherat
  + * @author Jean-Francois Arcand
    * @version $Revision$ $Date$
    */
   
  @@ -103,6 +106,23 @@
       implements ServletContext {
   
   
  +    // ---------------------------------------------------------- Attributes
  +    /**
  +     * Cache Class object used for reflection.
  +     */
  +    private HashMap classCache;
  +    
  +    
  +    /**
  +     * Cache method object.
  +     */
  +    private HashMap objectCache;
  +    
  +    
  +    private static org.apache.commons.logging.Log log=
  +        org.apache.commons.logging.LogFactory.getLog( ApplicationContextFacade.class );
  +
  +        
       // ----------------------------------------------------------- Constructors
   
   
  @@ -115,6 +135,29 @@
       public ApplicationContextFacade(ApplicationContext context) {
           super();
           this.context = context;
  +        
  +        classCache = new HashMap();
  +        objectCache = new HashMap();
  +        initClassCache();
  +    }
  +    
  +    
  +    private void initClassCache(){
  +        Class[] clazz = new Class[]{String.class};
  +        classCache.put("getContext", clazz);
  +        classCache.put("getMimeType", clazz);
  +        classCache.put("getResourcePaths", clazz);
  +        classCache.put("getResource", clazz);
  +        classCache.put("getResourceAsStream", clazz);
  +        classCache.put("getRequestDispatcher", clazz);
  +        classCache.put("getNamedDispatcher", clazz);
  +        classCache.put("getServlet", clazz);
  +        classCache.put("getInitParameter", clazz);
  +        classCache.put("setAttribute", new Class[]{String.class, Object.class});
  +        classCache.put("removeAttribute", clazz);
  +        classCache.put("getRealPath", clazz);
  +        classCache.put("getAttribute", clazz);
  +        classCache.put("log", clazz);
       }
   
   
  @@ -125,16 +168,19 @@
        * Wrapped application context.
        */
       private ApplicationContext context = null;
  +    
   
   
       // ------------------------------------------------- ServletContext Methods
   
   
       public ServletContext getContext(String uripath) {
  -        ServletContext theContext = context.getContext(uripath);
  +        ServletContext theContext = (ServletContext)
  +            doPrivileged("getContext", new Object[]{uripath});
           if ((theContext != null) &&
  -            (theContext instanceof ApplicationContext))
  -            theContext = ((ApplicationContext) theContext).getFacade();
  +            (theContext instanceof ApplicationContext)){
  +            theContext = ((ApplicationContext)theContext).getFacade();
  +        }
           return (theContext);
       }
   
  @@ -150,50 +196,50 @@
   
   
       public String getMimeType(String file) {
  -        return context.getMimeType(file);
  +        return (String)doPrivileged("getMimeType", new Object[]{file});
       }
   
   
       public Set getResourcePaths(String path) {
  -        return context.getResourcePaths(path);
  +         return (Set)doPrivileged("getResourcePaths", new Object[]{path});
       }
   
   
       public URL getResource(String path)
           throws MalformedURLException {
  -        return context.getResource(path);
  +        return (URL)doPrivileged("getResource", new Object[]{path});
       }
   
   
       public InputStream getResourceAsStream(String path) {
  -        return context.getResourceAsStream(path);
  +        return (InputStream)doPrivileged("getResourceAsStream", new Object[]{path});
       }
   
   
  -    public RequestDispatcher getRequestDispatcher(String path) {
  -        return context.getRequestDispatcher(path);
  +    public RequestDispatcher getRequestDispatcher(final String path) {
  +        return (RequestDispatcher)doPrivileged("getRequestDispatcher", new Object[]{path});
       }
   
   
       public RequestDispatcher getNamedDispatcher(String name) {
  -        return context.getNamedDispatcher(name);
  +        return (RequestDispatcher)doPrivileged("getNamedDispatcher", new Object[]{name});
       }
   
   
       public Servlet getServlet(String name)
           throws ServletException {
  -        return context.getServlet(name);
  +       return (Servlet)doPrivileged("getServlet", null);
       }
   
   
       public Enumeration getServlets() {
  -        return context.getServlets();
  +        return (Enumeration)doPrivileged("getServlets", null);
       }
   
   
       public Enumeration getServletNames() {
  -        return context.getServletNames();
  -    }
  +        return (Enumeration)doPrivileged("getServletNames", null);
  +   }
   
   
       public void log(String msg) {
  @@ -202,58 +248,139 @@
   
   
       public void log(Exception exception, String msg) {
  -        context.log(exception, msg);
  +        doPrivileged("log", new Class[]{Exception.class, String.class}, new Object[]{exception,msg});
       }
   
   
       public void log(String message, Throwable throwable) {
  -        context.log(message, throwable);
  +        doPrivileged("log", new Class[]{String.class, Throwable.class}, new Object[]{message,
throwable});
       }
   
   
       public String getRealPath(String path) {
  -        return context.getRealPath(path);
  +        return (String)doPrivileged("getRealPath", new Object[]{path});
       }
   
   
       public String getServerInfo() {
  -        return context.getServerInfo();
  +        return (String)doPrivileged("getServerInfo", null);
       }
   
   
       public String getInitParameter(String name) {
  -        return context.getInitParameter(name);
  +        return (String)doPrivileged("getInitParameter", new Object[]{name});
       }
   
   
       public Enumeration getInitParameterNames() {
  -        return context.getInitParameterNames();
  +        return (Enumeration)doPrivileged("getInitParameterNames", null);
       }
   
   
       public Object getAttribute(String name) {
  -        return context.getAttribute(name);
  -    }
  +        return doPrivileged("getAttribute",new Object[]{name});
  +     }
   
   
       public Enumeration getAttributeNames() {
  -        return context.getAttributeNames();
  +        return (Enumeration)doPrivileged("getAttributeNames", null);
       }
   
   
       public void setAttribute(String name, Object object) {
  -        context.setAttribute(name, object);
  +        doPrivileged("setAttribute", new Object[]{name,object});
       }
   
   
       public void removeAttribute(String name) {
  -        context.removeAttribute(name);
  +        doPrivileged("removeAttribute", new Object[]{name});
       }
   
   
       public String getServletContextName() {
  -        return context.getServletContextName();
  +        return (String)doPrivileged("getServletContextName", null);
       }
   
  +       
  +    private Object doPrivileged(final String methodName, final Object[] params){
  +        return doPrivileged(context, methodName,params);
  +    }
   
  +    
  +    /**
  +     * Use reflection to invoke the requested method. Cache the method object 
  +     * to speed up the process
  +     * @param appContext The AppliationContext object on which the method
  +     *                   will be invoked
  +     * @param methodName The method to call.
  +     * @param params The arguments passed to the called method.
  +     */
  +    private Object doPrivileged(ApplicationContext appContext,
  +                                final String methodName, 
  +                                final Object[] params){
  +        try{
  +            Method method = (Method)objectCache.get(methodName);
  +            if (method == null){
  +                method = appContext.getClass()
  +                    .getMethod(methodName, (Class[])classCache.get(methodName));
  +                objectCache.put(methodName, method);
  +            }
  +            
  +            return executeMethod(method,appContext,params);
  +        } catch (Exception ex){
  +            if (log.isErrorEnabled()){
  +                log.error("doPrivileged", ex);
  +            }
  +            return null;
  +        }
  +    }
  +    
  +    /**
  +     * Use reflection to invoke the requested method. Cache the method object 
  +     * to speed up the process
  +     * @param appContext The AppliationContext object on which the method
  +     *                   will be invoked
  +     * @param methodName The method to call.
  +     * @param params The arguments passed to the called method.
  +     */    
  +    private Object doPrivileged(final String methodName, 
  +                                final Class[] clazz,
  +                                final Object[] params){
  +        try{
  +            Method method = context.getClass()
  +                    .getMethod(methodName, (Class[])clazz);
  +            return executeMethod(method,context,params);
  +        } catch (Exception ex){
  +            if (log.isErrorEnabled()){
  +                log.error("doPrivileged", ex);
  +            }
  +            return null;
  +        }
  +    }
  +    
  +    
  +    /**
  +     * Executes the method of the specified <code>ApplicationContext</code>
  +     * @param method The method object to be invoked.
  +     * @param context The AppliationContext object on which the method
  +     *                   will be invoked
  +     * @param params The arguments passed to the called method.
  +     */
  +    private Object executeMethod(final Method method, 
  +                                 final ApplicationContext context,
  +                                 final Object[] params) 
  +            throws PrivilegedActionException, 
  +                   IllegalAccessException,
  +                   InvocationTargetException {
  +                                     
  +        if (System.getSecurityManager() != null){
  +           return AccessController.doPrivileged(new PrivilegedExceptionAction(){
  +                public Object run() throws IllegalAccessException, InvocationTargetException{
  +                    return method.invoke(context,  params);
  +                }
  +            });
  +        } else {
  +            return method.invoke(context, params);
  +        }        
  +    }
   }
  
  
  
  1.5       +24 -36    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/security/SecurityClassLoad.java
  
  Index: SecurityClassLoad.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/security/SecurityClassLoad.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SecurityClassLoad.java	26 Feb 2003 18:38:26 -0000	1.4
  +++ SecurityClassLoad.java	4 Mar 2003 01:57:06 -0000	1.5
  @@ -97,37 +97,7 @@
           String basePackage = "org.apache.catalina.";
           loader.loadClass
               (basePackage +
  -             "core.ApplicationContext$PrivilegedGetRequestDispatcher");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedGetResource");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedGetResourcePaths");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedLogMessage");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedLogException");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedLogThrowable");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedGetNamedDispatcher");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedGetInitParameter");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$PrivilegedGetInitParameterNames");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$1");
  -        loader.loadClass
  -            (basePackage +
  -             "core.ApplicationContext$2");
  +             "core.ApplicationContextFacade$1");
           loader.loadClass
               (basePackage +
                "core.ApplicationDispatcher$PrivilegedForward");
  @@ -218,8 +188,26 @@
                "CoyoteResponseFacade$SetContentTypePrivilegedAction");
           loader.loadClass
               (basePackage +
  +             "CoyoteResponseFacade$1");
  +        loader.loadClass
  +            (basePackage +
                "OutputBuffer$1");
  -        
  +        loader.loadClass
  +            (basePackage +
  +             "CoyoteInputStream$1");
  +        loader.loadClass
  +            (basePackage +
  +             "CoyoteInputStream$2");
  +                loader.loadClass
  +            (basePackage +
  +             "CoyoteInputStream$3");
  +                loader.loadClass
  +            (basePackage +
  +             "CoyoteInputStream$4");
  +                loader.loadClass
  +            (basePackage +
  +             "CoyoteInputStream$5");
  +                
       }
   
   }
  
  
  
  1.4       +135 -12   jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteInputStream.java
  
  Index: CoyoteInputStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteInputStream.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CoyoteInputStream.java	5 Jan 2003 11:24:22 -0000	1.3
  +++ CoyoteInputStream.java	4 Mar 2003 01:57:06 -0000	1.4
  @@ -61,7 +61,10 @@
   package org.apache.coyote.tomcat5;
   
   import java.io.IOException;
  -
  +import java.security.AccessController;
  +import java.security.PrivilegedAction;
  +import java.security.PrivilegedExceptionAction;
  +import java.security.PrivilegedActionException;
   import javax.servlet.ServletInputStream;
   
   
  @@ -69,6 +72,7 @@
    * This class handles reading bytes.
    * 
    * @author Remy Maucherat
  + * @author Jean-Francois Arcand
    */
   public class CoyoteInputStream
       extends ServletInputStream {
  @@ -92,22 +96,120 @@
   
   
       public int read()
  -        throws IOException {
  -        return ib.read();
  +        throws IOException {    
  +        if (System.getSecurityManager() != null){
  +            
  +            try{
  +                Integer result = 
  +                    (Integer)AccessController.doPrivileged(
  +                        new PrivilegedExceptionAction(){
  +
  +                            public Object run() throws IOException{
  +                                Integer integer = new Integer(ib.read());
  +                                return integer;
  +                            }
  +
  +                });
  +                return result.intValue();
  +            } catch(PrivilegedActionException pae){
  +                Exception e = pae.getException();
  +                if (e instanceof IOException){
  +                    throw (IOException)e;
  +                } else {
  +                    throw new RuntimeException(e.getMessage());
  +                }
  +            }
  +        } else {
  +            return ib.read();
  +        }
       }
   
       public int available() throws IOException {
  -        return ib.available();
  +        
  +        if (System.getSecurityManager() != null){
  +            try{
  +                Integer result = 
  +                    (Integer)AccessController.doPrivileged(
  +                        new PrivilegedExceptionAction(){
  +
  +                            public Object run() throws IOException{
  +                                Integer integer = new Integer(ib.available());
  +                                return integer;
  +                            }
  +
  +                });
  +                return result.intValue();
  +            } catch(PrivilegedActionException pae){
  +                Exception e = pae.getException();
  +                if (e instanceof IOException){
  +                    throw (IOException)e;
  +                } else {
  +                    throw new RuntimeException(e.getMessage());
  +                }
  +            }
  +        } else {
  +           return ib.available();
  +        }    
  +    }
  +
  +    public int read(final byte[] b) throws IOException {
  +        
  +        if (System.getSecurityManager() != null){
  +            try{
  +                Integer result = 
  +                    (Integer)AccessController.doPrivileged(
  +                        new PrivilegedExceptionAction(){
  +
  +                            public Object run() throws IOException{
  +                                Integer integer = 
  +                                    new Integer(ib.read(b, 0, b.length));
  +                                return integer;
  +                            }
  +
  +                });
  +                return result.intValue();
  +            } catch(PrivilegedActionException pae){
  +                Exception e = pae.getException();
  +                if (e instanceof IOException){
  +                    throw (IOException)e;
  +                } else {
  +                    throw new RuntimeException(e.getMessage());
  +                }
  +            }
  +        } else {
  +            return ib.read(b, 0, b.length);
  +         }        
       }
   
  -    public int read(byte[] b) throws IOException {
  -        return ib.read(b, 0, b.length);
  -    }
   
  -
  -    public int read(byte[] b, int off, int len)
  +    public int read(final byte[] b, final int off, final int len)
           throws IOException {
  -        return ib.read(b, off, len);
  +            
  +        if (System.getSecurityManager() != null){
  +            try{
  +                Integer result = 
  +                    (Integer)AccessController.doPrivileged(
  +                        new PrivilegedExceptionAction(){
  +
  +                            public Object run() throws IOException{
  +                                Integer integer = 
  +                                    new Integer(ib.read(b, off, len));
  +                                return integer;
  +                            }
  +
  +                });
  +                return result.intValue();
  +            } catch(PrivilegedActionException pae){
  +                Exception e = pae.getException();
  +                if (e instanceof IOException){
  +                    throw (IOException)e;
  +                } else {
  +                    throw new RuntimeException(e.getMessage());
  +                }
  +            }
  +        } else {
  +            return ib.read(b, off, len);
  +        }            
       }
   
   
  @@ -122,8 +224,29 @@
        * which would permantely disable us.
        */
       public void close() throws IOException {
  -        ib.close();
  +        
  +        if (System.getSecurityManager() != null){
  +            try{
  +                AccessController.doPrivileged(
  +                    new PrivilegedExceptionAction(){
  +
  +                        public Object run() throws IOException{
  +                            ib.close();
  +                            return null;
  +                        }
  +
  +                });
  +            } catch(PrivilegedActionException pae){
  +                Exception e = pae.getException();
  +                if (e instanceof IOException){
  +                    throw (IOException)e;
  +                } else {
  +                    throw new RuntimeException(e.getMessage());
  +                }
  +            }
  +        } else {
  +             ib.close();
  +        }            
       }
  -
   
   }
  
  
  
  1.3       +27 -6     jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteResponseFacade.java
  
  Index: CoyoteResponseFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteResponseFacade.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CoyoteResponseFacade.java	4 Nov 2002 05:14:09 -0000	1.2
  +++ CoyoteResponseFacade.java	4 Mar 2003 01:57:06 -0000	1.3
  @@ -69,6 +69,8 @@
   import java.io.PrintWriter;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
  +import java.security.PrivilegedExceptionAction;
  +import java.security.PrivilegedActionException;
   import java.util.Locale;
   import javax.servlet.ServletException;
   import javax.servlet.ServletOutputStream;
  @@ -242,9 +244,28 @@
               //                (/*sm.getString("responseFacade.finished")*/);
               return;
   
  -        response.setAppCommitted(true);
  +        if (System.getSecurityManager() != null){
  +            try{
  +                AccessController.doPrivileged(new PrivilegedExceptionAction(){
  +
  +                    public Object run() throws IOException{
  +                        response.setAppCommitted(true);
   
  -        response.flushBuffer();
  +                        response.flushBuffer();
  +                        return null;
  +                    }
  +                });
  +            } catch(PrivilegedActionException e){
  +                Exception ex = e.getException();
  +                if (ex instanceof IOException){
  +                    throw (IOException)ex;
  +                }
  +            }
  +        } else {
  +            response.setAppCommitted(true);
  +
  +            response.flushBuffer();            
  +        }
   
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message