Class SecurityExpressionRoot
- All Implemented Interfaces:
SecurityExpressionOperations
- Direct Known Subclasses:
MessageSecurityExpressionRoot,WebSecurityExpressionRoot
- Since:
- 3.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSecurityExpressionRoot(Supplier<Authentication> authentication) Creates a new instance that uses lazy initialization of theAuthenticationobject.SecurityExpressionRoot(Authentication authentication) Creates a new instance -
Method Summary
Modifier and TypeMethodDescriptionfinal booleandenyAll()Always denies accessfinal AuthenticationGets theAuthenticationused for evaluating the expressionsConvenience method to accessAuthentication.getPrincipal()fromgetAuthentication()final booleanhasAnyAuthority(String... authorities) Determines if theSecurityExpressionOperations.getAuthentication()has any of the specified authorities withinAuthentication.getAuthorities().final booleanhasAnyRole(String... roles) Determines if theSecurityExpressionOperations.getAuthentication()has any of the specified authorities withinAuthentication.getAuthorities().final booleanhasAuthority(String authority) Determines if theSecurityExpressionOperations.getAuthentication()has a particular authority withinAuthentication.getAuthorities().booleanhasPermission(Object target, Object permission) Determines if theSecurityExpressionOperations.getAuthentication()has permission to access the target given the permissionbooleanhasPermission(Object targetId, String targetType, Object permission) Determines if theSecurityExpressionOperations.getAuthentication()has permission to access the domain object with a given id, type, and permission.final booleanDetermines if theSecurityExpressionOperations.getAuthentication()has a particular authority withinAuthentication.getAuthorities().final booleanDetermines if theSecurityExpressionOperations.getAuthentication()is anonymousfinal booleanDetermines iftheSecurityExpressionOperations.getAuthentication()is authenticatedfinal booleanDetermines if theSecurityExpressionOperations.getAuthentication()authenticated without the use of remember mefinal booleanDetermines if theSecurityExpressionOperations.getAuthentication()was authenticated using remember mefinal booleanAlways grants access.voidsetDefaultRolePrefix(String defaultRolePrefix) Sets the default prefix to be added tohasAnyRole(String...)orhasRole(String).voidsetPermissionEvaluator(PermissionEvaluator permissionEvaluator) voidsetRoleHierarchy(RoleHierarchy roleHierarchy) voidsetTrustResolver(AuthenticationTrustResolver trustResolver)
-
Field Details
-
permitAll
public final boolean permitAllAllows "permitAll" expression- See Also:
-
denyAll
public final boolean denyAllAllows "denyAll" expression- See Also:
-
read
- See Also:
-
write
- See Also:
-
create
- See Also:
-
delete
- See Also:
-
admin
- See Also:
-
-
Constructor Details
-
SecurityExpressionRoot
Creates a new instance- Parameters:
authentication- theAuthenticationto use. Cannot be null.
-
SecurityExpressionRoot
Creates a new instance that uses lazy initialization of theAuthenticationobject.- Parameters:
authentication- theSupplierof theAuthenticationto use. Cannot be null.- Since:
- 5.8
-
-
Method Details
-
hasAuthority
Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()has a particular authority withinAuthentication.getAuthorities().- Specified by:
hasAuthorityin interfaceSecurityExpressionOperations- Parameters:
authority- the authority to test (i.e. "ROLE_USER")- Returns:
- true if the authority is found, else false
-
hasAnyAuthority
Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()has any of the specified authorities withinAuthentication.getAuthorities().- Specified by:
hasAnyAuthorityin interfaceSecurityExpressionOperations- Parameters:
authorities- the authorities to test (i.e. "ROLE_USER", "ROLE_ADMIN")- Returns:
- true if any of the authorities is found, else false
-
hasRole
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 interfaceSecurityExpressionOperations- Parameters:
role- the authority to test (i.e. "USER")- Returns:
- true if the authority is found, else false
-
hasAnyRole
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 interfaceSecurityExpressionOperations- Parameters:
roles- the authorities to test (i.e. "USER", "ADMIN")- Returns:
- true if any of the authorities is found, else false
-
getAuthentication
Description copied from interface:SecurityExpressionOperationsGets theAuthenticationused for evaluating the expressions- Specified by:
getAuthenticationin interfaceSecurityExpressionOperations- Returns:
- the
Authenticationfor evaluating the expressions
-
permitAll
public final boolean permitAll()Description copied from interface:SecurityExpressionOperationsAlways grants access.- Specified by:
permitAllin interfaceSecurityExpressionOperations- Returns:
- true
-
denyAll
public final boolean denyAll()Description copied from interface:SecurityExpressionOperationsAlways denies access- Specified by:
denyAllin interfaceSecurityExpressionOperations- Returns:
- false
-
isAnonymous
public final boolean isAnonymous()Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()is anonymous- Specified by:
isAnonymousin interfaceSecurityExpressionOperations- Returns:
- true if the user is anonymous, else false
-
isAuthenticated
public final boolean isAuthenticated()Description copied from interface:SecurityExpressionOperationsDetermines iftheSecurityExpressionOperations.getAuthentication()is authenticated- Specified by:
isAuthenticatedin interfaceSecurityExpressionOperations- Returns:
- true if the
SecurityExpressionOperations.getAuthentication()is authenticated, else false
-
isRememberMe
public final boolean isRememberMe()Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()was authenticated using remember me- Specified by:
isRememberMein interfaceSecurityExpressionOperations- Returns:
- true if the
SecurityExpressionOperations.getAuthentication()authenticated using remember me, else false
-
isFullyAuthenticated
public final boolean isFullyAuthenticated()Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()authenticated without the use of remember me- Specified by:
isFullyAuthenticatedin interfaceSecurityExpressionOperations- Returns:
- true if the
SecurityExpressionOperations.getAuthentication()authenticated without the use of remember me, else false
-
getPrincipal
Convenience method to accessAuthentication.getPrincipal()fromgetAuthentication()- Returns:
-
setTrustResolver
-
setRoleHierarchy
-
setDefaultRolePrefix
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_".
-
hasPermission
Description copied from interface:SecurityExpressionOperationsDetermines if theSecurityExpressionOperations.getAuthentication()has permission to access the target given the permission- Specified by:
hasPermissionin interfaceSecurityExpressionOperations- Parameters:
target- the target domain object to check permission onpermission- 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
-
hasPermission
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 interfaceSecurityExpressionOperations- Parameters:
targetId- the identifier of the domain object to determine accesstargetType- 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
-
setPermissionEvaluator
-