Class DefaultAuthenticationManager

java.lang.Object
org.tentackle.session.auth.DefaultAuthenticationManager
All Implemented Interfaces:
AuthenticationManager

@Service(AuthenticationManager.class) public class DefaultAuthenticationManager extends Object implements AuthenticationManager
The default authentication manager.

Collects all AuthenticationProviders along the classpath and orders them by priority, then by class name, so that the chain is deterministic regardless of the order in which the modules happen to be discovered.

Author:
harald
  • Constructor Details

    • DefaultAuthenticationManager

      public DefaultAuthenticationManager()
      Creates an authentication manager.
      Collects all AuthenticationProvider services.
    • DefaultAuthenticationManager

      protected DefaultAuthenticationManager(List<AuthenticationProvider> providers)
      Creates an authentication manager for an explicit chain.
      Useful for applications that wire their providers themselves, and for tests.

      The chain is copied and frozen: authenticate(Credentials) iterates it on every login, from every request thread, and must never see it change underneath.

      Parameters:
      providers - the providers, in any order
  • Method Details

    • discoverProviders

      protected static List<AuthenticationProvider> discoverProviders()
      Collects all authentication providers along the classpath.
      Returns:
      the providers, never null
    • getProviders

      public List<AuthenticationProvider> getProviders()
      Description copied from interface: AuthenticationManager
      Gets the provider chain in the order it is asked.

      The chain is fixed once the manager is created, since AuthenticationManager.authenticate(Credentials) iterates it concurrently. Implementations must therefore not hand out a list a caller could modify.

      Specified by:
      getProviders in interface AuthenticationManager
      Returns:
      the providers, never null, unmodifiable
    • authenticate

      public Authentication authenticate(Credentials credentials)
      Description copied from interface: AuthenticationManager
      Authenticates the credentials presented by a client.
      Specified by:
      authenticate in interface AuthenticationManager
      Parameters:
      credentials - the credentials, null if the client presented none
      Returns:
      the proven identity, never null
    • resolveUser

      protected void resolveUser(Authentication authentication)
      Determines the application's user for a proven identity.

      Providers that know the application's user (such as a password provider that looked it up anyway) set the ids themselves. For all others the application's UserResolver is applied.

      Parameters:
      authentication - the proven identity