Class SecurityExpressionRoot
- java.lang.Object
- 
- org.springframework.security.access.expression.SecurityExpressionRoot
 
- 
- All Implemented Interfaces:
- SecurityExpressionOperations
 - Direct Known Subclasses:
- MessageSecurityExpressionRoot,- WebSecurityExpressionRoot
 
 public abstract class SecurityExpressionRoot extends java.lang.Object implements SecurityExpressionOperations Base root object for use in Spring Security expression evaluations.- Since:
- 3.0
 
- 
- 
Field SummaryFields Modifier and Type Field Description java.lang.Stringadminprotected Authenticationauthenticationjava.lang.Stringcreatejava.lang.StringdeletebooleandenyAllAllows "denyAll" expressionbooleanpermitAllAllows "permitAll" expressionjava.lang.Stringreadjava.lang.Stringwrite
 - 
Constructor SummaryConstructors Constructor Description SecurityExpressionRoot(Authentication authentication)Creates a new instance
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandenyAll()Always denies accessAuthenticationgetAuthentication()Gets theAuthenticationused for evaluating the expressionsjava.lang.ObjectgetPrincipal()Convenience method to accessAuthentication.getPrincipal()fromgetAuthentication()booleanhasAnyAuthority(java.lang.String... authorities)Determines if theSecurityExpressionOperations.getAuthentication()has any of the specified authorities withinAuthentication.getAuthorities().booleanhasAnyRole(java.lang.String... roles)Determines if theSecurityExpressionOperations.getAuthentication()has any of the specified authorities withinAuthentication.getAuthorities().booleanhasAuthority(java.lang.String authority)Determines if theSecurityExpressionOperations.getAuthentication()has a particular authority withinAuthentication.getAuthorities().booleanhasPermission(java.lang.Object target, java.lang.Object permission)Determines if theSecurityExpressionOperations.getAuthentication()has permission to access the target given the permissionbooleanhasPermission(java.lang.Object targetId, java.lang.String targetType, java.lang.Object permission)Determines if theSecurityExpressionOperations.getAuthentication()has permission to access the domain object with a given id, type, and permission.booleanhasRole(java.lang.String role)Determines if theSecurityExpressionOperations.getAuthentication()has a particular authority withinAuthentication.getAuthorities().booleanisAnonymous()Determines if theSecurityExpressionOperations.getAuthentication()is anonymousbooleanisAuthenticated()Determines iftheSecurityExpressionOperations.getAuthentication()is authenticatedbooleanisFullyAuthenticated()Determines if theSecurityExpressionOperations.getAuthentication()authenticated without the use of remember mebooleanisRememberMe()Determines if theSecurityExpressionOperations.getAuthentication()was authenticated using remember mebooleanpermitAll()Always grants access.voidsetDefaultRolePrefix(java.lang.String defaultRolePrefix)Sets the default prefix to be added tohasAnyRole(String...)orhasRole(String).voidsetPermissionEvaluator(PermissionEvaluator permissionEvaluator)voidsetRoleHierarchy(RoleHierarchy roleHierarchy)voidsetTrustResolver(AuthenticationTrustResolver trustResolver)
 
- 
- 
- 
Field Detail- 
authenticationprotected final Authentication authentication 
 - 
permitAllpublic final boolean permitAll Allows "permitAll" expression- See Also:
- Constant Field Values
 
 - 
denyAllpublic final boolean denyAll Allows "denyAll" expression- See Also:
- Constant Field Values
 
 - 
readpublic final java.lang.String read - See Also:
- Constant Field Values
 
 - 
writepublic final java.lang.String write - See Also:
- Constant Field Values
 
 - 
createpublic final java.lang.String create - See Also:
- Constant Field Values
 
 - 
deletepublic final java.lang.String delete - See Also:
- Constant Field Values
 
 - 
adminpublic final java.lang.String admin - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
SecurityExpressionRootpublic SecurityExpressionRoot(Authentication authentication) Creates a new instance- Parameters:
- authentication- the- Authenticationto use. Cannot be null.
 
 
- 
 - 
Method Detail- 
hasAuthoritypublic final boolean hasAuthority(java.lang.String authority) Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()has a particular authority withinAuthentication.getAuthorities().- Specified by:
- hasAuthorityin interface- SecurityExpressionOperations
- Parameters:
- authority- the authority to test (i.e. "ROLE_USER")
- Returns:
- true if the authority is found, else false
 
 - 
hasAnyAuthoritypublic final boolean hasAnyAuthority(java.lang.String... authorities) Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()has any of the specified authorities withinAuthentication.getAuthorities().- Specified by:
- hasAnyAuthorityin interface- SecurityExpressionOperations
- Parameters:
- authorities- the authorities to test (i.e. "ROLE_USER", "ROLE_ADMIN")
- Returns:
- true if any of the authorities is found, else false
 
 - 
