Class DefaultSecurityService

  • All Implemented Interfaces:
    SecurityService

    @Singleton
    public class DefaultSecurityService
    extends java.lang.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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<Authentication> getAuthentication()
      Retrieves Authentication 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultSecurityService

        public DefaultSecurityService()
    • Method Detail

      • username

        public java.util.Optional<java.lang.String> username()
        Get the username of the current user.
        Specified by:
        username in interface SecurityService
        Returns:
        the username of the current user
      • isAuthenticated

        public boolean isAuthenticated()
        Check if a user is authenticated.
        Specified by:
        isAuthenticated in interface SecurityService
        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 interface SecurityService
        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 interface SecurityService
        Parameters:
        role - the authority to check
        rolesKey - The map key to be used in the authentications attributes. E.g. "roles".
        Returns:
        true if the current user has the authority, false otherwise