Package io.micronaut.security.utils
Class DefaultSecurityService
- java.lang.Object
-
- io.micronaut.security.utils.DefaultSecurityService
-
- All Implemented Interfaces:
SecurityService
@Singleton public class DefaultSecurityService extends java.lang.Object implements SecurityService
Default implementation ofSecurityService. It usesServerRequestContext.currentRequest()to retrieve theAuthenticationobject if any.- Since:
- 1.0
- Author:
- Sergio del Amo
-
-
Constructor Summary
Constructors Constructor Description DefaultSecurityService()
-
Method Summary
All Methods Instance Methods Concrete 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
public java.util.Optional<java.lang.String> username()
Get the username of the current user.- Specified by:
usernamein interfaceSecurityService- Returns:
- the username of the current user
-
getAuthentication
public java.util.Optional<Authentication> getAuthentication()
RetrievesAuthenticationif authenticated.- Specified by:
getAuthenticationin interfaceSecurityService- Returns:
- the
Authenticationof the current user
-
isAuthenticated
public boolean isAuthenticated()
Check if a user is authenticated.- Specified by:
isAuthenticatedin interfaceSecurityService- Returns:
- true if the user is authenticated, false otherwise
-
hasRole
public boolean hasRole(java.lang.String role)
If the current user has a specific role.- Specified by:
hasRolein interfaceSecurityService- Parameters:
role- the role to check- Returns:
- true if the current user has the role, false otherwise
-
hasRole
public boolean hasRole(java.lang.String role, java.lang.String rolesKey)If the current user has a specific role.- Specified by:
hasRolein interfaceSecurityService- 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
-
-