Author: markt
Date: Mon Jan  7 19:10:28 2013
New Revision: 1429970

URL: http://svn.apache.org/viewvc?rev=1429970&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54284
As per clarification from the Servlet EG, anonymous Filters and Servlets are 
not permitted.
Patch by Violeta Georgieva.

Added:
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestFilterDef.java
      - copied unchanged from r1429969, 
tomcat/trunk/test/org/apache/catalina/deploy/TestFilterDef.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/deploy/TestServletDef.java
      - copied unchanged from r1429969, 
tomcat/trunk/test/org/apache/catalina/deploy/TestServletDef.java
Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/FilterDef.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/ServletDef.java
    
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1429969

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1429970&r1=1429969&r2=1429970&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java 
Mon Jan  7 19:10:28 2013
@@ -944,6 +944,11 @@ public class ApplicationContext
     private FilterRegistration.Dynamic addFilter(String filterName,
             String filterClass, Filter filter) throws IllegalStateException {
         
+        if (filterName == null || filterName.equals("")) {
+            throw new IllegalArgumentException(sm.getString(
+                    "applicationContext.invalidFilterName", filterName));
+        }
+
         if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
             //TODO Spec breaking enhancement to ignore this restriction
             throw new IllegalStateException(
@@ -1084,6 +1089,11 @@ public class ApplicationContext
     private ServletRegistration.Dynamic addServlet(String servletName,
             String servletClass, Servlet servlet) throws IllegalStateException 
{
         
+        if (servletName == null || servletName.equals("")) {
+            throw new IllegalArgumentException(sm.getString(
+                    "applicationContext.invalidServletName", servletName));
+        }
+
         if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
             //TODO Spec breaking enhancement to ignore this restriction
             throw new IllegalStateException(

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1429970&r1=1429969&r2=1429970&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties 
Mon Jan  7 19:10:28 2013
@@ -21,6 +21,8 @@ applicationContext.addListener.ise=Liste
 applicationContext.addRole.ise=Roles can not be added to context {0} as the 
context has been initialised
 applicationContext.addServlet.ise=Servlets can not be added to context {0} as 
the context has been initialised
 applicationContext.attributeEvent=Exception thrown by attributes event listener
+applicationContext.invalidFilterName=Unable to add filter definition due to 
invalid filter name [{0}].
+applicationContext.invalidServletName=Unable to add servlet definition due to 
invalid servlet name [{0}].
 applicationContext.mapping.error=Error during mapping
 applicationContext.requestDispatcher.iae=Path {0} does not start with a "/" 
character
 applicationContext.resourcePaths.iae=Path {0} does not start with a "/" 
character

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/FilterDef.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/FilterDef.java?rev=1429970&r1=1429969&r2=1429970&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/FilterDef.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/FilterDef.java Mon Jan 
 7 19:10:28 2013
@@ -25,6 +25,8 @@ import java.util.Map;
 
 import javax.servlet.Filter;
 
+import org.apache.tomcat.util.res.StringManager;
+
 
 /**
  * Representation of a filter definition for a web application, as represented
@@ -38,6 +40,9 @@ public class FilterDef implements Serial
 
     private static final long serialVersionUID = 1L;
 
+    private static final StringManager sm =
+        StringManager.getManager(Constants.Package);
+
     // ------------------------------------------------------------- Properties
 
 
@@ -108,6 +113,10 @@ public class FilterDef implements Serial
     }
 
     public void setFilterName(String filterName) {
+        if (filterName == null || filterName.equals("")) {
+            throw new IllegalArgumentException(
+                    sm.getString("filterDef.invalidFilterName", filterName));
+        }
         this.filterName = filterName;
     }
 

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties?rev=1429970&r1=1429969&r2=1429970&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/LocalStrings.properties 
Mon Jan  7 19:10:28 2013
@@ -12,6 +12,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+filterDef.invalidFilterName=Invalid <filter-name> [{0}] in filter definition.
+
+servletDef.invalidServletName=Invalid <servlet-name> [{0}] in servlet 
definition.
 
 webXml.duplicateEnvEntry=Duplicate env-entry name [{0}]
 webXml.duplicateFilter=Duplicate filter name [{0}]

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/ServletDef.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/ServletDef.java?rev=1429970&r1=1429969&r2=1429970&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/ServletDef.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/deploy/ServletDef.java Mon 
Jan  7 19:10:28 2013
@@ -25,6 +25,8 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.tomcat.util.res.StringManager;
+
 
 /**
  * Representation of a servlet definition for a web application, as represented
@@ -35,6 +37,9 @@ public class ServletDef implements Seria
 
     private static final long serialVersionUID = 1L;
 
+    private static final StringManager sm =
+        StringManager.getManager(Constants.Package);
+
     // ------------------------------------------------------------- Properties
 
 
@@ -104,6 +109,10 @@ public class ServletDef implements Seria
     }
 
     public void setServletName(String servletName) {
+        if (servletName == null || servletName.equals("")) {
+            throw new IllegalArgumentException(
+                    sm.getString("servletDef.invalidServletName", 
servletName));
+        }
         this.servletName = servletName;
     }
 

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java?rev=1429970&r1=1429969&r2=1429970&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestApplicationContext.java 
Mon Jan  7 19:10:28 2013
@@ -18,6 +18,9 @@ package org.apache.catalina.core;
 
 import java.io.File;
 
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletResponse;
 
 import org.junit.Assert;
@@ -69,4 +72,40 @@ public class TestApplicationContext exte
         Assert.assertEquals(HttpServletResponse.SC_OK, rc);
         Assert.assertTrue(res.toString().contains("<p>OK</p>"));
     }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddFilterWithFilterNameNull() {
+        getServletContext().addFilter(null, (Filter) null);
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddFilterWithFilterNameEmptyString() {
+        getServletContext().addFilter("", (Filter) null);
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddServletWithServletNameNull() {
+        getServletContext().addServlet(null, (Servlet) null);
+    }
+
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testAddServletWithServletNameEmptyString() {
+        getServletContext().addServlet("", (Servlet) null);
+    }
+
+
+    private ServletContext getServletContext() {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp-3.0");
+        // app dir is relative to server home
+        StandardContext standardContext = (StandardContext) tomcat.addWebapp(
+                null, "/test", appDir.getAbsolutePath());
+
+        return standardContext.getServletContext();
+    }
 }

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=1429970&r1=1429969&r2=1429970&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Jan  7 19:10:28 2013
@@ -99,6 +99,11 @@
         Georgieva. (markt) 
       </fix>
       <fix>
+        <bug>54284</bug>: As per clarification from the Servlet EG, anonymous
+        Filters and Servlets are not permitted. Patch by Violeta Georgieva.
+        (markt)
+      </fix>
+      <fix>
         <bug>54371</bug>: Prevent exceptions when processing web fragments for
         unexpanded WAR files when the context path contains characters that
         need to be encoded in URLs such as spaces. Patch provided by Polina



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

Reply via email to