markt 2004/06/30 15:36:21 Modified: catalina/src/share/org/apache/catalina/core ApplicationContext.java catalina/src/share/org/apache/catalina/startup SecurityClassLoad.java Log: Fix bug 26174. NoClassDefFoundError when calling getNamedDispatcher with security manager - Ported Jean-Francois' patch from TC5 (but not the subsequent re-factoring) Revision Changes Path 1.44 +94 -20 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.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- ApplicationContext.java 1 Apr 2004 20:07:21 -0000 1.43 +++ ApplicationContext.java 30 Jun 2004 22:36:21 -0000 1.44 @@ -111,8 +111,48 @@ * @version $Revision$ $Date$ */ -public class ApplicationContext - implements ServletContext { +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 @@ -453,13 +493,17 @@ * * @param name Name of the initialization parameter to retrieve */ - public String getInitParameter(String name) { - + public String getInitParameter(final String name) { mergeParameters(); synchronized (parameters) { - return ((String) parameters.get(name)); + if (System.getSecurityManager() != null){ + PrivilegedGetInitParameter ip = + new PrivilegedGetInitParameter(name); + return (String)AccessController.doPrivileged(ip); + } else { + return ((String) parameters.get(name)); + } } - } @@ -468,12 +512,16 @@ * empty enumeration if the context has no initialization parameters. */ public Enumeration getInitParameterNames() { - mergeParameters(); synchronized (parameters) { - return (new Enumerator(parameters.keySet())); + if (System.getSecurityManager() != null){ + PrivilegedGetInitParameterNames pn = + new PrivilegedGetInitParameterNames(); + return (Enumeration)AccessController.doPrivileged(pn); + } else { + return (new Enumerator(parameters.keySet())); + } } - } @@ -534,10 +582,18 @@ Wrapper wrapper = (Wrapper) context.findChild(name); if (wrapper == null) return (null); - ApplicationDispatcher dispatcher = - new ApplicationDispatcher(wrapper, null, null, null, name); - return ((RequestDispatcher) dispatcher); + ApplicationDispatcher dispatcher; + if (System.getSecurityManager() != null){ + PrivilegedGetNamedDispatcher nd = + new PrivilegedGetNamedDispatcher(wrapper, name); + dispatcher = (ApplicationDispatcher)AccessController.doPrivileged(nd); + } else { + dispatcher = + new ApplicationDispatcher(wrapper, null, null, null, name); + } + + return ((RequestDispatcher) dispatcher); } @@ -775,9 +831,18 @@ * @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(){ - return (new Enumerator(empty)); - + public Object run(){ + return (new Enumerator(empty)); + } + } + ); + } else { + return (new Enumerator(empty)); + } } @@ -785,9 +850,18 @@ * @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(){ - return (new Enumerator(empty)); - + public Object run(){ + return (new Enumerator(empty)); + } + } + ); + } else { + return (new Enumerator(empty)); + } } 1.3 +13 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/SecurityClassLoad.java Index: SecurityClassLoad.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/SecurityClassLoad.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SecurityClassLoad.java 21 Sep 2003 04:31:33 -0000 1.2 +++ SecurityClassLoad.java 30 Jun 2004 22:36:21 -0000 1.3 @@ -84,6 +84,15 @@ String basePackage = "org.apache.catalina."; loader.loadClass (basePackage + + "core.ApplicationContext$PrivilegedGetNamedDispatcher"); + loader.loadClass + (basePackage + + "core.ApplicationContext$PrivilegedGetInitParameter"); + loader.loadClass + (basePackage + + "core.ApplicationContext$PrivilegedGetInitParameterNames"); + loader.loadClass + (basePackage + "core.ApplicationContext$PrivilegedGetRequestDispatcher"); loader.loadClass (basePackage +
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]