Class SecurityConstraint
- java.lang.Object
- 
- org.apache.tomcat.util.descriptor.web.XmlEncodingBase
- 
- org.apache.tomcat.util.descriptor.web.SecurityConstraint
 
 
- 
- All Implemented Interfaces:
- java.io.Serializable
 
 public class SecurityConstraint extends XmlEncodingBase implements java.io.Serializable Representation of a security constraint element for a web application, as represented in a<security-constraint>element in the deployment descriptor.WARNING: It is assumed that instances of this class will be created and modified only within the context of a single thread, before the instance is made visible to the remainder of the application. After that, only read access is expected. Therefore, none of the read and write access within this class is synchronized. - Author:
- Craig R. McClanahan
- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringROLE_ALL_AUTHENTICATED_USERSstatic java.lang.StringROLE_ALL_ROLES
 - 
Constructor SummaryConstructors Constructor Description SecurityConstraint()Construct a new security constraint instance with default values.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAuthRole(java.lang.String authRole)Add an authorization role, which is a role name that will be permitted access to the resources protected by this security constraint.voidaddCollection(SecurityCollection collection)Add a new web resource collection to those protected by this security constraint.static SecurityConstraint[]createConstraints(ServletSecurityElement element, java.lang.String urlPattern)Convert aServletSecurityElementto an array ofSecurityConstraint(s).booleanfindAuthRole(java.lang.String role)Check a role.java.lang.String[]findAuthRoles()Return the set of roles that are permitted access to the resources protected by this security constraint.SecurityCollectionfindCollection(java.lang.String name)Return the web resource collection for the specified name, if any; otherwise, returnnull.SecurityCollection[]findCollections()Return all of the web resource collections protected by this security constraint.static SecurityConstraint[]findUncoveredHttpMethods(SecurityConstraint[] constraints, boolean denyUncoveredHttpMethods, Log log)booleangetAllRoles()Was the "all roles" wildcard included in this authentication constraint?booleangetAuthConstraint()Return the authorization constraint present flag for this security constraint.booleangetAuthenticatedUsers()Was the "all authenticated users" wildcard included in this authentication constraint?java.lang.StringgetDisplayName()java.lang.StringgetUserConstraint()Return the user data constraint for this security constraint.booleanincluded(java.lang.String uri, java.lang.String method)Check if the constraint applies to a URI and method.voidremoveAuthRole(java.lang.String authRole)Remove the specified role from the set of roles permitted to access the resources protected by this security constraint.voidremoveCollection(SecurityCollection collection)Remove the specified web resource collection from those protected by this security constraint.voidsetAuthConstraint(boolean authConstraint)Set the authorization constraint present flag for this security constraint.voidsetCharset(java.nio.charset.Charset charset)voidsetDisplayName(java.lang.String displayName)Set the display name of this security constraint.voidsetUserConstraint(java.lang.String userConstraint)Set the user data constraint for this security constraint.java.lang.StringtoString()Return a String representation of this security constraint.voidtreatAllAuthenticatedUsersAsApplicationRole()Called in the unlikely event that an application defines a role named "**".- 
Methods inherited from class org.apache.tomcat.util.descriptor.web.XmlEncodingBasegetCharset, getEncoding, setEncoding
 
- 
 
- 
- 
- 
Field Detail- 
ROLE_ALL_ROLESpublic static final java.lang.String ROLE_ALL_ROLES - See Also:
- Constant Field Values
 
 - 
ROLE_ALL_AUTHENTICATED_USERSpublic static final java.lang.String ROLE_ALL_AUTHENTICATED_USERS - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getAllRolespublic boolean getAllRoles() Was the "all roles" wildcard included in this authentication constraint?- Returns:
- trueif all roles
 
 - 
getAuthenticatedUserspublic boolean getAuthenticatedUsers() Was the "all authenticated users" wildcard included in this authentication constraint?- Returns:
- trueif all authenticated users
 
 - 
