Package de.trustable.ca3s.core.security
Class SecurityUtils
- java.lang.Object
-
- de.trustable.ca3s.core.security.SecurityUtils
-
public final class SecurityUtils extends Object
Utility class for Spring Security.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optional<String>getCurrentUserJWT()Get the JWT of the current user.static Optional<String>getCurrentUserLogin()Get the login of the current user.static booleanhasCurrentUserAnyOfAuthorities(String... authorities)Checks if the current user has any of the authorities.static booleanhasCurrentUserNoneOfAuthorities(String... authorities)Checks if the current user has none of the authorities.static booleanhasCurrentUserThisAuthority(String authority)Checks if the current user has a specific authority.static booleanisAuthenticated()Check if a user is authenticated.static booleanisCurrentUserInRole(String authority)If the current user has a specific authority (security role).
-
-
-
Method Detail
-
getCurrentUserLogin
public static Optional<String> getCurrentUserLogin()
Get the login of the current user.- Returns:
- the login of the current user.
-
getCurrentUserJWT
public static Optional<String> getCurrentUserJWT()
Get the JWT of the current user.- Returns:
- the JWT of the current user.
-
isAuthenticated
public static boolean isAuthenticated()
Check if a user is authenticated.- Returns:
- true if the user is authenticated, false otherwise.
-
hasCurrentUserAnyOfAuthorities
public static boolean hasCurrentUserAnyOfAuthorities(String... authorities)
Checks if the current user has any of the authorities.- Parameters:
authorities- the authorities to check.- Returns:
- true if the current user has any of the authorities, false otherwise.
-
hasCurrentUserNoneOfAuthorities
public static boolean hasCurrentUserNoneOfAuthorities(String... authorities)
Checks if the current user has none of the authorities.- Parameters:
authorities- the authorities to check.- Returns:
- true if the current user has none of the authorities, false otherwise.
-
hasCurrentUserThisAuthority
public static boolean hasCurrentUserThisAuthority(String authority)
Checks if the current user has a specific authority.- Parameters:
authority- the authority to check.- Returns:
- true if the current user has the authority, false otherwise.
-
isCurrentUserInRole
public static boolean isCurrentUserInRole(String authority)
If the current user has a specific authority (security role).The name of this method comes from the
isUserInRole()method in the Servlet API.- Parameters:
authority- the authority to check.- Returns:
- true if the current user has the authority, false otherwise.
-
-