Top Description Fields Constructors Methods
org.eclipse.jetty.ee10.servlet.security

public Class ConstraintSecurityHandler

extends SecurityHandler
implements ConstraintAware
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.ee10.servlet.security.ConstraintAware
Imports
java.io.IOException, java.util.ArrayList, .Arrays, .Collections, .HashMap, .HashSet, .List, .Map, .Set, java.util.concurrent.CopyOnWriteArrayList, .CopyOnWriteArraySet, java.util.stream.Collectors, .Stream, jakarta.servlet.HttpConstraintElement, .HttpMethodConstraintElement, .ServletSecurityElement, jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic, .ServletSecurity.TransportGuarantee, org.eclipse.jetty.ee10.servlet.ServletContextHandler, org.eclipse.jetty.http.pathmap.MappedResource, .MatchedResource, .PathMappings, .PathSpec, org.eclipse.jetty.security.Constraint, .Constraint.Transport, .SecurityHandler, org.eclipse.jetty.server.Request, .Server, org.eclipse.jetty.server.handler.ContextHandler, org.eclipse.jetty.util.component.DumpableCollection, org.slf4j.Logger, .LoggerFactory

ConstraintSecurityHandler

Handler to enforce SecurityConstraints. This implementation is servlet spec 3.1 compliant and pre-computes the constraint combinations for runtime efficiency.

Field Summary

Modifier and TypeField and Description
private final List<ConstraintMapping>
private final PathMappings<Map<String, Constraint>>
private boolean
private final List<ConstraintMapping>
private final Set<String>
private static final String
public static final String
public static final String
private static final Logger
private static final String
Inherited from org.eclipse.jetty.security.SecurityHandler:
SESSION_AUTHENTICATED_ATTRIBUTE

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public boolean
protected Constraint

Returns:

The combination as per the servlet specification.
combineServletConstraints
(Constraint
A constraint
constraintA
,
Constraint
B constraint
constraintB
)

Combine constrains as per the servlet specification.

public static Constraint

Returns:

the created constraint
createConstraint
(String
the name
name
,
HttpConstraintElement
the http constraint element
element
)

Create a Constraint

public static Constraint

Returns:

the created constraint
createConstraint
(String
the name
name
,
String[]
the list of allowed roles
rolesAllowed
,
ServletSecurity.EmptyRoleSemantic
the permission semantic
permitOrDeny
,
ServletSecurity.TransportGuarantee
the transport guarantee
transport
)

Create Constraint

public static List<ConstraintMapping>

Returns:

the list of constraint mappings
createConstraintsWithMappingsForPath
(String
the name
name
,
String
the path spec
pathSpec
,
ServletSecurityElement
the servlet security element
securityElement
)

Generate Constraints and ConstraintMappings for the given url pattern and ServletSecurityElement

protected void
doStart()

Overrides org.eclipse.jetty.security.SecurityHandler.doStart.

Starts the managed lifecycle beans in the order they were added.
protected void
doStop()

Overrides org.eclipse.jetty.security.SecurityHandler.doStop.

Stops the managed lifecycle beans in the reverse order they were added.
public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.
protected Constraint
public List<ConstraintMapping>
public Set<String>
protected Set<String>

Returns:

the set of strings
getOmittedMethods
(String
the method
omission
)

Given a string of the form <method>.

public Set<String>

Returns:

Set of paths for which there are uncovered methods
getPathsWithUncoveredHttpMethods
()

Servlet spec 3.1 pg.

public boolean
private boolean

Returns:

true if the context with which this ConstraintSecurityHandler has not yet started, or if there is no context, the server has not yet started.
isInDurableState
()

Constraints can be added to the ConstraintSecurityHandler before the associated context is started.

protected boolean

Returns:

true if omission exist
omissionsExist
(Map<String, Constraint>
the method mappings
methodMappings
)

Check if any http method omissions exist in the list of method to auth info mappings.

protected void
processConstraintMapping(ConstraintMapping
the constraint mapping
mapping
)

Create and combine the constraint with the existing processed constraints.

protected void
processConstraintMappingWithMethodOmissions(ConstraintMapping
the constraint mapping
mapping
,
Map<String, Constraint>
the mappings of roles
mappings
)

Constraints that name method omissions are dealt with differently.

public static List<ConstraintMapping>

Returns:

the list of constraint mappings
removeConstraintMappingsForPath
(String
the path spec
pathSpec
,
List<ConstraintMapping>
a new list minus the matching constraints
constraintMappings
)

Take out of the constraint mappings those that match the given path.

