Author: markt
Date: Wed Aug 31 14:20:17 2011
New Revision: 1163633

URL: http://svn.apache.org/viewvc?rev=1163633&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51744
Don't allow user code to close the JNDI context while a web app is running

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/naming/NamingContext.java
    tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug 31 14:20:17 2011
@@ -1 +1 @@
-/tomcat/trunk:1156171,1156276,1156304,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932
+/tomcat/trunk:1156171,1156276,1156304,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630

Modified: tomcat/tc7.0.x/trunk/java/org/apache/naming/NamingContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/naming/NamingContext.java?rev=1163633&r1=1163632&r2=1163633&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/naming/NamingContext.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/naming/NamingContext.java Wed Aug 31 
14:20:17 2011
@@ -743,8 +743,8 @@ public class NamingContext implements Co
      * @exception NamingException if a naming exception is encountered
      */
     @Override
-    public void close()
-        throws NamingException {
+    public void close() throws NamingException {
+        checkWritable();
         env.clear();
     }
 

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1163633&r1=1163632&r2=1163633&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/naming/resources/TestNamingContext.java 
Wed Aug 31 14:20:17 2011
@@ -214,5 +214,61 @@ public class TestNamingContext extends T
         }
     }
     
+    @Test
+    public void testBug51744() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        tomcat.enableNaming();
+        
+        // Must have a real docBase - just use temp
+        StandardContext ctx = (StandardContext)
+            tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+        
+        // Map the test Servlet
+        Bug51744Servlet bug51744Servlet = new Bug51744Servlet();
+        Tomcat.addServlet(ctx, "bug51744Servlet", bug51744Servlet);
+        ctx.addServletMapping("/", "bug51744Servlet");
 
+        tomcat.start();
+
+        ByteChunk bc = new ByteChunk();
+        int rc = getUrl("http://localhost:"; + getPort() + "/", bc, null);
+        assertEquals(200, rc);
+        assertEquals(Bug51744Servlet.EXPECTED, bc.toString());
+    }
+
+    public static final class Bug51744Servlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        public static final String EXPECTED = "TestValue";
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+
+            resp.setContentType("text/plain;UTF-8");
+            PrintWriter out = resp.getWriter();
+
+            try {
+                Context ctx1 = new InitialContext();
+                Context env1 = (Context) ctx1.lookup("java:comp/env");
+                env1.addToEnvironment("TestName", EXPECTED);
+
+                boolean error = false;
+                try {
+                    env1.close();
+                } catch (NamingException ne) {
+                    error = true;
+                }
+                if (!error) {
+                    throw new ServletException(
+                            "No error when one was expected");
+                }
+                
+                out.print(env1.getEnvironment().get("TestName"));
+            } catch (NamingException ne) {
+                ne.printStackTrace(out);
+            }
+        }
+    }
 }

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1163633&r1=1163632&r2=1163633&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed Aug 31 14:20:17 2011
@@ -107,6 +107,10 @@
         <bug>51739</bug>: When using a landing page with FORM authentication
         ensure that the request has a valid HTTP method. (markt)
       </fix>
+      <fix>
+        <bug>51744</bug>: Prevent application code from closing the associated
+        JNDI context while the application is running. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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

Reply via email to