Class GenericUserAuthentication<A extends Identity>

java.lang.Object
io.inverno.mod.security.internal.authentication.user.GenericUserAuthentication<A>
Type Parameters:
A - the type of identity
All Implemented Interfaces:
Authentication, GroupAwareAuthentication, PrincipalAuthentication, UserAuthentication<A>

public class GenericUserAuthentication<A extends Identity> extends Object implements UserAuthentication<A>

Generic UserAuthentication implementation.

Since:
1.5
Author:
Jeremy Kuhn
  • Constructor Details

    • GenericUserAuthentication

      public GenericUserAuthentication(String username, A identity, Set<String> groups, boolean authenticated)

      Creates a generic user authentication with the specified username, identity and set of groups.

      Parameters:
      username - a username
      identity - an identity
      groups - a set of groups
      authenticated - true to create an authenticated authentication, false otherwise
  • Method Details

    • setCause

      public void setCause(SecurityException cause)

      Sets the cause of the failed authentication.

      This also sets the authenticated flag to false when the specified cause is not null.

      Parameters:
      cause - a security exception resulting from the failed authentication
    • getUsername

      public String getUsername()
      Description copied from interface: PrincipalAuthentication

      Returns the unique username of the authenticated entity.

      Specified by:
      getUsername in interface PrincipalAuthentication
      Returns:
      a username
    • getGroups

      public Set<String> getGroups()
      Description copied from interface: GroupAwareAuthentication

      Returns the groups to which the authenticated entity belongs to.

      Specified by:
      getGroups in interface GroupAwareAuthentication
      Returns:
      a sets of groups
    • getIdentity

      public A getIdentity()
      Description copied from interface: UserAuthentication

      Returns the user's identity.

      Specified by:
      getIdentity in interface UserAuthentication<A extends Identity>
      Returns:
      the user identity or null if none was resolved during the authentication process.
    • isAuthenticated

      public boolean isAuthenticated()
      Description copied from interface: Authentication

      Determine whether the authentication is authenticated.

      A non-authenticated authentication might indicates that no authentication took place (i.e. anonymous access) or that the authentication failed. In case of a failed authentication, the cause is exposed by Authentication.getCause().

      Specified by:
      isAuthenticated in interface Authentication
      Returns:
      true if the the authentication is authenticated, false otherwise
    • getCause

      public Optional<SecurityException> getCause()
      Description copied from interface: Authentication

      Returns the cause of a failed authentication.

      A non-authenticated authentication with no cause indicates that no authentication took place (i.e. anonymous access).

      A non-authenticated authentication with a cause indicates a failed authentication.

      Specified by:
      getCause in interface Authentication
      Returns:
      an optional returning the cause of the failed authentication, or an empty optional if there was no authentication or if the authentication was successful
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object