Package io.micronaut.security.utils
Interface SecurityService
-
- All Known Implementing Classes:
DefaultSecurityService
public interface SecurityServiceProvides a set of convenient methods related to authentication and authorization.- Since:
- 1.0
- Author:
- Sergio del Amo
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.Optional<Authentication>getAuthentication()RetrievesAuthenticationif authenticated.booleanhasRole(java.lang.String role)If the current user has a specific role.booleanhasRole(java.lang.String role, java.lang.String rolesKey)If the current user has a specific role.booleanisAuthenticated()Check if a user is authenticated.java.util.Optional<java.lang.String>username()Get the username of the current user.
-
-
-
Method Detail
-
username
java.util.Optional<java.lang.String> username()
Get the username of the current user.- Returns:
- the username of the current user or Optional.empty if not authenticated
-
getAuthentication
java.util.Optional<Authentication> getAuthentication()
RetrievesAuthenticationif authenticated.- Returns:
- the
Authenticationof the current user
-
isAuthenticated
boolean isAuthenticated()
Check if a user is authenticated.- Returns:
- true if the user is authenticated, false otherwise
-
hasRole
boolean hasRole(java.lang.String role)
If the current user has a specific role.- Parameters:
role- the role to check- Returns:
- true if the current user has the role, false otherwise
-
hasRole
boolean hasRole(java.lang.String role, java.lang.String rolesKey)If the current user has a specific role.- Parameters:
role- the authority to checkrolesKey- The map key to be used in the authentications attributes. E.g. "roles".- Returns:
- true if the current user has the authority, false otherwise
-
-