Package io.micronaut.security.utils
Class DefaultSecurityService
java.lang.Object
io.micronaut.security.utils.DefaultSecurityService
- All Implemented Interfaces:
SecurityService
@Requires(classes=io.micronaut.http.context.ServerRequestContext.class)
@Singleton
public class DefaultSecurityService
extends Object
implements SecurityService
Default implementation of
SecurityService
. It uses ServerRequestContext.currentRequest()
to retrieve the Authentication
object if any.- Since:
- 1.0
- Author:
- Sergio del Amo
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionRetrievesAuthentication
if authenticated.boolean
If the current user has a specific role.boolean
Check if a user is authenticated.username()
Get the username of the current user.
-
Constructor Details
-
DefaultSecurityService
- Parameters:
rolesFinder
- Roles Parser
-
-
Method Details
-
username
Get the username of the current user.- Specified by:
username
in interfaceSecurityService
- Returns:
- the username of the current user
-
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
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
-