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 theAuthentication
object 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()
RetrievesAuthentication
if authenticated.boolean
hasRole(java.lang.String role)
If the current user has a specific role.boolean
hasRole(java.lang.String role, java.lang.String rolesKey)
If the current user has a specific role.boolean
isAuthenticated()
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:
username
in interfaceSecurityService
- Returns:
- the username of the current user
-
getAuthentication
public java.util.Optional<Authentication> getAuthentication()
RetrievesAuthentication
if authenticated.- Specified by:
getAuthentication
in interfaceSecurityService
- Returns:
- the
Authentication
of the current user
-
isAuthenticated
public boolean isAuthenticated()
Check if a user is authenticated.- Specified by:
isAuthenticated
in 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:
hasRole
in 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:
hasRole
in 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
-
-