Interface SecurityService

  • All Known Implementing Classes:
    DefaultSecurityService

    public interface SecurityService
    Provides a set of convenient methods related to authentication and authorization.
    Since:
    1.0
    Author:
    Sergio del Amo
    • Method Detail

      • username

        java.util.Optional<java.lang.String> username()
        Get the username of the current user.
        Returns:
        the username of the current user or Optional.empty if not authenticated
      • isAuthenticated

        boolean isAuthenticated()
        Check if a user is authenticated.
        Returns:
        true if the user is authenticated, false otherwise
      • hasRole

        boolean hasRole​(java.lang.String role)
        If the current user has a specific role.
        Parameters:
        role - the role to check
        Returns:
        true if the current user has the role, false otherwise
      • hasRole

        boolean hasRole​(java.lang.String role,
                        java.lang.String rolesKey)
        If the current user has a specific role.
        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