Author: markt
Date: Wed Aug 31 14:17:41 2011
New Revision: 1163630
URL: http://svn.apache.org/viewvc?rev=1163630&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/trunk/java/org/apache/naming/NamingContext.java
tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java
Modified: tomcat/trunk/java/org/apache/naming/NamingContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/NamingContext.java?rev=1163630&r1=1163629&r2=1163630&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/NamingContext.java (original)
+++ tomcat/trunk/java/org/apache/naming/NamingContext.java Wed Aug 31 14:17:41
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/trunk/test/org/apache/naming/resources/TestNamingContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java?rev=1163630&r1=1163629&r2=1163630&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java
(original)
+++ tomcat/trunk/test/org/apache/naming/resources/TestNamingContext.java Wed
Aug 31 14:17:41 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);
+ }
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]