Apache Tomcat 7.0.4

org.apache.catalina.valves
Class RequestFilterValve

java.lang.Object
  extended by org.apache.catalina.util.LifecycleBase
      extended by org.apache.catalina.util.LifecycleMBeanBase
          extended by org.apache.catalina.valves.ValveBase
              extended by org.apache.catalina.valves.RequestFilterValve
All Implemented Interfaces:
MBeanRegistration, Contained, Lifecycle, Valve
Direct Known Subclasses:
RemoteAddrValve, RemoteHostValve

public abstract class RequestFilterValve
extends ValveBase

Implementation of a Valve that performs filtering based on comparing the appropriate request property (selected based on which subclass you choose to configure into your Container's pipeline) against a set of regular expressions configured for this Valve.

This valve is configured by setting the allow and/or deny properties to a comma-delimited list of regular expressions (in the syntax supported by the jakarta-regexp library) to which the appropriate request property will be compared. Evaluation proceeds as follows:

This Valve may be attached to any Container, depending on the granularity of the filtering you wish to perform.

Version:
$Id: RequestFilterValve.java 939305 2010-04-29 13:43:39Z kkolinko $
Author:
Craig R. McClanahan

Field Summary
protected  String allow
          The comma-delimited set of allow expressions.
protected  Pattern[] allows
          The set of allow regular expressions we will evaluate.
protected  Pattern[] denies
          The set of deny regular expressions we will evaluate.
protected  String deny
          The comma-delimited set of deny expressions.
protected static StringManager sm
          The StringManager for this package.
 
Fields inherited from class org.apache.catalina.valves.ValveBase
asyncSupported, container, containerLog, next
 
Fields inherited from class org.apache.catalina.util.LifecycleMBeanBase
mserver
 
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, DESTROY_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
 
Constructor Summary
RequestFilterValve()
           
 
Method Summary
 String getAllow()
          Return a comma-delimited set of the allow expressions configured for this Valve, if any; otherwise, return null.
 String getDeny()
          Return a comma-delimited set of the deny expressions configured for this Valve, if any; otherwise, return null.
 String getInfo()
          Return descriptive information about this Valve implementation.
abstract  void invoke(Request request, Response response)
          Extract the desired request property, and pass it (along with the specified request and response objects) to the protected process() method to perform the actual filtering.
protected  Pattern[] precalculate(String list)
          Return an array of regular expression objects initialized from the specified argument, which must be null or a comma-delimited list of regular expression patterns.
protected  void process(String property, Request request, Response response)
          Perform the filtering that has been configured for this Valve, matching against the specified request property.
 void setAllow(String allow)
          Set the comma-delimited set of the allow expressions configured for this Valve, if any.
 void setDeny(String deny)
          Set the comma-delimited set of the deny expressions configured for this Valve, if any.
 
Methods inherited from class org.apache.catalina.valves.ValveBase
backgroundProcess, event, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, startInternal, stopInternal, toString
 
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
 
Methods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, init, removeLifecycleListener, setState, setState, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sm

protected static final StringManager sm
The StringManager for this package.


allow

protected String allow
The comma-delimited set of allow expressions.


allows

protected Pattern[] allows
The set of allow regular expressions we will evaluate.


denies

protected Pattern[] denies
The set of deny regular expressions we will evaluate.


deny

protected String deny
The comma-delimited set of deny expressions.

Constructor Detail

RequestFilterValve

public RequestFilterValve()
Method Detail

getAllow

public String getAllow()
Return a comma-delimited set of the allow expressions configured for this Valve, if any; otherwise, return null.


setAllow

public void setAllow(String allow)
Set the comma-delimited set of the allow expressions configured for this Valve, if any.

Parameters:
allow - The new set of allow expressions

getDeny

public String getDeny()
Return a comma-delimited set of the deny expressions configured for this Valve, if any; otherwise, return null.


setDeny

public void setDeny(String deny)
Set the comma-delimited set of the deny expressions configured for this Valve, if any.

Parameters:
deny - The new set of deny expressions

getInfo

public String getInfo()
Return descriptive information about this Valve implementation.

Specified by:
getInfo in interface Valve
Overrides:
getInfo in class ValveBase

invoke

public abstract void invoke(Request request,
                            Response response)
                     throws IOException,
                            ServletException
Extract the desired request property, and pass it (along with the specified request and response objects) to the protected process() method to perform the actual filtering. This method must be implemented by a concrete subclass.

Specified by:
invoke in interface Valve
Specified by:
invoke in class ValveBase
Parameters:
request - The servlet request to be processed
response - The servlet response to be created
Throws:
IOException - if an input/output error occurs
ServletException - if a servlet error occurs

precalculate

protected Pattern[] precalculate(String list)
Return an array of regular expression objects initialized from the specified argument, which must be null or a comma-delimited list of regular expression patterns.

Parameters:
list - The comma-separated list of patterns
Throws:
IllegalArgumentException - if one of the patterns has invalid syntax

process

protected void process(String property,
                       Request request,
                       Response response)
                throws IOException,
                       ServletException
Perform the filtering that has been configured for this Valve, matching against the specified request property.

Parameters:
property - The request property on which to filter
request - The servlet request to be processed
response - The servlet response to be processed
Throws:
IOException - if an input/output error occurs
ServletException - if a servlet error occurs

Apache Tomcat 7.0.4

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.