Handler to enforce SecurityConstraints. This implementation is servlet spec 3.1 compliant and pre-computes the constraint combinations for runtime efficiency.
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private final PathMappings | |
| private boolean | |
| private final List | |
| private final Set | |
| private static final String | |
| public static final String | |
| public static final String | |
| private static final Logger | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addConstraintMapping(ConstraintMapping
the mapping mapping)Implements org. |
| public void | addKnownRole(String
the role role)Implements org. |
| public boolean | checkPathsWithUncoveredHttpMethods()
Implements org. |
| protected Constraint | Returns: The combination as per the servlet specification.A constraint constraintA, Constraint B constraint constraintB)Combine constrains as per the servlet specification. |
| public static Constraint | Returns: the created constraintthe name name, HttpConstraintElement the http constraint element element)Create a Constraint |
| public static Constraint | Returns: the created constraintthe name name, String[] the list of allowed roles rolesAllowed, ServletSecurity.the permission semantic permitOrDeny,the transport guarantee transportCreate Constraint |
| public static List | Returns: the list of constraint mappingsthe 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. |
| protected void | doStop()
Overrides org. |
| public void | dump(Appendable
The appendable to dump to out, String The indent to apply after any new lines. indent)Overrides org. Implements org. |
| protected Constraint | getConstraint(String pathInContext, Request request)
Implements abstract org. |
| public List | |
| public Set | |
| protected Set | Returns: the set of stringsthe method omission)Given a string of the form |
| public Set | Returns: Set of paths for which there are uncovered methodsServlet 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.Constraints can be added to the ConstraintSecurityHandler before the associated context is started. |
| protected boolean | Returns: true if omission existthe 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 | Returns: the list of constraint mappingsthe 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. |
| public void | setDenyUncoveredHttpMethods(boolean
true for denied method access deny)Implements org. |
| public void |
| _constraintMappings | back to summary |
|---|---|
| private final List<ConstraintMapping> _constraintMappings | |
| _constraintsByPathAndMethod | back to summary |
|---|---|
| private final PathMappings<Map<String, Constraint>> _constraintsByPathAndMethod | |
| _denyUncoveredMethods | back to summary |
|---|---|
| private boolean _denyUncoveredMethods | |
| _durableConstraintMappings | back to summary |
|---|---|
| private final List<ConstraintMapping> _durableConstraintMappings | |
| _roles | back to summary |
|---|---|
| private final Set<String> _roles | |
| ALL_METHODS | back to summary |
|---|---|
| private static final String ALL_METHODS | |
| ANY_KNOWN_ROLE | back to summary |
|---|---|
| public static final String ANY_KNOWN_ROLE | |
| ANY_ROLE | back to summary |
|---|---|
| public static final String ANY_ROLE | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| OMISSION_SUFFIX | back to summary |
|---|---|
| private static final String OMISSION_SUFFIX | |
| ConstraintSecurityHandler | back to summary |
|---|---|
| public ConstraintSecurityHandler() | |
| addConstraintMapping | back to summary |
|---|---|
| public void addConstraintMapping(ConstraintMapping mapping) Implements org. Doc from org. Add a Constraint Mapping. May be called for running webapplication as an annotated servlet is instantiated.
| |
| addKnownRole | back to summary |
|---|---|
| public void addKnownRole(String role) Implements org. Doc from org. Add a Role definition. May be called on running webapplication as an annotated servlet is instantiated. | |
| checkPathsWithUncoveredHttpMethods | back to summary |
|---|---|
| public boolean checkPathsWithUncoveredHttpMethods() Implements org. Servlet spec 3.1 pg. 147.
| |
| combineServletConstraints | back to summary |
|---|---|
| protected Constraint combineServletConstraints(Constraint constraintA, Constraint constraintB) Combine constrains as per the servlet specification.
This is NOT equivalent to
| |
| createConstraint | back to summary |
|---|---|
| public static Constraint createConstraint(String name, HttpConstraintElement element) Create a Constraint
| |
| createConstraint | back to summary |
|---|---|
| public static Constraint createConstraint(String name, String[] rolesAllowed, ServletSecurity. Create Constraint
| |
| createConstraintsWithMappingsForPath | back to summary |
|---|---|
| public static List Generate Constraints and ConstraintMappings for the given url pattern and ServletSecurityElement
| |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception Overrides org. Doc from org. Starts the managed lifecycle beans in the order they were added.
| |
| doStop | back to summary |
|---|---|
| protected void doStop() throws Exception Overrides org. Doc from org. Stops the managed lifecycle beans in the reverse order they were added.
| |
| dump | back to summary |
|---|---|
| public void dump(Appendable out, String indent) throws IOException Overrides org. Implements org. Doc from org. 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.
| |
| getConstraint | back to summary |
|---|---|
| protected Constraint getConstraint(String pathInContext, Request request) Implements abstract org.
| |
| getConstraintMappings | back to summary |
|---|---|
| public List Implements org.
| |
| getKnownRoles | back to summary |
|---|---|
| public Set Overrides org. Implements org.
| |
| getOmittedMethods | back to summary |
|---|---|
| protected Set Given a string of the form | |
| getPathsWithUncoveredHttpMethods | back to summary |
|---|---|
| public Set 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 | |
| isDenyUncoveredHttpMethods | back to summary |
|---|---|
| public boolean isDenyUncoveredHttpMethods() Implements org.
| |
| isInDurableState | back 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.
| |
| omissionsExist | back 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.
| |
| processConstraintMapping | back to summary |
|---|---|
| protected void processConstraintMapping(ConstraintMapping mapping) Create and combine the constraint with the existing processed constraints.
| |
| processConstraintMappingWithMethodOmissions | back 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.
| |
| removeConstraintMappingsForPath | back to summary |
|---|---|
| public static List Take out of the constraint mappings those that match the given path.
| |
| setConstraintMappings | back 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.
| |
| setConstraintMappings | back 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.
| |
| setConstraintMappings | back to summary |
|---|---|
| public void setConstraintMappings(List<ConstraintMapping> constraintMappings, Set<String> roles) Implements org. 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.
| |
| setDenyUncoveredHttpMethods | back to summary |
|---|---|
| public void setDenyUncoveredHttpMethods(boolean deny) Implements org. Doc from org. 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.
| |
| setRoles | back to summary |
|---|---|
| public void setRoles(Set<String> roles) Set the known roles.
This may be overridden by a subsequent call to | |