public class ConstraintSecurityHandler extends SecurityHandler implements ConstraintAware
Handler to enforce SecurityConstraints. This implementation is servlet spec 3.1 compliant and pre-computes the constraint combinations for runtime efficiency.
SecurityHandler.NotCheckedAbstractHandler.ErrorDispatchHandlerAbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.ListenerContainer.InheritedListener, Container.Listener| Modifier and Type | Field and Description |
|---|---|
private PathMap<java.util.Map<java.lang.String,RoleInfo>> |
_constraintMap |
private java.util.List<ConstraintMapping> |
_constraintMappings |
private boolean |
_denyUncoveredMethods |
private java.util.Set<java.lang.String> |
_roles |
private static java.lang.String |
ALL_METHODS |
private static Logger |
LOG |
private static java.lang.String |
OMISSION_SUFFIX |
__NO_USER, __NOBODY_handler| Constructor and Description |
|---|
ConstraintSecurityHandler() |
| Modifier and Type | Method and Description |
|---|---|
void |
addConstraintMapping(ConstraintMapping mapping)
Add a Constraint Mapping.
|
void |
addRole(java.lang.String role)
Add a Role definition.
|
boolean |
checkPathsWithUncoveredHttpMethods()
Servlet spec 3.1 pg.
|
protected boolean |
checkUserDataPermissions(java.lang.String pathInContext,
Request request,
Response response,
RoleInfo roleInfo) |
protected boolean |
checkWebResourcePermissions(java.lang.String pathInContext,
Request request,
Response response,
java.lang.Object constraintInfo,
UserIdentity userIdentity) |
protected void |
configureRoleInfo(RoleInfo ri,
ConstraintMapping mapping)
Initialize or update the RoleInfo from the constraint
|
static Constraint |
createConstraint() |
static Constraint |
createConstraint(Constraint constraint) |
static Constraint |
createConstraint(java.lang.String name,
boolean authenticate,
java.lang.String[] roles,
int dataConstraint)
Create a security constraint
|
static Constraint |
createConstraint(java.lang.String name,
javax.servlet.HttpConstraintElement element)
Create a Constraint
|
static Constraint |
createConstraint(java.lang.String name,
java.lang.String[] rolesAllowed,
javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic permitOrDeny,
javax.servlet.annotation.ServletSecurity.TransportGuarantee transport)
Create Constraint
|
static java.util.List<ConstraintMapping> |
createConstraintsWithMappingsForPath(java.lang.String name,
java.lang.String pathSpec,
javax.servlet.ServletSecurityElement securityElement)
Generate Constraints and ContraintMappings for the given url pattern and ServletSecurityElement
|
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
java.util.List<ConstraintMapping> |
getConstraintMappings() |
static java.util.List<ConstraintMapping> |
getConstraintMappingsForPath(java.lang.String pathSpec,
java.util.List<ConstraintMapping> constraintMappings) |
protected java.util.Set<java.lang.String> |
getOmittedMethods(java.lang.String omission)
Given a string of the form
<method>.<method>.omission
split out the individual method names. |
java.util.Set<java.lang.String> |
getPathsWithUncoveredHttpMethods()
Servlet spec 3.1 pg.
|
java.util.Set<java.lang.String> |
getRoles() |
protected boolean |
isAuthMandatory(Request baseRequest,
Response baseResponse,
java.lang.Object constraintInfo) |
boolean |
isDenyUncoveredHttpMethods() |
protected boolean |
omissionsExist(java.lang.String path,
java.util.Map<java.lang.String,RoleInfo> methodMappings)
Check if any http method omissions exist in the list of method
to auth info mappings.
|
protected RoleInfo |
prepareConstraintInfo(java.lang.String pathInContext,
Request request)
Find constraints that apply to the given path.
|
protected void |
processConstraintMapping(ConstraintMapping mapping)
Create and combine the constraint with the existing processed
constraints.
|
protected void |
processConstraintMappingWithMethodOmissions(ConstraintMapping mapping,
java.util.Map<java.lang.String,RoleInfo> mappings)
Constraints that name method omissions are dealt with differently.
|
static java.util.List<ConstraintMapping> |
removeConstraintMappingsForPath(java.lang.String pathSpec,
java.util.List<ConstraintMapping> constraintMappings)
Take out of the constraint mappings those that match the
given path.
|
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 RoleInfo class.
|
void |
setConstraintMappings(java.util.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 RoleInfo class.
|
void |
setConstraintMappings(java.util.List<ConstraintMapping> constraintMappings,
java.util.Set<java.lang.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 RoleInfo class.
|
void |
setDenyUncoveredHttpMethods(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.
|
void |
setRoles(java.util.Set<java.lang.String> roles)
Set the known roles.
|
checkSecurity, findIdentityService, findLoginService, getAuthenticator, getAuthenticatorFactory, getAuthMethod, getCurrentSecurityHandler, getIdentityService, getInitParameter, getInitParameterNames, getKnownAuthenticatorFactories, getLoginService, getRealmName, handle, isCheckWelcomeFiles, isSessionRenewedOnAuthentication, logout, setAuthenticator, setAuthenticatorFactory, setAuthMethod, setCheckWelcomeFiles, setIdentityService, setInitParameter, setLoginService, setRealmName, setSessionRenewedOnAuthenticationdestroy, expandChildren, getHandler, getHandlers, insertHandler, setHandlerdoShutdown, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServerdoError, getServeraddBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stopdumpContainer, dumpIterable, dumpMapEntries, dumpObjects, dumpSelf, namedprivate static final Logger LOG
private static final java.lang.String OMISSION_SUFFIX
private static final java.lang.String ALL_METHODS
private final java.util.List<ConstraintMapping> _constraintMappings
private final java.util.Set<java.lang.String> _roles
private boolean _denyUncoveredMethods
public static Constraint createConstraint()
public static Constraint createConstraint(Constraint constraint)
public static Constraint createConstraint(java.lang.String name, boolean authenticate, java.lang.String[] roles, int dataConstraint)
name - the name of the constraintauthenticate - true to authenticateroles - list of rolesdataConstraint - the data constraintpublic static Constraint createConstraint(java.lang.String name, javax.servlet.HttpConstraintElement element)
name - the nameelement - the http constraint elementpublic static Constraint createConstraint(java.lang.String name, java.lang.String[] rolesAllowed, javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic permitOrDeny, javax.servlet.annotation.ServletSecurity.TransportGuarantee transport)
name - the namerolesAllowed - the list of allowed rolespermitOrDeny - the permission semantictransport - the transport guaranteepublic static java.util.List<ConstraintMapping> getConstraintMappingsForPath(java.lang.String pathSpec, java.util.List<ConstraintMapping> constraintMappings)
public static java.util.List<ConstraintMapping> removeConstraintMappingsForPath(java.lang.String pathSpec, java.util.List<ConstraintMapping> constraintMappings)
pathSpec - the path specconstraintMappings - a new list minus the matching constraintspublic static java.util.List<ConstraintMapping> createConstraintsWithMappingsForPath(java.lang.String name, java.lang.String pathSpec, javax.servlet.ServletSecurityElement securityElement)
name - the namepathSpec - the path specsecurityElement - the servlet security elementpublic java.util.List<ConstraintMapping> getConstraintMappings()
getConstraintMappings in interface ConstraintAwarepublic java.util.Set<java.lang.String> getRoles()
getRoles in interface ConstraintAwarepublic void setConstraintMappings(java.util.List<ConstraintMapping> constraintMappings)
constraintMappings - The constraintMappings to set, from which the set of known roles
is determined.public void setConstraintMappings(ConstraintMapping[] constraintMappings)
constraintMappings - The constraintMappings to set as array, from which the set of known roles
is determined. Needed to retain API compatibility for 7.xpublic void setConstraintMappings(java.util.List<ConstraintMapping> constraintMappings, java.util.Set<java.lang.String> roles)
setConstraintMappings in interface ConstraintAwareconstraintMappings - The constraintMappings to set.roles - The known roles (or null to determine them from the mappings)public void setRoles(java.util.Set<java.lang.String> roles)
setConstraintMappings(ConstraintMapping[]) or
setConstraintMappings(List, Set).roles - The known roles (or null to determine them from the mappings)public void addConstraintMapping(ConstraintMapping mapping)
ConstraintAwareaddConstraintMapping in interface ConstraintAwaremapping - the mappingConstraintAware.addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping)public void addRole(java.lang.String role)
ConstraintAwareaddRole in interface ConstraintAwarerole - the roleConstraintAware.addRole(java.lang.String)protected void doStart()
throws java.lang.Exception
ContainerLifeCycledoStart in class SecurityHandlerjava.lang.ExceptionSecurityHandler.doStart()protected void doStop()
throws java.lang.Exception
ContainerLifeCycledoStop in class SecurityHandlerjava.lang.Exceptionprotected void processConstraintMapping(ConstraintMapping mapping)
mapping - the constraint mappingprotected void processConstraintMappingWithMethodOmissions(ConstraintMapping mapping, java.util.Map<java.lang.String,RoleInfo> mappings)
mapping - the constraint mappingmappings - the mappings of rolesprotected void configureRoleInfo(RoleInfo ri, ConstraintMapping mapping)
ri - the role infomapping - the constraint mappingprotected RoleInfo prepareConstraintInfo(java.lang.String pathInContext, Request request)
prepareConstraintInfo in class SecurityHandlerSecurityHandler.prepareConstraintInfo(java.lang.String, org.eclipse.jetty.server.Request)protected boolean checkUserDataPermissions(java.lang.String pathInContext,
Request request,
Response response,
RoleInfo roleInfo)
throws java.io.IOException
checkUserDataPermissions in class SecurityHandlerjava.io.IOExceptionprotected boolean isAuthMandatory(Request baseRequest, Response baseResponse, java.lang.Object constraintInfo)
isAuthMandatory in class SecurityHandlerprotected boolean checkWebResourcePermissions(java.lang.String pathInContext,
Request request,
Response response,
java.lang.Object constraintInfo,
UserIdentity userIdentity)
throws java.io.IOException
checkWebResourcePermissions in class SecurityHandlerjava.io.IOExceptionSecurityHandler.checkWebResourcePermissions(java.lang.String, org.eclipse.jetty.server.Request, org.eclipse.jetty.server.Response, java.lang.Object, org.eclipse.jetty.server.UserIdentity)public void dump(java.lang.Appendable out,
java.lang.String indent)
throws java.io.IOException
Dumpabledump in interface Dumpabledump in class ContainerLifeCycleout - The appendable to dump toindent - The indent to apply after any new lines.java.io.IOException - if unable to write to Appendablepublic void setDenyUncoveredHttpMethods(boolean deny)
ConstraintAwaresetDenyUncoveredHttpMethods in interface ConstraintAwaredeny - true for denied method accessConstraintAware.setDenyUncoveredHttpMethods(boolean)public boolean isDenyUncoveredHttpMethods()
isDenyUncoveredHttpMethods in interface ConstraintAwarepublic boolean checkPathsWithUncoveredHttpMethods()
checkPathsWithUncoveredHttpMethods in interface ConstraintAwarepublic java.util.Set<java.lang.String> getPathsWithUncoveredHttpMethods()
protected boolean omissionsExist(java.lang.String path,
java.util.Map<java.lang.String,RoleInfo> methodMappings)
path - the pathmethodMappings - the method mappingsprotected java.util.Set<java.lang.String> getOmittedMethods(java.lang.String omission)
<method>.<method>.omission
split out the individual method names.omission - the method