You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2011/11/03 21:37:27 UTC

svn commit: r1197300 - /tomcat/trunk/java/org/apache/catalina/valves/RequestFilterValve.java

Author: markt
Date: Thu Nov  3 20:37:26 2011
New Revision: 1197300

URL: http://svn.apache.org/viewvc?rev=1197300&view=rev
Log:
Ensure that subsequent attempts to start the Valves will not succeed
until valid configuration is provided.

Modified:
    tomcat/trunk/java/org/apache/catalina/valves/RequestFilterValve.java

Modified: tomcat/trunk/java/org/apache/catalina/valves/RequestFilterValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/RequestFilterValve.java?rev=1197300&r1=1197299&r2=1197300&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/RequestFilterValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/RequestFilterValve.java Thu Nov  3 20:37:26 2011
@@ -73,6 +73,14 @@ public abstract class RequestFilterValve
      */
     protected volatile Pattern allow = null;
 
+
+    /**
+     * The current allow configuration value that may or may not compile into a
+     * valid {@link Pattern}.
+     */
+    protected volatile String allowValue = null;
+
+
     /**
      * Helper variable to catch configuration errors.
      * It is <code>true</code> by default, but becomes <code>false</code>
@@ -87,6 +95,14 @@ public abstract class RequestFilterValve
      */
     protected volatile Pattern deny = null;
 
+
+    /**
+     * The current deny configuration value that may or may not compile into a
+     * valid {@link Pattern}.
+     */
+    protected volatile String denyValue = null;
+
+
     /**
      * Helper variable to catch configuration errors.
      * It is <code>true</code> by default, but becomes <code>false</code>
@@ -104,12 +120,7 @@ public abstract class RequestFilterValve
      * Valve, if any; otherwise, return <code>null</code>.
      */
     public String getAllow() {
-        // Use local copies for thread safety
-        Pattern allow = this.allow;
-        if (allow == null) {
-            return null;
-        }
-        return allow.toString();
+        return allowValue;
     }
 
 
@@ -122,10 +133,12 @@ public abstract class RequestFilterValve
     public void setAllow(String allow) {
         if (allow == null || allow.length() == 0) {
             this.allow = null;
+            allowValue = null;
             allowValid = true;
         } else {
             boolean success = false;
             try {
+                allowValue = allow;
                 this.allow = Pattern.compile(allow);
                 success = true;
             } finally {
@@ -140,12 +153,7 @@ public abstract class RequestFilterValve
      * Valve, if any; otherwise, return <code>null</code>.
      */
     public String getDeny() {
-        // Use local copies for thread safety
-        Pattern deny = this.deny;
-        if (deny == null) {
-            return null;
-        }
-        return deny.toString();
+        return denyValue;
     }
 
 
@@ -158,10 +166,12 @@ public abstract class RequestFilterValve
     public void setDeny(String deny) {
         if (deny == null || deny.length() == 0) {
             this.deny = null;
+            denyValue = null;
             denyValid = true;
         } else {
             boolean success = false;
             try {
+                denyValue = deny;
                 this.deny = Pattern.compile(deny);
                 success = true;
             } finally {
@@ -203,6 +213,16 @@ public abstract class RequestFilterValve
     }
 
 
+    @Override
+    protected synchronized void startInternal() throws LifecycleException {
+        if (!allowValid || !denyValid) {
+            throw new LifecycleException(
+                    sm.getString("requestFilterValve.configInvalid"));
+        }
+        super.startInternal();
+    }
+
+
     /**
      * Perform the filtering that has been configured for this Valve, matching
      * against the specified request property.



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