Module org.eclipse.jetty.security
Package org.eclipse.jetty.security
Class ConstraintSecurityHandler
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.server.handler.AbstractHandler
-
- org.eclipse.jetty.server.handler.AbstractHandlerContainer
-
- org.eclipse.jetty.server.handler.HandlerWrapper
-
- org.eclipse.jetty.security.SecurityHandler
-
- org.eclipse.jetty.security.ConstraintSecurityHandler
-
- All Implemented Interfaces:
Authenticator.AuthConfiguration,ConstraintAware,org.eclipse.jetty.server.Handler,org.eclipse.jetty.server.HandlerContainer,org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.LifeCycle
public class ConstraintSecurityHandler extends SecurityHandler implements ConstraintAware
ConstraintSecurityHandlerHandler 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 org.eclipse.jetty.security.SecurityHandler
SecurityHandler.NotChecked
-
Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.AbstractHandler
org.eclipse.jetty.server.handler.AbstractHandler.ErrorDispatchHandler
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
-
Field Summary
-
Fields inherited from class org.eclipse.jetty.security.SecurityHandler
__NO_USER, __NOBODY
-
-
Constructor Summary
Constructors Constructor Description ConstraintSecurityHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConstraintMapping(ConstraintMapping mapping)Add a Constraint Mapping.voidaddRole(java.lang.String role)Add a Role definition.booleancheckPathsWithUncoveredHttpMethods()Servlet spec 3.1 pg.protected booleancheckUserDataPermissions(java.lang.String pathInContext, org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, RoleInfo roleInfo)protected booleancheckWebResourcePermissions(java.lang.String pathInContext, org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, java.lang.Object constraintInfo, org.eclipse.jetty.server.UserIdentity userIdentity)protected voidconfigureRoleInfo(RoleInfo ri, ConstraintMapping mapping)Initialize or update the RoleInfo from the constraintstatic org.eclipse.jetty.util.security.ConstraintcreateConstraint()static org.eclipse.jetty.util.security.ConstraintcreateConstraint(java.lang.String name, boolean authenticate, java.lang.String[] roles, int dataConstraint)Create a security constraintstatic org.eclipse.jetty.util.security.ConstraintcreateConstraint(java.lang.String name, java.lang.String[] rolesAllowed, javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic permitOrDeny, javax.servlet.annotation.ServletSecurity.TransportGuarantee transport)Create Constraintstatic org.eclipse.jetty.util.security.ConstraintcreateConstraint(java.lang.String name, javax.servlet.HttpConstraintElement element)Create a Constraintstatic org.eclipse.jetty.util.security.ConstraintcreateConstraint(org.eclipse.jetty.util.security.Constraint 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 ServletSecurityElementprotected voiddoStart()protected voiddoStop()voiddump(java.lang.Appendable out, java.lang.String indent)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>.omissionsplit 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 booleanisAuthMandatory(org.eclipse.jetty.server.Request baseRequest, org.eclipse.jetty.server.Response baseResponse, java.lang.Object constraintInfo)booleanisDenyUncoveredHttpMethods()protected booleanomissionsExist(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 RoleInfoprepareConstraintInfo(java.lang.String pathInContext, org.eclipse.jetty.server.Request request)Find constraints that apply to the given path.protected voidprocessConstraintMapping(ConstraintMapping mapping)Create and combine the constraint with the existing processed constraints.protected voidprocessConstraintMappingWithMethodOmissions(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.voidsetConstraintMappings(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.voidsetConstraintMappings(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.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 RoleInfo 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.voidsetRoles(java.util.Set<java.lang.String> roles)Set the known roles.-
Methods inherited from class org.eclipse.jetty.security.SecurityHandler
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, setSessionRenewedOnAuthentication
-
Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
-
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
createConstraint
public static org.eclipse.jetty.util.security.Constraint createConstraint()
-
createConstraint
public static org.eclipse.jetty.util.security.Constraint createConstraint(org.eclipse.jetty.util.security.Constraint constraint)
-
createConstraint
public static org.eclipse.jetty.util.security.Constraint createConstraint(java.lang.String name, boolean authenticate, java.lang.String[] roles, int dataConstraint)Create a security constraint- Parameters:
name- the name of the constraintauthenticate- true to authenticateroles- list of rolesdataConstraint- the data constraint- Returns:
- the constraint
-
createConstraint
public static org.eclipse.jetty.util.security.Constraint createConstraint(java.lang.String name, javax.servlet.HttpConstraintElement element)Create a Constraint- Parameters:
name- the nameelement- the http constraint element- Returns:
- the created constraint
-
createConstraint
public static org.eclipse.jetty.util.security.Constraint createConstraint(java.lang.String name, java.lang.String[] rolesAllowed, javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic permitOrDeny, javax.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
-
getConstraintMappingsForPath
public static java.util.List<ConstraintMapping> getConstraintMappingsForPath(java.lang.String pathSpec, java.util.List<ConstraintMapping> constraintMappings)
-
removeConstraintMappingsForPath
public 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.- Parameters:
pathSpec- the path specconstraintMappings- a new list minus the matching constraints- Returns:
- the list of constraint mappings
-
createConstraintsWithMappingsForPath
public 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- Parameters:
name- the namepathSpec- the path specsecurityElement- the servlet security element- Returns:
- the list of constraint mappings
-
getConstraintMappings
public java.util.List<ConstraintMapping> getConstraintMappings()
- Specified by:
getConstraintMappingsin interfaceConstraintAware- Returns:
- Returns the constraintMappings.
-
getRoles
public java.util.Set<java.lang.String> getRoles()
- Specified by:
getRolesin interfaceConstraintAware
-
setConstraintMappings
public 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.- Parameters:
constraintMappings- The constraintMappings to set, from which the set of known roles is determined.
-
setConstraintMappings
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 RoleInfo 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
public 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.- Specified by:
setConstraintMappingsin interfaceConstraintAware- Parameters:
constraintMappings- The constraintMappings to set.roles- The known roles (or null to determine them from the mappings)
-
setRoles
public void setRoles(java.util.Set<java.lang.String> roles)
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
public void addConstraintMapping(ConstraintMapping mapping)
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
-
addRole
public void addRole(java.lang.String role)
Description copied from interface:ConstraintAwareAdd a Role definition. May be called on running webapplication as an annotated servlet is instantiated.- Specified by:
addRolein interfaceConstraintAware- Parameters:
role- the role
-
doStart
protected void doStart() throws java.lang.Exception- Overrides:
doStartin classSecurityHandler- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception- Overrides:
doStopin classSecurityHandler- Throws:
java.lang.Exception
-
processConstraintMapping
protected void processConstraintMapping(ConstraintMapping mapping)
Create and combine the constraint with the existing processed constraints.- Parameters:
mapping- the constraint mapping
-
processConstraintMappingWithMethodOmissions
protected void processConstraintMappingWithMethodOmissions(ConstraintMapping mapping, java.util.Map<java.lang.String,RoleInfo> 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 RoleInfo. 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
-
configureRoleInfo
protected void configureRoleInfo(RoleInfo ri, ConstraintMapping mapping)
Initialize or update the RoleInfo from the constraint- Parameters:
ri- the role infomapping- the constraint mapping
-
prepareConstraintInfo
protected RoleInfo prepareConstraintInfo(java.lang.String pathInContext, org.eclipse.jetty.server.Request request)
Find constraints that apply to the given path. In order to do this, we consult 3 different types of information stored in the mappings for each path - each mapping represents a merged set of user data constraints, roles etc -:- A mapping of an exact method name
- A mapping with key * that matches every method name
- Mappings with keys of the form "<method>.<method>.<method>.omission" that indicates it will match every method name EXCEPT those given
- Specified by:
prepareConstraintInfoin classSecurityHandler- See Also:
SecurityHandler.prepareConstraintInfo(java.lang.String, org.eclipse.jetty.server.Request)
-
checkUserDataPermissions
protected boolean checkUserDataPermissions(java.lang.String pathInContext, org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, RoleInfo roleInfo) throws java.io.IOException- Specified by:
checkUserDataPermissionsin classSecurityHandler- Throws:
java.io.IOException
-
isAuthMandatory
protected boolean isAuthMandatory(org.eclipse.jetty.server.Request baseRequest, org.eclipse.jetty.server.Response baseResponse, java.lang.Object constraintInfo)- Specified by:
isAuthMandatoryin classSecurityHandler
-
checkWebResourcePermissions
protected boolean checkWebResourcePermissions(java.lang.String pathInContext, org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, java.lang.Object constraintInfo, org.eclipse.jetty.server.UserIdentity userIdentity) throws java.io.IOException- Specified by:
checkWebResourcePermissionsin classSecurityHandler- Throws:
java.io.IOException
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.io.IOException
-
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
public java.util.Set<java.lang.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:
- list of paths for which there are uncovered methods
-
omissionsExist
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.- Parameters:
path- the pathmethodMappings- the method mappings- Returns:
- true if omission exist
-
getOmittedMethods
protected java.util.Set<java.lang.String> getOmittedMethods(java.lang.String omission)
Given a string of the form<method>.<method>.omissionsplit out the individual method names.- Parameters:
omission- the method- Returns:
- the list of strings
-
-