Package org.apache.catalina.valves
Class RequestFilterValve
- java.lang.Object
-
- org.apache.catalina.valves.ValveBase
-
- org.apache.catalina.valves.RequestFilterValve
-
- All Implemented Interfaces:
Contained
,Lifecycle
,Valve
,GlassFishValve
- 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/ordeny
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:- The subclass extracts the request property to be filtered, and
calls the common
process()
method. - If there are any deny expressions configured, the property will be compared to each such expression. If a match is found, this request will be rejected with a "Forbidden" HTTP response.
- If there are any allow expressions configured, the property will be compared to each such expression. If a match is found, this request will be allowed to pass through to the next Valve in the current pipeline.
- If one or more deny expressions was specified but no allow expressions, allow this request to pass through (because none of the deny expressions matched it).
- The request will be rejected with a "Forbidden" HTTP response.
This Valve may be attached to any Container, depending on the granularity of the filtering you wish to perform.
- Version:
- $Revision: 1.5 $ $Date: 2006/03/07 22:30:07 $
- Author:
- Craig R. McClanahan
-
-
Field Summary
Fields Modifier and Type Field Description protected String
allow
The comma-delimited set ofallow
expressions.protected Pattern[]
allows
The set ofallow
regular expressions we will evaluate.protected Pattern[]
denies
The set ofdeny
regular expressions we will evaluate.protected String
deny
The comma-delimited set ofdeny
expressions.-
Fields inherited from class org.apache.catalina.valves.ValveBase
container, controller, debug, domain, lifecycle, log, next, oname, rb, started
-
Fields inherited from interface org.glassfish.web.valve.GlassFishValve
END_PIPELINE, INVOKE_NEXT
-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
-
-
Constructor Summary
Constructors Constructor Description RequestFilterValve()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description String
getAllow()
Return a comma-delimited set of theallow
expressions configured for this Valve, if any; otherwise, returnnull
.String
getDeny()
Return a comma-delimited set of thedeny
expressions configured for this Valve, if any; otherwise, returnnull
.String
getInfo()
Return descriptive information about this Valve implementation.abstract int
invoke(Request request, Response response)
Extract the desired request property, and pass it (along with the specified request and response objects) to the protectedprocess()
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 benull
or a comma-delimited list of regular expression patterns.protected int
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 theallow
expressions configured for this Valve, if any.void
setDeny(String deny)
Set the comma-delimited set of thedeny
expressions configured for this Valve, if any.-
Methods inherited from class org.apache.catalina.valves.ValveBase
addLifecycleListener, backgroundProcess, createObjectName, event, findLifecycleListeners, getContainer, getController, getDebug, getDomain, getNext, getObjectName, getParentName, invoke, isStarted, postInvoke, removeLifecycleListener, setContainer, setController, setDebug, setNext, setObjectName, start, stop
-
-
-
-
Field Detail
-
allow
protected String allow
The comma-delimited set ofallow
expressions.
-
allows
protected Pattern[] allows
The set ofallow
regular expressions we will evaluate.
-
denies
protected Pattern[] denies
The set ofdeny
regular expressions we will evaluate.
-
deny
protected String deny
The comma-delimited set ofdeny
expressions.
-
-
Method Detail
-
getAllow
public String getAllow()
Return a comma-delimited set of theallow
expressions configured for this Valve, if any; otherwise, returnnull
.
-
setAllow
public void setAllow(String allow)
Set the comma-delimited set of theallow
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 thedeny
expressions configured for this Valve, if any; otherwise, returnnull
.
-
setDeny
public void setDeny(String deny)
Set the comma-delimited set of thedeny
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.
-
invoke
public abstract int invoke(Request request, Response response) throws IOException, jakarta.servlet.ServletException
Extract the desired request property, and pass it (along with the specified request and response objects) to the protectedprocess()
method to perform the actual filtering. This method must be implemented by a concrete subclass.- Specified by:
invoke
in interfaceGlassFishValve
- Specified by:
invoke
in classValveBase
- Parameters:
request
- The servlet request to be processedresponse
- The servlet response to be created- Returns:
INVOKE_NEXT
orEND_PIPELINE
- Throws:
IOException
- if an input/output error occursjakarta.servlet.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 benull
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 int process(String property, Request request, Response response) throws IOException, jakarta.servlet.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 filterrequest
- The servlet request to be processedresponse
- The servlet response to be processed- Throws:
IOException
- if an input/output error occursjakarta.servlet.ServletException
- if a servlet error occurs
-
-