getAuthConstraintpublic boolean getAuthConstraint() Return the authorization constraint present flag for this security constraint.- Returns:
- trueif this needs authorization
 
 - 
setAuthConstraintpublic void setAuthConstraint(boolean authConstraint) Set the authorization constraint present flag for this security constraint.- Parameters:
- authConstraint- The new value
 
 - 
getDisplayNamepublic java.lang.String getDisplayName() - Returns:
- the display name of this security constraint.
 
 - 
setDisplayNamepublic void setDisplayName(java.lang.String displayName) Set the display name of this security constraint.- Parameters:
- displayName- The new value
 
 - 
getUserConstraintpublic java.lang.String getUserConstraint() Return the user data constraint for this security constraint.- Returns:
- the user constraint
 
 - 
setUserConstraintpublic void setUserConstraint(java.lang.String userConstraint) Set the user data constraint for this security constraint.- Parameters:
- userConstraint- The new user data constraint
 
 - 
treatAllAuthenticatedUsersAsApplicationRolepublic void treatAllAuthenticatedUsersAsApplicationRole() Called in the unlikely event that an application defines a role named "**".
 - 
addAuthRolepublic void addAuthRole(java.lang.String authRole) Add an authorization role, which is a role name that will be permitted access to the resources protected by this security constraint.- Parameters:
- authRole- Role name to be added
 
 - 
setCharsetpublic void setCharset(java.nio.charset.Charset charset) - Overrides:
- setCharsetin class- XmlEncodingBase
 
 - 
addCollectionpublic void addCollection(SecurityCollection collection) Add a new web resource collection to those protected by this security constraint.- Parameters:
- collection- The new web resource collection
 
 - 
findAuthRolepublic boolean findAuthRole(java.lang.String role) Check a role.- Parameters:
- role- Role name to be checked
- Returns:
- trueif the specified role is permitted access to the resources protected by this security constraint.
 
 - 
findAuthRolespublic java.lang.String[] findAuthRoles() Return the set of roles that are permitted access to the resources protected by this security constraint. If none have been defined, a zero-length array is returned (which implies that all authenticated users are permitted access).- Returns:
- the roles array
 
 - 
findCollectionpublic SecurityCollection findCollection(java.lang.String name) Return the web resource collection for the specified name, if any; otherwise, returnnull.- Parameters:
- name- Web resource collection name to return
- Returns:
- the collection
 
 - 
findCollectionspublic SecurityCollection[] findCollections() Return all of the web resource collections protected by this security constraint. If there are none, a zero-length array is returned.- Returns:
- the collections array
 
 - 
includedpublic boolean included(java.lang.String uri, java.lang.String method)Check if the constraint applies to a URI and method.- Parameters:
- uri- Context-relative URI to check
- method- Request method being used
- Returns:
- trueif the specified context-relative URI (and associated HTTP method) are protected by this security constraint.
 
 - 
removeAuthRolepublic void removeAuthRole(java.lang.String authRole) Remove the specified role from the set of roles permitted to access the resources protected by this security constraint.- Parameters:
- authRole- Role name to be removed
 
 - 
removeCollectionpublic void removeCollection(SecurityCollection collection) Remove the specified web resource collection from those protected by this security constraint.- Parameters:
- collection- Web resource collection to be removed
 
 - 
toStringpublic java.lang.String toString() Return a String representation of this security constraint.- Overrides:
- toStringin class- java.lang.Object
 
 - 
createConstraintspublic static SecurityConstraint[] createConstraints(ServletSecurityElement element, java.lang.String urlPattern) Convert aServletSecurityElementto an array ofSecurityConstraint(s).- Parameters:
- element- The element to be converted
- urlPattern- The url pattern that the element should be applied to
- Returns:
- The (possibly zero length) array of constraints that are the equivalent to the input
 
 - 
findUncoveredHttpMethodspublic static SecurityConstraint[] findUncoveredHttpMethods(SecurityConstraint[] constraints, boolean denyUncoveredHttpMethods, Log log) 
 
- 
 
-