Top Fields Constructors Methods
org.apache.catalina.filters

public final Class RemoteCIDRFilter

extends FilterBase
Class Inheritance
Imports
java.io.IOException, .PrintWriter, java.net.InetAddress, .UnknownHostException, java.util.ArrayList, .Collections, .List, jakarta.servlet.FilterChain, .ServletException, .ServletRequest, .ServletResponse, jakarta.servlet.http.HttpServletResponse, org.apache.catalina.util.NetMask, org.apache.juli.logging.Log, .LogFactory

Field Summary

Modifier and TypeField and Description
private final List<NetMask>
allow

The list of allowed NetMasks

private final List<NetMask>
deny

The list of denied NetMasks

private final Log
log

Our logger

private static final String
PLAIN_TEXT_MIME_TYPE

text/plain MIME type: this is the MIME type we return when a ServletResponse is not an HttpServletResponse

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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
doFilter(final ServletRequest
The request to process
request
,
final ServletResponse
The response associated with the request
response
,
final FilterChain
Provides access to the next filter in the chain for this filter to pass the request and response to for further processing
chain
)

Implements jakarta.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.

private List<String>

Returns:

a string list of processing errors (empty when no errors)
fillFromInput
(final String
The input string
input
,
final List<NetMask>
The list to fill
target
)

Fill a NetMask list from a string input containing a comma-separated list of (hopefully valid) NetMasks.

public String

Returns:

the #allow list as a string, without the leading '[' and trailing ']'
getAllow
()

Return a string representation of the NetMask list in #allow.

public String

Returns:

the #deny list as string, without the leading '[' and trailing ']'
getDeny
()

Return a string representation of the NetMask list in #deny.

public Log
private boolean

Returns:

true if allowed
isAllowed
(final String
The remote's IP address, as a string
property
)

Test if a remote's IP address is allowed to proceed.

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.

private void
public void
setAllow(final String
The list of netmasks, as a comma separated string
input
)

Fill the #allow list with the list of netmasks provided as an argument, if any.

public void
setDeny(final String
The list of netmasks, as a comma separated string
input
)

Fill the #deny list with the list of netmasks provided as an argument, if any.

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

Field Detail

allowback to summary
private final List<NetMask> allow

The list of allowed NetMasks

denyback to summary
private final List<NetMask> deny

The list of denied NetMasks

logback to summary
private final Log log

Our logger

PLAIN_TEXT_MIME_TYPEback to summary
private static final String PLAIN_TEXT_MIME_TYPE

text/plain MIME type: this is the MIME type we return when a ServletResponse is not an HttpServletResponse

Constructor Detail

RemoteCIDRFilterback to summary
public RemoteCIDRFilter()

Method Detail

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

Implements jakarta.servlet.Filter.doFilter.

Doc from jakarta.servlet.Filter.doFilter.

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

A typical implementation of this method would follow the following pattern:-
1. Examine the request
2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering
3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering
4. a) Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
4. b) or not pass on the request/response pair to the next entity in the filter chain to block the request processing
5. Directly set headers on the response after invocation of the next entity in the filter chain.

Parameters
request:ServletRequest

The request to process

response:ServletResponse

The response associated with the request

chain:FilterChain

Provides access to the next filter in the chain for this filter to pass the request and response to for further processing

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs during this filter's processing of the request
ServletException:
if the processing fails for any other reason
fillFromInputback to summary
private List<String> fillFromInput(final String input, final List<NetMask> target)

Fill a NetMask list from a string input containing a comma-separated list of (hopefully valid) NetMasks.

Parameters
input:String

The input string

target:List<NetMask>

The list to fill

Returns:List<String>

a string list of processing errors (empty when no errors)

getAllowback to summary
public String getAllow()

Return a string representation of the NetMask list in #allow.

Returns:String

the #allow list as a string, without the leading '[' and trailing ']'

getDenyback to summary
public String getDeny()

Return a string representation of the NetMask list in #deny.

Returns:String

the #deny list as string, without the leading '[' and trailing ']'

getLoggerback to summary
public Log getLogger()

Implements abstract org.apache.catalina.filters.FilterBase.getLogger.

Annotations
@Override
isAllowedback to summary
private boolean isAllowed(final String property)

Test if a remote's IP address is allowed to proceed.

Parameters
property:String

The remote's IP address, as a string

Returns:boolean

true if allowed

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
sendErrorWhenNotHttpback to summary
private void sendErrorWhenNotHttp(ServletResponse response) throws IOException
setAllowback to summary
public void setAllow(final String input)

Fill the #allow list with the list of netmasks provided as an argument, if any. Calls #fillFromInput.

Parameters
input:String

The list of netmasks, as a comma separated string

Exceptions
IllegalArgumentException:
One or more netmasks are invalid
setDenyback to summary
public void setDeny(final String input)

Fill the #deny list with the list of netmasks provided as an argument, if any. Calls #fillFromInput.

Parameters
input:String

The list of netmasks, as a comma separated string

Exceptions
IllegalArgumentException:
One or more netmasks are invalid