public void
setConstraintMappings(List<ConstraintMapping>
The constraintMappings to set, from which the set of known roles is determined.
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.

public void
setConstraintMappings(ConstraintMapping[]
The constraintMappings to set as array, from which the set of known roles is determined. Needed to retain API compatibility for 7.x
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.

public void
setConstraintMappings(List<ConstraintMapping>
The constraintMappings to set.
constraintMappings
,
Set<String>
The known roles (or null to determine them from the mappings)
roles
)

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.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.
public void
setDenyUncoveredHttpMethods(boolean
true for denied method access
deny
)

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.setDenyUncoveredHttpMethods.

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.
public void
setRoles(Set<String>
The known roles (or null to determine them from the mappings)
roles
)

Set the known roles.

Inherited from org.eclipse.jetty.security.SecurityHandler:
findIdentityServicefindLoginServicegetAuthenticationTypegetAuthenticatorgetAuthenticatorFactorygetCurrentSecurityHandlergetIdentityServicegetKnownAuthenticatorFactoriesgetLoginServicegetParametergetParameterNamesgetRealmNamegetSessionMaxInactiveIntervalOnAuthenticationhandleisAuthorizedisSessionRenewedOnAuthenticationredirectToSecuresetAuthenticationTypesetAuthenticatorsetAuthenticatorFactorysetIdentityServicesetLoginServicesetParametersetRealmNamesetSessionMaxInactiveIntervalOnAuthenticationsetSessionRenewedOnAuthentication

Field Detail

_constraintMappingsback to summary
private final List<ConstraintMapping> _constraintMappings
_constraintsByPathAndMethodback to summary
private final PathMappings<Map<String, Constraint>> _constraintsByPathAndMethod
_denyUncoveredMethodsback to summary
private boolean _denyUncoveredMethods
_durableConstraintMappingsback to summary
private final List<ConstraintMapping> _durableConstraintMappings
_rolesback to summary
private final Set<String> _roles
ALL_METHODSback to summary
private static final String ALL_METHODS
ANY_KNOWN_ROLEback to summary
public static final String ANY_KNOWN_ROLE
ANY_ROLEback to summary
public static final String ANY_ROLE
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.security.SecurityHandler.LOG.

OMISSION_SUFFIXback to summary
private static final String OMISSION_SUFFIX

Constructor Detail

ConstraintSecurityHandlerback to summary
public ConstraintSecurityHandler()

Method Detail

addConstraintMappingback to summary
public void addConstraintMapping(ConstraintMapping mapping)

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.addConstraintMapping.

Doc from org.eclipse.jetty.ee10.servlet.security.ConstraintAware.addConstraintMapping.

Add a Constraint Mapping. May be called for running webapplication as an annotated servlet is instantiated.

Parameters
mapping:ConstraintMapping

the mapping

Annotations
@Override
addKnownRoleback to summary
public void addKnownRole(String role)

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.addKnownRole.

Doc from org.eclipse.jetty.ee10.servlet.security.ConstraintAware.addKnownRole.

Add a Role definition. May be called on running webapplication as an annotated servlet is instantiated.

Parameters
role:String

the role

Annotations
@Override
checkPathsWithUncoveredHttpMethodsback to summary
public boolean checkPathsWithUncoveredHttpMethods()

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.checkPathsWithUncoveredHttpMethods.

Servlet spec 3.1 pg. 147.

Returns:boolean

Doc from org.eclipse.jetty.ee10.servlet.security.ConstraintAware.checkPathsWithUncoveredHttpMethods.

true if urls with uncovered http methods

Annotations
@Override
combineServletConstraintsback to summary
protected Constraint combineServletConstraints(Constraint constraintA, Constraint constraintB)

Combine constrains as per the servlet specification. This is NOT equivalent to Constraint#combine(Constraint, Constraint), which implements a more secure combination.

Parameters
constraintA:Constraint

A constraint

constraintB:Constraint

B constraint

Returns:Constraint

The combination as per the servlet specification.

createConstraintback to summary
public static Constraint createConstraint(String name, HttpConstraintElement element)

Create a Constraint

Parameters
name:String

the name

element:HttpConstraintElement

the http constraint element

Returns:Constraint

the created constraint

createConstraintback to summary
public static Constraint createConstraint(String name, String[] rolesAllowed, ServletSecurity.EmptyRoleSemantic permitOrDeny, ServletSecurity.TransportGuarantee transport)

Create Constraint

Parameters
name:String

the name

rolesAllowed:String[]

the list of allowed roles

permitOrDeny:ServletSecurity.EmptyRoleSemantic

the permission semantic

transport:ServletSecurity.TransportGuarantee

the transport guarantee

Returns:Constraint

the created constraint

createConstraintsWithMappingsForPathback to summary
public static List<ConstraintMapping> createConstraintsWithMappingsForPath(String name, String pathSpec, ServletSecurityElement securityElement)

Generate Constraints and ConstraintMappings for the given url pattern and ServletSecurityElement

Parameters
name:String

the name

pathSpec:String

the path spec

securityElement:ServletSecurityElement

the servlet security element

Returns:List<ConstraintMapping>

the list of constraint mappings

doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.security.SecurityHandler.doStart.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.security.SecurityHandler.doStop.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

If there was a problem stopping. Will cause a transition to FAILED state

dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

Dump 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.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
getConstraintback to summary
protected Constraint getConstraint(String pathInContext, Request request)

Implements abstract org.eclipse.jetty.security.SecurityHandler.getConstraint.

Annotations
@Override
getConstraintMappingsback to summary
public List<ConstraintMapping> getConstraintMappings()

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.getConstraintMappings.

Annotations
@Override
getKnownRolesback to summary
public Set<String> getKnownRoles()

Overrides org.eclipse.jetty.security.SecurityHandler.getKnownRoles.

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.getKnownRoles.

Annotations
@Override
getOmittedMethodsback to summary
protected Set<String> getOmittedMethods(String omission)

Given a string of the form <method>.<method>.omission split out the individual method names.

Parameters
omission:String

the method

Returns:Set<String>

the set of strings

getPathsWithUncoveredHttpMethodsback to summary
public Set<String> 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<String>

Set of paths for which there are uncovered methods

isDenyUncoveredHttpMethodsback to summary
public boolean isDenyUncoveredHttpMethods()

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.isDenyUncoveredHttpMethods.

Annotations
@Override
isInDurableStateback to summary
private boolean isInDurableState()

Constraints can be added to the ConstraintSecurityHandler before the associated context is started. These constraints should persist across a stop/start. Others can be added after the associated context is starting (eg by a web.xml/web-fragment.xml, annotation or jakarta.servlet api call) - these should not be persisted across a stop/start as they will be re-added on the restart.

Returns:boolean

true if the context with which this ConstraintSecurityHandler has not yet started, or if there is no context, the server has not yet started.

omissionsExistback to summary
protected boolean omissionsExist(Map<String, Constraint> methodMappings)

Check if any http method omissions exist in the list of method to auth info mappings.

Parameters
methodMappings:Map<String, Constraint>

the method mappings

Returns:boolean

true if omission exist

processConstraintMappingback to summary
protected void processConstraintMapping(ConstraintMapping mapping)

Create and combine the constraint with the existing processed constraints.

Parameters
mapping:ConstraintMapping

the constraint mapping

processConstraintMappingWithMethodOmissionsback to summary
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:ConstraintMapping

the constraint mapping

mappings:Map<String, Constraint>

the mappings of roles

removeConstraintMappingsForPathback to summary
public static List<ConstraintMapping> removeConstraintMappingsForPath(String pathSpec, List<ConstraintMapping> constraintMappings)

Take out of the constraint mappings those that match the given path.

Parameters
pathSpec:String

the path spec

constraintMappings:List<ConstraintMapping>

a new list minus the matching constraints

Returns:List<ConstraintMapping>

the list of constraint mappings

setConstraintMappingsback to summary
public void setConstraintMappings(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.

Parameters
constraintMappings:List<ConstraintMapping>

The constraintMappings to set, from which the set of known roles is determined.

setConstraintMappingsback to summary
public void setConstraintMappings(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.

Parameters
constraintMappings:ConstraintMapping[]

The constraintMappings to set as array, from which the set of known roles is determined. Needed to retain API compatibility for 7.x

setConstraintMappingsback to summary
public void setConstraintMappings(List<ConstraintMapping> constraintMappings, Set<String> roles)

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.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:List<ConstraintMapping>

The constraintMappings to set.

roles:Set<String>

The known roles (or null to determine them from the mappings)

Annotations
@Override
setDenyUncoveredHttpMethodsback to summary
public void setDenyUncoveredHttpMethods(boolean deny)

Implements org.eclipse.jetty.ee10.servlet.security.ConstraintAware.setDenyUncoveredHttpMethods.

Doc from org.eclipse.jetty.ee10.servlet.security.ConstraintAware.setDenyUncoveredHttpMethods.

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.

Parameters
deny:boolean

true for denied method access

Annotations
@Override
setRolesback to summary
public void setRoles(Set<String> roles)

Set the known roles. This may be overridden by a subsequent call to setConstraintMappings(ConstraintMapping[]) or setConstraintMappings(List, Set).

Parameters
roles:Set<String>

The known roles (or null to determine them from the mappings)