Class SecurityHandler
- All Implemented Interfaces:
Authenticator.Configuration, Handler, Handler.Container, Handler.Singleton, Request.Handler, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, Invocable
- Direct Known Subclasses:
ConstraintSecurityHandler, SecurityHandler.PathMapped
Select and apply an Authenticator to a request.
The Authenticator may either be directly set on the handler
or it will be created during AbstractLifeCycle.start() with a call to
either the default or set AuthenticatorFactory.
SecurityHandler has a set of parameters that are used by the Authentication.Configuration. At startup, any context init parameters that start with "org.eclipse.jetty.security." that do not have values in the SecurityHandler init parameters, are copied.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassstatic classA concrete implementation ofSecurityHandlerthat uses aPathMappingsto match request to a list ofConstraints, which are applied in the order of least significant to most significant.Nested classes/interfaces inherited from class Handler.Abstract
Handler.Abstract.NonBlockingNested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Authenticator.Configuration
Authenticator.Configuration.WrapperNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface Handler
Handler.Abstract, Handler.AbstractContainer, Handler.Collection, Handler.Container, Handler.Sequence, Handler.Singleton, Handler.WrapperNested classes/interfaces inherited from interface Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.TaskNested classes/interfaces inherited from interface LifeCycle
LifeCycle.ListenerNested classes/interfaces inherited from interface Request.Handler
Request.Handler.AbortException -
Field Summary
FieldsFields inherited from interface Invocable
__nonBlocking, NOOP -
Constructor Summary
Constructors -
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 IdentityServiceprotected LoginServiceFind an appropriateLoginServicefrom the list returned byContainer.getBeans(Class)called on the result ofHandler.Abstract.getServer().protected abstract ConstraintgetConstraint(String pathInContext, Request request) static SecurityHandlerGet the identityService.Get the loginService.getParameter(String key) Get a SecurityHandler init parameterGet a SecurityHandler init parameter namesintGet the interval in seconds, which if non-zero, will be set withSession.setMaxInactiveInterval(int)when a session is newly authenticatedbooleanInvoked to handle the passed HTTP request and response.protected booleanisAuthorized(Constraint constraint, AuthenticationState authenticationState) booleanShould session ID be renewed on authentication.protected voidredirectToSecure(Request request, Response response, Callback callback) voidsetAuthenticationType(String authenticationType) voidsetAuthenticator(Authenticator authenticator) Set the authenticator.voidsetAuthenticatorFactory(Authenticator.Factory authenticatorFactory) voidsetIdentityService(IdentityService identityService) Set the identityService.voidsetLoginService(LoginService loginService) Set the loginService.setParameter(String key, String value) Set an authentication parameter for retrieval viaAuthenticator.Configuration.getParameter(String)voidsetRealmName(String realmName) voidsetSessionMaxInactiveIntervalOnAuthentication(int seconds) Set the interval in seconds, which if non-zero, will be set withSession.setMaxInactiveInterval(int)when a session is newly authenticated.voidsetSessionRenewedOnAuthentication(boolean renew) Set renew the session on Authentication.Methods inherited from class Handler.Wrapper
getHandler, getInvocationType, setHandlerMethods inherited from class Handler.AbstractContainer
findContainerOf, getDescendant, getDescendants, isDynamic, setDynamic, setServerMethods inherited from class Handler.Abstract
destroy, getServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, 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 AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Destroyable
destroyMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface Handler.Container
getContainer, getDescendant, getDescendants, getDescendantsMethods inherited from interface Handler.Singleton
getHandlers, getTail, insertHandler, setHandlerMethods inherited from interface LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Field Details
-
SESSION_AUTHENTICATED_ATTRIBUTE
-
-
Constructor Details
-
SecurityHandler
protected SecurityHandler() -
SecurityHandler
-
-
Method Details
-
getIdentityService
Get the identityService.- Specified by:
getIdentityServicein interfaceAuthenticator.Configuration- Returns:
- the identityService
-
setIdentityService
Set the identityService.- Parameters:
identityService- the identityService to set
-
getLoginService
Get the loginService.- Specified by:
getLoginServicein interfaceAuthenticator.Configuration- Returns:
- the loginService
-
setLoginService
Set the loginService. If aLoginServiceis not set, or is set to null, then duringdoStart()thefindLoginService()method is used to locate one.- Parameters:
loginService- the loginService to set
-
getAuthenticator
-
setAuthenticator
Set the authenticator.- Parameters:
authenticator- the authenticator- Throws:
IllegalStateException- if the SecurityHandler is running
-
getAuthenticatorFactory
- Returns:
- the authenticatorFactory
-
setAuthenticatorFactory
- Parameters:
authenticatorFactory- the authenticatorFactory to set- Throws:
IllegalStateException- if the SecurityHandler is running
-
getKnownAuthenticatorFactories
- Returns:
- the list of discovered authenticatorFactories
-
getRealmName
- Specified by:
getRealmNamein interfaceAuthenticator.Configuration- Returns:
- the realmName
-
setRealmName
- Parameters:
realmName- the realmName to set- Throws:
IllegalStateException- if the SecurityHandler is running
-
getAuthenticationType
- Specified by:
getAuthenticationTypein interfaceAuthenticator.Configuration- Returns:
- the name of the Authenticator
-
setAuthenticationType
- Parameters:
authenticationType- the name of the Authenticator to use- Throws:
IllegalStateException- if the SecurityHandler is running
-
getParameter
Description copied from interface:Authenticator.ConfigurationGet a SecurityHandler init parameter- Specified by:
getParameterin interfaceAuthenticator.Configuration- Parameters:
key- parameter name- Returns:
- Parameter value or null
-
getParameterNames
Description copied from interface:Authenticator.ConfigurationGet a SecurityHandler init parameter names- Specified by:
getParameterNamesin interfaceAuthenticator.Configuration- Returns:
- Set of parameter names
-
setParameter
Set an authentication parameter for retrieval viaAuthenticator.Configuration.getParameter(String)- Parameters:
key- the keyvalue- the init value- Returns:
- previous value
- Throws:
IllegalStateException- if the SecurityHandler is started
-
findLoginService
Find an appropriateLoginServicefrom the list returned byContainer.getBeans(Class)called on the result ofHandler.Abstract.getServer(). A service is selected by:- if
setRealmName(String)has been called, the first service with a matching name is used - if the list is size 1, that service is used
- otherwise no service is selected.
- Returns:
- An appropriate
LoginServiceor null
- if
-
findIdentityService
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classHandler.Abstract- Throws:
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
-
isSessionRenewedOnAuthentication
public boolean isSessionRenewedOnAuthentication()Description copied from interface:Authenticator.ConfigurationShould session ID be renewed on authentication.- Specified by:
isSessionRenewedOnAuthenticationin interfaceAuthenticator.Configuration- Returns:
- true if the session ID should be renewed on authentication
-
setSessionRenewedOnAuthentication
public void setSessionRenewedOnAuthentication(boolean renew) Set renew the session on Authentication.If set to true, then on authentication, the session associated with a request is invalidated and replaced with a new session.
- Parameters:
renew- true to renew the authentication on session- See Also:
-
getSessionMaxInactiveIntervalOnAuthentication
public int getSessionMaxInactiveIntervalOnAuthentication()Description copied from interface:Authenticator.ConfigurationGet the interval in seconds, which if non-zero, will be set withSession.setMaxInactiveInterval(int)when a session is newly authenticated- Specified by:
getSessionMaxInactiveIntervalOnAuthenticationin interfaceAuthenticator.Configuration- Returns:
- An interval in seconds; or 0 to not set the interval on authentication; or a negative number to make the session never timeout after authentication.
-
setSessionMaxInactiveIntervalOnAuthentication
public void setSessionMaxInactiveIntervalOnAuthentication(int seconds) Set the interval in seconds, which if non-zero, will be set withSession.setMaxInactiveInterval(int)when a session is newly authenticated.- Parameters:
seconds- An interval in seconds; or 0 to not set the interval on authentication; or a negative number to make the session never timeout after authentication.- See Also:
-
handle
Description copied from interface:Request.HandlerInvoked to handle the passed HTTP request and response.
The request is accepted by returning true, then handling must be concluded by completing the passed callback. The handling may be asynchronous, i.e. this method may return true and complete the given callback later, possibly from a different thread. If this method returns false, then the callback must not be invoked and any mutation on the response reversed.
Exceptions thrown by this method may be subsequently handled by an error
Request.Handler, if present, otherwise a default HTTP 500 error is generated and the callback completed while writing the error response.The simplest implementation is:
public boolean handle(Request request, Response response, Callback callback) { callback.succeeded(); return true; }A HelloWorld implementation is:
public boolean handle(Request request, Response response, Callback callback) { response.write(true, ByteBuffer.wrap("Hello World\n".getBytes(StandardCharsets.UTF_8)), callback); return true; }- Specified by:
handlein interfaceRequest.Handler- Overrides:
handlein classHandler.Wrapper- Parameters:
request- the HTTP request to handleresponse- the HTTP response to handlecallback- the callback to complete when the handling is complete- Returns:
- True if and only if the request will be handled, a response generated and the callback eventually called. This may occur within the scope of the call to this method, or asynchronously some time later. If false is returned, then this method must not generate a response, nor complete the callback.
- Throws:
Exception- if there is a failure during the handling. Catchers cannot assume that the callback will be called and thus should attempt to complete the request as if a false had been returned.- See Also:
-
getCurrentSecurityHandler
-
getConstraint
-
redirectToSecure
-
isAuthorized
-
getKnownRoles
-