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) static StringgetAuthorizedRolesMatchValue(Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Returns the value to be used in the authorizedRoles field of a search request.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_ROLE_SEARCH_VALUE
- See Also:
-
ANONYMOUS_PSEUDO_ROLE_SEARCH_VALUE
- See Also:
-
-
Method Details
-
getAuthorizedRolesMatchValue
public static String getAuthorizedRolesMatchValue(@NonNull Collection<? extends org.springframework.security.core.GrantedAuthority> authorities) Returns the value to be used in the authorizedRoles field of a search request.
For each role, this method will include the role itself and the role with the ROLE_ prefix.- Parameters:
authorities- the user authorities/roles- Returns:
- the value to be used in the authorizedRoles field of a search request
-
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)
-