hasRolepublic final boolean hasRole(java.lang.String role) Description copied from interface:SecurityExpressionOperationsDetermines if the SecurityExpressionOperations.getAuthentication()has a particular authority withinAuthentication.getAuthorities().This is similar to SecurityExpressionOperations.hasAuthority(String)except that this method implies that the String passed in is a role. For example, if "USER" is passed in the implementation may convert it to use "ROLE_USER" instead. The way in which the role is converted may depend on the implementation settings.- Specified by:
- hasRolein interface- SecurityExpressionOperations
- Parameters:
- role- the authority to test (i.e. "USER")
- Returns:
- true if the authority is found, else false
 
 - 
hasAnyRolepublic final boolean hasAnyRole(java.lang.String... roles) Description copied from interface:SecurityExpressionOperationsDetermines if the SecurityExpressionOperations.getAuthentication()has any of the specified authorities withinAuthentication.getAuthorities().This is a similar to hasAnyAuthority except that this method implies that the String passed in is a role. For example, if "USER" is passed in the implementation may convert it to use "ROLE_USER" instead. The way in which the role is converted may depend on the implementation settings. - Specified by:
- hasAnyRolein interface- SecurityExpressionOperations
- Parameters:
- roles- the authorities to test (i.e. "USER", "ADMIN")
- Returns:
- true if any of the authorities is found, else false
 
 - 
getAuthenticationpublic final Authentication getAuthentication() Description copied from interface:SecurityExpressionOperationsGets theAuthenticationused for evaluating the expressions- Specified by:
- getAuthenticationin interface- SecurityExpressionOperations
- Returns:
- the Authenticationfor evaluating the expressions
 
 - 
permitAllpublic final boolean permitAll() Description copied from interface:SecurityExpressionOperationsAlways grants access.- Specified by:
- permitAllin interface- SecurityExpressionOperations
- Returns:
- true
 
 - 
denyAllpublic final boolean denyAll() Description copied from interface:SecurityExpressionOperationsAlways denies access- Specified by:
- denyAllin interface- SecurityExpressionOperations
- Returns:
- false
 
 - 
isAnonymouspublic final boolean isAnonymous() Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()is anonymous- Specified by:
- isAnonymousin interface- SecurityExpressionOperations
- Returns:
- true if the user is anonymous, else false
 
 - 
isAuthenticatedpublic final boolean isAuthenticated() Description copied from interface:SecurityExpressionOperationsDetermines iftheSecurityExpressionOperations.getAuthentication()is authenticated- Specified by:
- isAuthenticatedin interface- SecurityExpressionOperations
- Returns:
- true if the SecurityExpressionOperations.getAuthentication()is authenticated, else false
 
 - 
isRememberMepublic final boolean isRememberMe() Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()was authenticated using remember me- Specified by:
- isRememberMein interface- SecurityExpressionOperations
- Returns:
- true if the SecurityExpressionOperations.getAuthentication()authenticated using remember me, else false
 
 - 
isFullyAuthenticatedpublic final boolean isFullyAuthenticated() Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()authenticated without the use of remember me- Specified by:
- isFullyAuthenticatedin interface- SecurityExpressionOperations
- Returns:
- true if the SecurityExpressionOperations.getAuthentication()authenticated without the use of remember me, else false
 
 - 
getPrincipalpublic java.lang.Object getPrincipal() Convenience method to accessAuthentication.getPrincipal()fromgetAuthentication()- Returns:
 
 - 
setTrustResolverpublic void setTrustResolver(AuthenticationTrustResolver trustResolver) 
 - 
setRoleHierarchypublic void setRoleHierarchy(RoleHierarchy roleHierarchy) 
 - 
setDefaultRolePrefixpublic void setDefaultRolePrefix(java.lang.String defaultRolePrefix) Sets the default prefix to be added to hasAnyRole(String...)orhasRole(String). For example, if hasRole("ADMIN") or hasRole("ROLE_ADMIN") is passed in, then the role ROLE_ADMIN will be used when the defaultRolePrefix is "ROLE_" (default).If null or empty, then no default role prefix is used. - Parameters:
- defaultRolePrefix- the default prefix to add to roles. Default "ROLE_".
 
 - 
hasPermissionpublic boolean hasPermission(java.lang.Object target, java.lang.Object permission)Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()has permission to access the target given the permission- Specified by:
- hasPermissionin interface- SecurityExpressionOperations
- Parameters:
- target- the target domain object to check permission on
- permission- the permission to check on the domain object (i.e. "read", "write", etc).
- Returns:
- true if permission is granted to the SecurityExpressionOperations.getAuthentication(), else false
 
 - 
hasPermissionpublic boolean hasPermission(java.lang.Object targetId, java.lang.String targetType, java.lang.Object permission)Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()has permission to access the domain object with a given id, type, and permission.- Specified by:
- hasPermissionin interface- SecurityExpressionOperations
- Parameters:
- targetId- the identifier of the domain object to determine access
- targetType- the type (i.e. com.example.domain.Message)
- permission- the perission to check on the domain object (i.e. "read", "write", etc)
- Returns:
- true if permission is granted to the SecurityExpressionOperations.getAuthentication(), else false
 
 - 
setPermissionEvaluatorpublic void setPermissionEvaluator(PermissionEvaluator permissionEvaluator) 
 
- 
 
-