Package org.craftercms.engine.util
Class SecurityUtils
java.lang.Object
org.craftercms.engine.util.SecurityUtils
Utility class for security related operations.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckAccess(Collection<String> authorizedRoles, String url) Validates that the user has access to a content protected by the specified roles.protected static booleancontainsRole(String role, Collection<String> roles) getAuthorizedRolesMatchValue(Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Returns a list of values to be used for authorized roles matching.static StringgetRoleFieldNameWithKeyword(String roleFieldName) Returns the role field name ensuring it ends with ".keyword"protected static booleanhasAnyRole(org.springframework.security.core.Authentication auth, Collection<String> roles)
-
Field Details
-
ANONYMOUS_PSEUDO_ROLE
- See Also:
-
ROLE_PREFIX
- See Also:
-
AUTHENTICATED_PSEUDO_ROLE
- See Also:
-
AUTHENTICATED_PSEUDO_ROLES_SEARCH_VALUES
-
ANONYMOUS_PSEUDO_ROLES_SEARCH_VALUES
-
KEYWORD_SUFFIX
- See Also:
-
-
Method Details
-
getAuthorizedRolesMatchValue
public static List<String> getAuthorizedRolesMatchValue(@NonNull Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Returns a list of values to be used for authorized roles matching.
For each role, this method will include the role itself and the role with the ROLE_ prefix.- Parameters:
authorities- the user authorities/roles- Returns:
- a list of authorized roles for matching
-
getRoleFieldNameWithKeyword
Returns the role field name ensuring it ends with ".keyword"- Returns:
- the role field name with ".keyword" suffix for search exact matching
-
checkAccess
public static void checkAccess(Collection<String> authorizedRoles, String url) throws org.springframework.security.access.AccessDeniedException, org.springframework.security.core.AuthenticationException Validates that the user has access to a content protected by the specified roles. This method will throw anAccessDeniedExceptionif the user doesn't have access. Access is granted if:- authorizedRoles is empty
- authorizedRoles contains 'anonymous' pseudo-role
- authorizedRoles contains 'authenticated' pseudo-role and authentication is not anonymous
- authorizedRoles contains any of the user roles/authorities
- Throws:
org.springframework.security.access.AccessDeniedExceptionorg.springframework.security.core.AuthenticationException
-
containsRole
-
hasAnyRole
protected static boolean hasAnyRole(org.springframework.security.core.Authentication auth, Collection<String> roles)
-