tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r802882 - in /tomcat/trunk/java/org/apache/catalina/filters: RemoteAddrFilter.java RemoteHostFilter.java RequestFilter.java
Date Mon, 10 Aug 2009 18:23:17 GMT
Author: markt
Date: Mon Aug 10 18:23:17 2009
New Revision: 802882

URL: http://svn.apache.org/viewvc?rev=802882&view=rev
Log:
Add filtering of Comet events to the request filters
Based on a patch provided by Xie Xiaodong as part of GSOC2009.

Modified:
    tomcat/trunk/java/org/apache/catalina/filters/RemoteAddrFilter.java
    tomcat/trunk/java/org/apache/catalina/filters/RemoteHostFilter.java
    tomcat/trunk/java/org/apache/catalina/filters/RequestFilter.java

Modified: tomcat/trunk/java/org/apache/catalina/filters/RemoteAddrFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/RemoteAddrFilter.java?rev=802882&r1=802881&r2=802882&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/filters/RemoteAddrFilter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/filters/RemoteAddrFilter.java Mon Aug 10 18:23:17
2009
@@ -26,6 +26,8 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
+import org.apache.catalina.CometEvent;
+import org.apache.catalina.CometFilterChain;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -54,12 +56,13 @@
 
     /**
      * Extract the desired request property, and pass it (along with the
-     * specified request and response objects) to the protected
-     * <code>process()</code> method to perform the actual filtering.
-     * This method must be implemented by a concrete subclass.
+     * specified request and response objects and associated filter chain) to
+     * the protected <code>process()</code> method to perform the actual
+     * filtering.
      *
-     * @param request The servlet request to be processed
+     * @param request  The servlet request to be processed
      * @param response The servlet response to be created
+     * @param chain    The filter chain for this request
      *
      * @exception IOException if an input/output error occurs
      * @exception ServletException if a servlet error occurs
@@ -71,7 +74,25 @@
         process(request.getRemoteAddr(), request, response, chain);
 
     }
-    
+
+    /**
+     * Extract the desired request property, and pass it (along with the comet
+     * event and filter chain) to the protected <code>process()</code> method
+     * to perform the actual filtering.
+     *
+     * @param event The comet event to be processed
+     * @param chain The filter chain for this event
+     *
+     * @exception IOException if an input/output error occurs
+     * @exception ServletException if a servlet error occurs
+     */
+    @Override
+    public void doFilterEvent(CometEvent event, CometFilterChain chain)
+            throws IOException, ServletException {
+        processCometEvent(event.getHttpServletRequest().getRemoteHost(),
+                event, chain);        
+    }
+
     protected Log getLogger() {
         return log;
     }

Modified: tomcat/trunk/java/org/apache/catalina/filters/RemoteHostFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/RemoteHostFilter.java?rev=802882&r1=802881&r2=802882&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/filters/RemoteHostFilter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/filters/RemoteHostFilter.java Mon Aug 10 18:23:17
2009
@@ -26,6 +26,8 @@
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
+import org.apache.catalina.CometEvent;
+import org.apache.catalina.CometFilterChain;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 
@@ -55,12 +57,13 @@
 
     /**
      * Extract the desired request property, and pass it (along with the
-     * specified request and response objects) to the protected
-     * <code>process()</code> method to perform the actual filtering.
-     * This method must be implemented by a concrete subclass.
+     * specified request and response objects and associated filter chain) to
+     * the protected <code>process()</code> method to perform the actual
+     * filtering.
      *
-     * @param request The servlet request to be processed
+     * @param request  The servlet request to be processed
      * @param response The servlet response to be created
+     * @param chain    The filter chain for this request
      *
      * @exception IOException if an input/output error occurs
      * @exception ServletException if a servlet error occurs
@@ -72,8 +75,27 @@
         process(request.getRemoteHost(), request, response, chain);
 
     }
+    
+    /**
+     * Extract the desired request property, and pass it (along with the comet
+     * event and filter chain) to the protected <code>process()</code> method
+     * to perform the actual filtering.
+     *
+     * @param event The comet event to be processed
+     * @param chain The filter chain for this event
+     *
+     * @exception IOException if an input/output error occurs
+     * @exception ServletException if a servlet error occurs
+     */
+    @Override
+    public void doFilterEvent(CometEvent event, CometFilterChain chain)
+            throws IOException, ServletException {
+        processCometEvent(event.getHttpServletRequest().getRemoteHost(),
+                event, chain);        
+    }
 
     protected Log getLogger() {
         return log;
     }
