Class ConstraintSecurityHandler
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
org.eclipse.jetty.ee10.servlet.security.ConstraintSecurityHandler
- All Implemented Interfaces:
ConstraintAware, Authenticator.Configuration, Handler, Handler.Container, Handler.Singleton, Request.Handler, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, Invocable
ConstraintSecurityHandler
Handler to enforce SecurityConstraints. This implementation is servlet spec 3.1 compliant and pre-computes the constraint combinations for runtime efficiency.
-
Nested Class Summary
Nested classes/interfaces inherited from class SecurityHandler
SecurityHandler.NotChecked, SecurityHandler.PathMappedNested 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 class SecurityHandler
SESSION_AUTHENTICATED_ATTRIBUTEFields inherited from interface Invocable
__nonBlocking, NOOP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConstraintMapping(ConstraintMapping mapping) Add a Constraint Mapping.voidaddKnownRole(String role) Add a Role definition.booleanServlet spec 3.1 pg. 147.protected ConstraintcombineServletConstraints(Constraint constraintA, Constraint constraintB) Combine constrains as per the servlet specification.static ConstraintcreateConstraint(String name, jakarta.servlet.HttpConstraintElement element) Create a Constraintstatic ConstraintcreateConstraint(String name, String[] rolesAllowed, jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic permitOrDeny, jakarta.servlet.annotation.ServletSecurity.TransportGuarantee transport) Create Constraintstatic List<ConstraintMapping> createConstraintsWithMappingsForPath(String name, String pathSpec, jakarta.servlet.ServletSecurityElement securityElement) Generate Constraints and ConstraintMappings for the given url pattern and ServletSecurityElementprotected 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.voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.protected ConstraintgetConstraint(String pathInContext, Request request) getOmittedMethods(String omission) Given a string of the form<method>.<method>.omissionsplit out the individual method names.Servlet spec 3.1 pg. 147.booleanprotected booleanomissionsExist(Map<String, Constraint> methodMappings) Check if any http method omissions exist in the list of method to auth info mappings.protected voidCreate and combine the constraint with the existing processed constraints.protected voidprocessConstraintMappingWithMethodOmissions(ConstraintMapping mapping, Map<String, Constraint> mappings) Constraints that name method omissions are dealt with differently.static List<ConstraintMapping> removeConstraintMappingsForPath(String pathSpec, List<ConstraintMapping> constraintMappings) Take out of the constraint mappings those that match the given path.voidsetConstraintMappings(List<ConstraintMapping> constraintMappings) Process the constraints following the combining rules in Servlet 3.0 EA spec section 13.7.1 Note that much of the logic is in the Constraint class.voidsetConstraintMappings(List<ConstraintMapping> constraintMappings, Set<String> roles) Process the constraints following the combining rules in Servlet 3.0 EA spec section 13.7.1 Note that much of the logic is in the Constraint class.voidsetConstraintMappings(ConstraintMapping[] constraintMappings) Process the constraints following the combining rules in Servlet 3.0 EA spec section 13.7.1 Note that much of the logic is in the Constraint class.voidsetDenyUncoveredHttpMethods(boolean deny) See Servlet Spec 31, sec 13.8.4, pg 145 When true, requests with http methods not explicitly covered either by inclusion or omissions in constraints, will have access denied.voidSet the known roles.Methods inherited from class SecurityHandler
findIdentityService, findLoginService, getAuthenticationType, getAuthenticator, getAuthenticatorFactory, getCurrentSecurityHandler, getIdentityService, getKnownAuthenticatorFactories, getLoginService, getParameter, getParameterNames, getRealmName, getSessionMaxInactiveIntervalOnAuthentication, handle, isAuthorized, isSessionRenewedOnAuthentication, redirectToSecure, setAuthenticationType, setAuthenticator, setAuthenticatorFactory, setIdentityService, setLoginService, setParameter, setRealmName, setSessionMaxInactiveIntervalOnAuthentication, setSessionRenewedOnAuthenticationMethods 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, 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
-
ANY_KNOWN_ROLE
- See Also:
-
ANY_ROLE
- See Also:
-
-
Constructor Details
-
ConstraintSecurityHandler
public ConstraintSecurityHandler()
-
-
Method Details
-
getConstraint
- Specified by:
getConstraintin classSecurityHandler
-
createConstraint
public static Constraint createConstraint(String name, jakarta.servlet.HttpConstraintElement element) Create a Constraint- Parameters:
name- the nameelement- the http constraint element- Returns:
- the created constraint
-
createConstraint
public static Constraint createConstraint(String name, String[] rolesAllowed, jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic permitOrDeny, jakarta.servlet.annotation.ServletSecurity.TransportGuarantee transport) Create Constraint- Parameters:
name- the namerolesAllowed- the list of allowed rolespermitOrDeny- the permission semantictransport- the transport guarantee- Returns:
- the created constraint
-
removeConstraintMappingsForPath
public static List<ConstraintMapping> removeConstraintMappingsForPath(String pathSpec, List<ConstraintMapping> constraintMappings) Take out of the constraint mappings those that match the given path.- Parameters:
pathSpec- the path specconstraintMappings- a new list minus the matching constraints- Returns:
- the list of constraint mappings
-
createConstraintsWithMappingsForPath
public static List<ConstraintMapping> createConstraintsWithMappingsForPath(String name, String pathSpec, jakarta.servlet.ServletSecurityElement securityElement) Generate Constraints and ConstraintMappings for the given url pattern and ServletSecurityElement- Parameters:
name- the namepathSpec- the path specsecurityElement- the servlet security element- Returns:
- the list of constraint mappings
-
getConstraintMappings
- Specified by:
getConstraintMappingsin interfaceConstraintAware
-
getKnownRoles
- Specified by:
getKnownRolesin interfaceConstraintAware- Overrides:
getKnownRolesin classSecurityHandler
-
setConstraintMappings
Process the constraints following the combining rules in Servlet 3.0 EA spec section 13.7.1 Note that much of the logic is in the Constraint class.- Parameters:
constraintMappings- The constraintMappings to set, from which the set of known roles is determined.
-
setConstraintMappings
Process the constraints following the combining rules in Servlet 3.0 EA spec section 13.7.1 Note that much of the logic is in the Constraint class.- Parameters:
constraintMappings- The constraintMappings to set as array, from which the set of known roles is determined. Needed to retain API compatibility for 7.x
-
setConstraintMappings
Process the constraints following the combining rules in Servlet 3.0 EA spec section 13.7.1 Note that much of the logic is in the Constraint class.- Specified by:
setConstraintMappingsin interfaceConstraintAware- Parameters:
constraintMappings- The constraintMappings to set.roles- The known roles (or null to determine them from the mappings)
-
setRoles
Set the known roles. This may be overridden by a subsequent call tosetConstraintMappings(ConstraintMapping[])orsetConstraintMappings(List, Set).- Parameters:
roles- The known roles (or null to determine them from the mappings)
-
addConstraintMapping
Description copied from interface:ConstraintAwareAdd a Constraint Mapping. May be called for running webapplication as an annotated servlet is instantiated.- Specified by:
addConstraintMappingin interfaceConstraintAware- Parameters:
mapping- the mapping
-
addKnownRole
Description copied from interface:ConstraintAwareAdd a Role definition. May be called on running webapplication as an annotated servlet is instantiated.- Specified by:
addKnownRolein interfaceConstraintAware- Parameters:
role- the role
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classSecurityHandler- 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 classSecurityHandler- Throws:
Exception- If there was a problem stopping. Will cause a transition to FAILED state
-
combineServletConstraints
Combine constrains as per the servlet specification. This is NOT equivalent to
Constraint.combine(Constraint, Constraint), which implements a more secure combination.- Parameters:
constraintA- A constraintconstraintB- B constraint- Returns:
- The combination as per the servlet specification.
-
processConstraintMapping
Create and combine the constraint with the existing processed constraints.- Parameters:
mapping- the constraint mapping
-
processConstraintMappingWithMethodOmissions
protected void processConstraintMappingWithMethodOmissions(ConstraintMapping mapping, Map<String, Constraint> mappings) Constraints that name method omissions are dealt with differently. We create an entry in the mappings with key "<method>.omission". This entry is only ever combined with other omissions for the same method to produce a consolidated Constraint. Then, when we wish to find the relevant constraints for a given Request (in prepareConstraintInfo()), we consult 3 types of entries in the mappings: an entry that names the method of the Request specifically, an entry that names constraints that apply to all methods, entries of the form <method>.omission, where the method of the Request is not named in the omission.- Parameters:
mapping- the constraint mappingmappings- the mappings of roles
-
dump
Description copied from interface:DumpableDump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- 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
-
setDenyUncoveredHttpMethods
public void setDenyUncoveredHttpMethods(boolean deny) Description copied from interface:ConstraintAwareSee Servlet Spec 31, sec 13.8.4, pg 145 When true, requests with http methods not explicitly covered either by inclusion or omissions in constraints, will have access denied.- Specified by:
setDenyUncoveredHttpMethodsin interfaceConstraintAware- Parameters:
deny- true for denied method access
-
isDenyUncoveredHttpMethods
public boolean isDenyUncoveredHttpMethods()- Specified by:
isDenyUncoveredHttpMethodsin interfaceConstraintAware
-
checkPathsWithUncoveredHttpMethods
public boolean checkPathsWithUncoveredHttpMethods()Servlet spec 3.1 pg. 147.- Specified by:
checkPathsWithUncoveredHttpMethodsin interfaceConstraintAware- Returns:
- true if urls with uncovered http methods
-
getPathsWithUncoveredHttpMethods
Servlet spec 3.1 pg. 147. The container must check all the combined security constraint information and log any methods that are not protected and the urls at which they are not protected- Returns:
- Set of paths for which there are uncovered methods
-
omissionsExist
Check if any http method omissions exist in the list of method to auth info mappings.- Parameters:
methodMappings- the method mappings- Returns:
- true if omission exist
-
getOmittedMethods
-