Class SecurityHandler
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.Handler.Abstract
org.eclipse.jetty.server.Handler.AbstractContainer
org.eclipse.jetty.server.Handler.Wrapper
org.eclipse.jetty.security.SecurityHandler
- All Implemented Interfaces:
Authenticator.Configuration, org.eclipse.jetty.server.Handler, org.eclipse.jetty.server.Handler.Container, org.eclipse.jetty.server.Handler.Singleton, org.eclipse.jetty.server.Request.Handler, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.util.thread.Invocable
- Direct Known Subclasses:
SecurityHandler.PathMapped, SecurityHandler.PathMethodMapped
public abstract class SecurityHandler
extends org.eclipse.jetty.server.Handler.Wrapper
implements Authenticator.Configuration
Abstract SecurityHandler.
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.static classA concrete implementation ofSecurityHandlerthat uses aPathMappingsto match request paths to a map of an HTTP method to aConstraint.Nested classes/interfaces inherited from class org.eclipse.jetty.server.Handler.Abstract
org.eclipse.jetty.server.Handler.Abstract.NonBlockingNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Authenticator.Configuration
Authenticator.Configuration.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.Dumpable.DumpAppendableNested classes/interfaces inherited from interface org.eclipse.jetty.server.Handler
org.eclipse.jetty.server.Handler.Abstract, org.eclipse.jetty.server.Handler.AbstractContainer, org.eclipse.jetty.server.Handler.Collection, org.eclipse.jetty.server.Handler.Container, org.eclipse.jetty.server.Handler.Sequence, org.eclipse.jetty.server.Handler.Singleton, org.eclipse.jetty.server.Handler.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
org.eclipse.jetty.util.thread.Invocable.Callable, org.eclipse.jetty.util.thread.Invocable.InvocationType, org.eclipse.jetty.util.thread.Invocable.ReadyTask, org.eclipse.jetty.util.thread.Invocable.TaskNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.server.Request.Handler
org.eclipse.jetty.server.Request.Handler.AbortException -
Field Summary
FieldsFields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
LEGENDFields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking, NOOP -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedSecurityHandler(org.eclipse.jetty.server.Handler handler) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStart()protected voiddoStop()protected IdentityServiceprotected LoginServiceFind an appropriateLoginServicefrom the list returned byContainer.getBeans(Class)called on the result ofHandler.Abstract.getServer().protected abstract ConstraintgetConstraint(String pathInContext, org.eclipse.jetty.server.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 authenticatedbooleanhandle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) protected booleanisAuthorized(Constraint constraint, AuthenticationState authenticationState) booleanShould session ID be renewed on authentication.protected voidredirectToSecure(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.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 org.eclipse.jetty.server.Handler.Wrapper
getHandler, getInvocationType, setHandlerMethods inherited from class org.eclipse.jetty.server.Handler.AbstractContainer
findContainerOf, getDescendant, getDescendants, isDynamic, setDynamic, setServerMethods 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, 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 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
dumpSelfMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpableMethods inherited from interface org.eclipse.jetty.server.Handler
getServer, setServerMethods 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
-
SESSION_AUTHENTICATED_ATTRIBUTE
-
-
Constructor Details
-
SecurityHandler
protected SecurityHandler() -
SecurityHandler
protected SecurityHandler(org.eclipse.jetty.server.Handler handler)
-
-
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
-
doStop
-
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
public boolean handle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) throws Exception - Specified by:
handlein interfaceorg.eclipse.jetty.server.Request.Handler- Overrides:
handlein classorg.eclipse.jetty.server.Handler.Wrapper- Throws:
Exception
-
getCurrentSecurityHandler
-
getConstraint
protected abstract Constraint getConstraint(String pathInContext, org.eclipse.jetty.server.Request request) -
redirectToSecure
protected void redirectToSecure(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) -
isAuthorized
-
getKnownRoles
-