+
 }

Modified: tomcat/trunk/java/org/apache/catalina/filters/RequestFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/filters/RequestFilter.java?rev=802882&r1=802881&r2=802882&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/filters/RequestFilter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/filters/RequestFilter.java Mon Aug 10 18:23:17 2009
@@ -30,6 +30,9 @@
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.catalina.CometEvent;
+import org.apache.catalina.CometFilter;
+import org.apache.catalina.CometFilterChain;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -67,7 +70,7 @@
  */
 
 public abstract class RequestFilter
-    extends FilterBase {
+    extends FilterBase implements CometFilter {
 
 
     // ----------------------------------------------------- Class Variables
@@ -253,44 +256,70 @@
             ServletResponse response, FilterChain chain)
             throws IOException, ServletException {
 
-        // Check the deny patterns, if any
+        if (isAllowed(property)) {
+            chain.doFilter(request, response);
+        } else {
+            if (isHttpServletResponse(response)) {
+                ((HttpServletResponse) response)
+                        .sendError(HttpServletResponse.SC_FORBIDDEN);
+            } else {
+                sendErrorWhenNotHttp(response);
+            }
+        }
+    }
+
+    /**
+     * Perform the filtering that has been configured for this Filter, matching
+     * against the specified request property.
+     * 
+     * @param property  The property to check against the allow/deny rules
+     * @param event     The comet event to be filtered
+     * @param chain     The comet filter chain
+     * @exception IOException if an input/output error occurs
+     * @exception ServletException if a servlet error occurs
+     */
+    protected void processCometEvent(String property, CometEvent event, CometFilterChain
chain)
+            throws IOException, ServletException {
+        HttpServletResponse response = event.getHttpServletResponse();
+        
+        if (isAllowed(property)) {
+            chain.doFilterEvent(event);
+        } else {
+            response.sendError(HttpServletResponse.SC_FORBIDDEN);
+            event.close();
+        }
+    }
+
+    /**
+     * Process the allow and deny rules for the provided property.
+     * 
+     * @param property  The property to test against the allow and deny lists
+     * @return          <code>true</code> if this request should be allowed,
+     *                  <code>false</code> otherwise
+     */
+    private boolean isAllowed(String property) {
         for (int i = 0; i < this.denies.length; i++) {
             if (this.denies[i].matcher(property).matches()) {
-                if (isHttpServletResponse(response)) {
-                    ((HttpServletResponse) response)
-                            .sendError(HttpServletResponse.SC_FORBIDDEN);
-                    return;
-                } else {
-                    sendErrorWhenNotHttp(response);
-                    return;
-                }
+                return false;
             }
         }
-
+     
         // Check the allow patterns, if any
         for (int i = 0; i < this.allows.length; i++) {
             if (this.allows[i].matcher(property).matches()) {
-                chain.doFilter(request, response);
-                return;
+                return true;
             }
         }
 
         // Allow if denies specified but not allows
         if ((this.denies.length > 0) && (this.allows.length == 0)) {
-            chain.doFilter(request, response);
-            return;
+            return true;
         }
 
         // Deny this request
-        if (isHttpServletResponse(response)) {
-            ((HttpServletResponse) response)
-                    .sendError(HttpServletResponse.SC_FORBIDDEN);
-        } else {
-            sendErrorWhenNotHttp(response);      
-        }
+        return false;
     }
 
-
     private void sendErrorWhenNotHttp(ServletResponse response)
             throws IOException {
         response.setContentType(PLAIN_TEXT_MIME_TYPE);



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


Mime
View raw message