Class IPAccessHandler
- All Implemented Interfaces:
Handler, HandlerContainer, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
Controls access to the wrapped handler by the real remote IP. Control is provided by white/black lists that include both internet addresses and URIs. This handler uses the real internet address of the connection, not one reported in the forwarded for headers, as this cannot be as easily forged.
Typically, the black/white lists will be used in one of three modes:
- Blocking a few specific IPs/URLs by specifying several black list entries.
- Allowing only some specific IPs/URLs by specifying several white lists entries.
- Allowing a general range of IPs/URLs by specifying several general white list entries, that are then further refined by several specific black list exceptions
By default an empty white list is treated as match all. If there is at least one entry in the white list, then a request must match a white list entry. Black list entries are always applied, so that even if an entry matches the white list, a black list entry will override it.
You can change white list policy setting whiteListByPath to true. In this mode a request will be white listed IF it has a matching URL in the white list, otherwise the black list applies, e.g. in default mode when whiteListByPath = false and wl = "127.0.0.1|/foo", /bar request from 127.0.0.1 will be blacklisted, if whiteListByPath=true then not.
Internet addresses may be specified as absolute address or as a combination of four octet wildcard specifications (a.b.c.d) that are defined as follows.
nnn - an absolute value (0-255)
mmm-nnn - an inclusive range of absolute values,
with following shorthand notations:
nnn- => nnn-255
-nnn => 0-nnn
- => 0-255
a,b,... - a list of wildcard specifications
Internet address specification is separated from the URI pattern using the "|" (pipe) character. URI patterns follow the servlet specification for simple * prefix and suffix wild cards (e.g. /, /foo, /foo/bar, /foo/bar/*, *.baz).
Earlier versions of the handler used internet address prefix wildcard specification to define a range of the internet addresses (e.g. 127., 10.10., 172.16.1.). They also used the first "/" character of the URI pattern to separate it from the internet address. Both of these features have been deprecated in the current version.
Examples of the entry specifications are:
- 10.10.1.2 - all requests from IP 10.10.1.2
- 10.10.1.2|/foo/bar - all requests from IP 10.10.1.2 to URI /foo/bar
- 10.10.1.2|/foo/* - all requests from IP 10.10.1.2 to URIs starting with /foo/
- 10.10.1.2|*.html - all requests from IP 10.10.1.2 to URIs ending with .html
- 10.10.0-255.0-255 - all requests from IPs within 10.10.0.0/16 subnet
- 10.10.0-.-255|/foo/bar - all requests from IPs within 10.10.0.0/16 subnet to URI /foo/bar
- 10.10.0-3,1,3,7,15|/foo/* - all requests from IPs addresses with last octet equal to 1,3,7,15 in subnet 10.10.0.0/22 to URIs starting with /foo/
Earlier versions of the handler used internet address prefix wildcard specification to define a range of the internet addresses (e.g. 127., 10.10., 172.16.1.). They also used the first "/" character of the URI pattern to separate it from the internet address. Both of these features have been deprecated in the current version.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractHandler
AbstractHandler.ErrorDispatchHandlerNested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
FieldsModifier and TypeFieldDescription(package private) PathMap<IPAddressMap<Boolean>> Deprecated.(package private) PathMap<IPAddressMap<Boolean>> Deprecated.(package private) booleanDeprecated.private static final LoggerDeprecated.Fields inherited from class HandlerWrapper
_handler -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.Creates new handler objectIPAccessHandler(String[] white, String[] black) Deprecated.Creates new handler object and initializes white- and black-list -
Method Summary
Modifier and TypeMethodDescriptionprotected voidadd(String entry, PathMap<IPAddressMap<Boolean>> patternMap) Deprecated.Helper method to parse the new entry and add it to the specified address pattern map.voidDeprecated.Add a blacklist entry to an existing handler configurationvoidDeprecated.Add a whitelist entry to an existing handler configurationvoiddump(Appendable out, String indent) Deprecated.Dump the handler configurationvoidhandle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Deprecated.Checks the incoming request against the whitelist and blacklistprotected booleanisAddrUriAllowed(String addr, String path) Deprecated.Check if specified request is allowed by current IPAccess rules.protected voidset(String[] entries, PathMap<IPAddressMap<Boolean>> patternMap) Deprecated.Helper method to process a list of new entries and replace the content of the specified address pattern mapvoidDeprecated.Re-initialize the blacklist of existing handler objectvoidDeprecated.Re-initialize the whitelist of existing handler objectvoidsetWhiteListByPath(boolean whiteListByPath) Deprecated.Re-initialize the mode of path matchingMethods inherited from class HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandlerMethods inherited from class AbstractHandlerContainer
doShutdown, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServerMethods inherited from class AbstractHandler
doError, doStart, doStop, getServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansMethods inherited from class AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Field Details
-
LOG
Deprecated. -
_white
PathMap<IPAddressMap<Boolean>> _whiteDeprecated. -
_black
PathMap<IPAddressMap<Boolean>> _blackDeprecated. -
_whiteListByPath
boolean _whiteListByPathDeprecated.
-
-
Constructor Details
-
IPAccessHandler
public IPAccessHandler()Deprecated.Creates new handler object -
IPAccessHandler
-
-
Method Details
-
addWhite
Deprecated.Add a whitelist entry to an existing handler configuration- Parameters:
entry- new whitelist entry
-
addBlack
Deprecated.Add a blacklist entry to an existing handler configuration- Parameters:
entry- new blacklist entry
-
setWhite
Deprecated.Re-initialize the whitelist of existing handler object- Parameters:
entries- array of whitelist entries
-
setBlack
Deprecated.Re-initialize the blacklist of existing handler object- Parameters:
entries- array of blacklist entries
-
setWhiteListByPath
public void setWhiteListByPath(boolean whiteListByPath) Deprecated.Re-initialize the mode of path matching- Parameters:
whiteListByPath- matching mode
-
handle
public void handle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException Deprecated.Checks the incoming request against the whitelist and blacklist- Specified by:
handlein interfaceHandler- Overrides:
handlein classHandlerWrapper- Parameters:
target- The target of the request - either a URI or a name.baseRequest- The original unwrapped request object.request- The request either as theRequestobject or a wrapper of that request. Themethod can be used access the Request object if required.HttpConnection.getCurrentConnection().getHttpChannel().getRequest()response- The response as theResponseobject or a wrapper of that request. Themethod can be used access the Response object if required.HttpConnection.getCurrentConnection().getHttpChannel().getResponse()- Throws:
IOException- if unable to handle the request or response processingjavax.servlet.ServletException- if unable to handle the request or response due to underlying servlet issue- See Also:
-
add
Deprecated.Helper method to parse the new entry and add it to the specified address pattern map.- Parameters:
entry- new entrypatternMap- target address pattern map
-
set
Deprecated.Helper method to process a list of new entries and replace the content of the specified address pattern map- Parameters:
entries- new entriespatternMap- target address pattern map
-
isAddrUriAllowed
-
dump
Deprecated.Dump the handler configuration- Specified by:
dumpin interfaceDumpable- Overrides:
dumpin classContainerLifeCycle- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
IOException- if unable to write to Appendable
-
InetAccessHandler.