Interface UserAuthentication<A extends Identity>

Type Parameters:
A - the identity type
All Superinterfaces:
Authentication, GroupAwareAuthentication, PrincipalAuthentication

public interface UserAuthentication<A extends Identity> extends PrincipalAuthentication, GroupAwareAuthentication

An authentication resulting from the authentication of a user uniquely identified by a username in a UserAuthenticator.

It extends the PrincipalAuthentication by exposing the identity of the authenticated user (if any) and the groups it belongs to. This implementation is then allows to create a complete SecurityContext with an Authentication, an Identity and an AccessController (i.e. RoleBasedAccessController).

For example, an application could then build its security context using a UserAuthenticator, a UserIdentityResolver and a GroupsRoleBasedAccessControllerResolver. Note that the API is flexible and allow other combinations as well.

Since:
1.5
Author:
Jeremy Kuhn
  • Method Details

    • getIdentity

      A getIdentity()

      Returns the user's identity.

      Returns:
      the user identity or null if none was resolved during the authentication process.
    • of

      static <A extends Identity> UserAuthentication<A> of(String username, String... groups)

      Creates a user authentication with the specified name and groups.

      This is a conveninence method that should be used with care and only used after a successful authentication to generate the resulting authentication.

      Type Parameters:
      A - the identity type
      Parameters:
      username - a username
      groups - an array of groups
      Returns:
      a new user authentication
    • of

      static <A extends Identity> UserAuthentication<A> of(String username, SecurityException cause)

      Returns a new denied user authentication for the specified username and cause.

      Type Parameters:
      A - the identity type
      Parameters:
      username - a username
      cause - the cause of the failed authentication
      Returns:
      a denied user authentication
    • of

      static <A extends Identity> UserAuthentication<A> of(String username, Collection<String> groups)

      Creates a user authentication with the specified name and groups.

      This is a conveninence method that should be used with care and only used after a successful authentication to generate the resulting authentication.

      Type Parameters:
      A - the identity type
      Parameters:
      username - a username
      groups - a collection of groups
      Returns:
      a new user authentication
    • of

      static <A extends Identity> UserAuthentication<A> of(String username, A identity, String... groups)

      Creates a user authentication with the specified name, identity and groups.

      This is a conveninence method that should be used with care and only used after a successful authentication to generate the resulting authentication.

      Type Parameters:
      A - the identity type
      Parameters:
      username - a username
      identity - the identity of the user
      groups - an array of groups
      Returns:
      a new user authentication
    • of

      static <A extends Identity> UserAuthentication<A> of(String username, A identity, Collection<String> groups)

      Creates a user authentication with the specified name, identity and groups.

      This is a conveninence method that should be used with care and only used after a successful authentication to generate the resulting authentication.

      Type Parameters:
      A - the identity type
      Parameters:
      username - a username
      identity - the identity of the user
      groups - a collection of groups
      Returns:
      a new user authentication
    • of

      static <A extends Identity> UserAuthentication<A> of(User<A> user)

      Creates a user authentication from the specified user.

      This is a conveninence method that should be used with care. In order to respect the Authentication contract it is important to make sure that the specified user has been previously authenticated by an Authenticator.

      The resulting authentication is authenticated if the specified user is not locked.

      Type Parameters:
      A - the identity type
      Parameters:
      user - an authenticated user
      Returns:
      a new user authentication