Package org.eclipse.jetty.server.handler
Class DoSHandler
java.lang.Object
- All Implemented Interfaces:
Handler,Handler.Container,Handler.Singleton,Request.Handler,Container,Destroyable,Dumpable,Dumpable.DumpableContainer,LifeCycle,Invocable
@ManagedObject("DoS Prevention Handler")
public class DoSHandler
extends ConditionalHandler.ElseNext
A Denial of Service Handler that protects from attacks by limiting the request rate from remote clients.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA Handler to reject DoS requests after first delaying them.static classThe Tracker implements the classic Leaky Bucket Algorithm.static classA Handler to reject DoS requests with a status code or failure.static interfaceA RateTracker is associated with an id, and stores request rate data.Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.ConditionalHandler
ConditionalHandler.Abstract, ConditionalHandler.ConnectorPredicate, ConditionalHandler.DontHandle, ConditionalHandler.ElseNext, ConditionalHandler.InetAddressPatternPredicate, ConditionalHandler.MethodPredicate, ConditionalHandler.NextElseReject, ConditionalHandler.PathSpecPredicate, ConditionalHandler.PredicateSet, ConditionalHandler.Reject, ConditionalHandler.SkipNextNested classes/interfaces inherited from class org.eclipse.jetty.server.Handler.Abstract
Handler.Abstract.NonBlockingNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendableNested classes/interfaces inherited from interface org.eclipse.jetty.server.Handler
Handler.AbstractContainer, Handler.Collection, Handler.Container, Handler.Sequence, Handler.Singleton, Handler.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.TaskNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.server.Request.Handler
Request.Handler.AbortException -
Field Summary
FieldsModifier and TypeFieldDescriptionFields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking, NOOP -
Constructor Summary
ConstructorsConstructorDescriptionDoSHandler(Function<Request, String> clientIdFn, DoSHandler.Tracker.Factory trackerFactory, Request.Handler rejectHandler, int maxTrackers) DoSHandler(DoSHandler.Tracker.Factory trackerFactory) DoSHandler(Handler handler, Function<Request, String> clientIdFn, DoSHandler.Tracker.Factory trackerFactory, Request.Handler rejectHandler, int maxTrackers) DoSHandler(Handler handler, Function<Request, String> clientIdFn, DoSHandler.Tracker.Factory trackerFactory, Request.Handler rejectHandler, int maxTrackers, boolean rejectUntracked) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.protected booleanonConditionsMet(Request request, Response response, Callback callback) Handle a request that has met the conditions.voidSet theServerto associate to thisHandler.Methods inherited from class org.eclipse.jetty.server.handler.ConditionalHandler.ElseNext
onConditionsNotMetMethods inherited from class org.eclipse.jetty.server.handler.ConditionalHandler
clear, dump, exclude, exclude, exclude, excludeInetAddressPattern, excludeMethod, excludePath, from, from, handle, include, include, include, includeInetAddressPattern, includeMethod, includePath, nextHandlerMethods inherited from class org.eclipse.jetty.server.Handler.Wrapper
getHandler, getInvocationType, setHandlerMethods inherited from class org.eclipse.jetty.server.Handler.AbstractContainer
findContainerOf, getDescendant, getDescendants, isDynamic, setDynamicMethods inherited from class org.eclipse.jetty.server.Handler.Abstract
destroy, getServerMethods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Destroyable
destroyMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpableMethods inherited from interface org.eclipse.jetty.server.Handler.Container
getContainer, getDescendant, getDescendants, getDescendantsMethods inherited from interface org.eclipse.jetty.server.Handler.Singleton
getHandlers, getTail, insertHandler, setHandlerMethods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Field Details
-
ID_FROM_REMOTE_ADDRESS_PORT
-
ID_FROM_REMOTE_ADDRESS
-
ID_FROM_REMOTE_PORT
-
ID_FROM_CONNECTION
-
-
Constructor Details
-
DoSHandler
- Parameters:
trackerFactory- Factory to create a Tracker
-
DoSHandler
public DoSHandler(@Name("clientIdFn") Function<Request, String> clientIdFn, @Name("trackerFactory") DoSHandler.Tracker.Factory trackerFactory, @Name("rejectHandler") Request.Handler rejectHandler, @Name("maxTrackers") int maxTrackers) - Parameters:
clientIdFn- Function to extract a remote client identifier from a request.trackerFactory- Factory to create a TrackerrejectHandler- AHandlerused to reject excess requests, ornullfor a default.maxTrackers- The maximum number of remote clients to track or -1 for a default value, 0 for unlimited. If this limit is exceeded, then requests from additional remote clients are rejected.
-
DoSHandler
public DoSHandler(@Name("handler") Handler handler, @Name("clientIdFn") Function<Request, String> clientIdFn, @Name("trackerFactory") DoSHandler.Tracker.Factory trackerFactory, @Name("rejectHandler") Request.Handler rejectHandler, @Name("maxTrackers") int maxTrackers) - Parameters:
handler- Then nextHandlerornullclientIdFn- Function to extract a remote client identifier from a request.trackerFactory- Factory to create a TrackerrejectHandler- AHandlerused to reject excess requests, ornullfor a default.maxTrackers- The maximum number of remote clients to track or -1 for a default value, 0 for unlimited. If this limit is exceeded, then requests from additional remote clients are rejected.
-
DoSHandler
public DoSHandler(@Name("handler") Handler handler, @Name("clientIdFn") Function<Request, String> clientIdFn, @Name("trackerFactory") DoSHandler.Tracker.Factory trackerFactory, @Name("rejectHandler") Request.Handler rejectHandler, @Name("maxTrackers") int maxTrackers, @Name("rejectUntracked") boolean rejectUntracked) - Parameters:
handler- Then nextHandlerornullclientIdFn- Function to extract a remote client identifier from a request.trackerFactory- Factory to create a TrackerrejectHandler- AHandlerused to reject excess requests, ornullfor a default.maxTrackers- The maximum number of remote clients to track or -1 for a default value, 0 for unlimited. If this limit is exceeded, then requests from additional remote clients are rejected.
-
-
Method Details
-
setServer
Description copied from interface:HandlerSet theServerto associate to thisHandler.- Specified by:
setServerin interfaceHandler- Overrides:
setServerin classHandler.AbstractContainer- Parameters:
server- theServerto associate to thisHandler
-
onConditionsMet
protected boolean onConditionsMet(Request request, Response response, Callback callback) throws Exception Description copied from class:ConditionalHandlerHandle a request that has met the conditions. Typically, the implementation will provide optional handling and then call theConditionalHandler.nextHandler(Request, Response, Callback)method to continue handling.- Specified by:
onConditionsMetin classConditionalHandler- Parameters:
request- The request to handleresponse- The response to generatecallback- The callback for completion- Returns:
- True if this handler will complete the callback
- Throws:
Exception- If there is a problem handling- See Also:
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classConditionalHandler- Throws:
AbstractLifeCycle.StopException- If thrown, the lifecycle will immediately be stopped.Exception- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classHandler.Abstract- Throws:
Exception- If there was a problem stopping. Will cause a transition to FAILED state
-