Top Description Fields Constructors Methods
org.apache.catalina.filters

public abstract Class RequestFilter

extends FilterBase
Class Inheritance
Known Direct Subclasses
org.apache.catalina.filters.RemoteAddrFilter, org.apache.catalina.filters.RemoteHostFilter
Imports
java.io.IOException, java.util.regex.Pattern, jakarta.servlet.FilterChain, .ServletException, .ServletRequest, .ServletResponse, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse

Implementation of a Filter 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 the regular expressions configured for this Filter.

This filter is configured by setting the allow and/or deny properties to a regular expressions (in the syntax supported by Pattern) to which the appropriate request property will be compared. Evaluation proceeds as follows:

Field Summary

Modifier and TypeField and Description
protected Pattern
allow

The regular expression used to test for allowed requests.

protected Pattern
deny

The regular expression used to test for denied requests.

protected int
denyStatus

The HTTP response status code that is used when rejecting denied request.

private static final String
PLAIN_TEXT_MIME_TYPE

mime type -- "text/plain"

Inherited from org.apache.catalina.filters.FilterBase:
sm

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract void
doFilter(ServletRequest
The servlet request to be processed
request
,
ServletResponse
The servlet response to be created
response
,
FilterChain
The filter chain
chain
)

Redeclares jakarta.servlet.Filter.doFilter.

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.

public String

Returns:

the regular expression used to test for allowed requests for this Filter, if any; otherwise, return null.
getAllow
()

public String

Returns:

the regular expression used to test for denied requests for this Filter, if any; otherwise, return null.
getDeny
()

public int

Returns:

response status code that is used to reject denied request.
getDenyStatus
()

private boolean

Returns:

true if this request should be allowed, false otherwise
isAllowed
(String
The property to test against the allow and deny lists
property
)

Process the allow and deny rules for the provided property.

protected boolean
isConfigProblemFatal()

Overrides org.apache.catalina.filters.FilterBase.isConfigProblemFatal.

Determines if an exception when calling a setter or an unknown configuration attribute triggers the failure of the this filter which in turn will prevent the web application from starting.

protected void
process(String
The request property on which to filter
property
,
ServletRequest
The servlet request to be processed
request
,
ServletResponse
The servlet response to be processed
response
,
FilterChain
The filter chain
chain
)

Perform the filtering that has been configured for this Filter, matching against the specified request property.

private void
public void
setAllow(String
The new allow expression
allow
)

Set the regular expression used to test for allowed requests for this Filter, if any.

public void
setDeny(String
The new deny expression
deny
)

Set the regular expression used to test for denied requests for this Filter, if any.

public void
setDenyStatus(int
The status code for deny
denyStatus
)

Set response status code that is used to reject denied request.

Inherited from org.apache.catalina.filters.FilterBase:
getLoggerinit

Field Detail

allowback to summary
protected Pattern allow

The regular expression used to test for allowed requests.

denyback to summary
protected Pattern deny

The regular expression used to test for denied requests.

denyStatusback to summary
protected int denyStatus

The HTTP response status code that is used when rejecting denied request. It is 403 by default, but may be changed to be 404.

PLAIN_TEXT_MIME_TYPEback to summary
private static final String PLAIN_TEXT_MIME_TYPE

mime type -- "text/plain"

Constructor Detail

RequestFilterback to summary
public RequestFilter()

Method Detail

doFilterback to summary
public abstract void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException

Redeclares jakarta.servlet.Filter.doFilter.

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.

Parameters
request:ServletRequest

The servlet request to be processed

response:ServletResponse

The servlet response to be created

chain:FilterChain

The filter chain

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet error occurs
getAllowback to summary
public String getAllow()
Returns:String

the regular expression used to test for allowed requests for this Filter, if any; otherwise, return null.

getDenyback to summary
public String getDeny()
Returns:String

the regular expression used to test for denied requests for this Filter, if any; otherwise, return null.

getDenyStatusback to summary
public int getDenyStatus()
Returns:int

response status code that is used to reject denied request.

isAllowedback to summary
private boolean isAllowed(String property)

Process the allow and deny rules for the provided property.

Parameters
property:String

The property to test against the allow and deny lists

Returns:boolean

true if this request should be allowed, false otherwise

isConfigProblemFatalback to summary
protected boolean isConfigProblemFatal()

Overrides org.apache.catalina.filters.FilterBase.isConfigProblemFatal.

Doc from org.apache.catalina.filters.FilterBase.isConfigProblemFatal.

Determines if an exception when calling a setter or an unknown configuration attribute triggers the failure of the this filter which in turn will prevent the web application from starting.

Returns:boolean

true if a problem should trigger the failure of this filter, else false

Annotations
@Override
processback to summary
protected void process(String property, ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException

Perform the filtering that has been configured for this Filter, matching against the specified request property.

Parameters
property:String

The request property on which to filter

request:ServletRequest

The servlet request to be processed

response:ServletResponse

The servlet response to be processed

chain:FilterChain

The filter chain

Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet error occurs
sendErrorWhenNotHttpback to summary
private void sendErrorWhenNotHttp(ServletResponse response) throws IOException
setAllowback to summary
public void setAllow(String allow)

Set the regular expression used to test for allowed requests for this Filter, if any.

Parameters
allow:String

The new allow expression

setDenyback to summary
public void setDeny(String deny)

Set the regular expression used to test for denied requests for this Filter, if any.

Parameters
deny:String

The new deny expression

setDenyStatusback to summary
public void setDenyStatus(int denyStatus)

Set response status code that is used to reject denied request.

Parameters
denyStatus:int

The status code for deny