@Singleton public class DefaultSecurityService extends Object implements SecurityService
SecurityService
. It uses ServerRequestContext.currentRequest()
to retrieve the Authentication
object if any.Constructor and Description |
---|
DefaultSecurityService() |
Modifier and Type | Method and Description |
---|---|
Optional<Authentication> |
getAuthentication()
Retrieves
Authentication if authenticated. |
boolean |
hasRole(String role)
If the current user has a specific role.
|
boolean |
hasRole(String role,
String rolesKey)
If the current user has a specific role.
|
boolean |
isAuthenticated()
Check if a user is authenticated.
|
Optional<String> |
username()
Get the username of the current user.
|
public Optional<String> username()
username
in interface SecurityService
public Optional<Authentication> getAuthentication()
Authentication
if authenticated.getAuthentication
in interface SecurityService
Authentication
of the current userpublic boolean isAuthenticated()
isAuthenticated
in interface SecurityService
public boolean hasRole(String role)
hasRole
in interface SecurityService
role
- the role to checkpublic boolean hasRole(String role, String rolesKey)
hasRole
in interface SecurityService
role
- the authority to checkrolesKey
- The map key to be used in the authentications attributes. E.g. "roles".