Class LdapAuthenticationProvider<T>

java.lang.Object
io.micronaut.security.ldap.LdapAuthenticationProvider<T>
Type Parameters:
T - Request Context Type
All Implemented Interfaces:
AuthenticationProvider<T>, Closeable, AutoCloseable

public class LdapAuthenticationProvider<T> extends Object implements AuthenticationProvider<T>, Closeable
Authenticates against an LDAP server using the configuration provided through LdapConfiguration. One provider will be created for each configuration.
Since:
1.0
Author:
James Kleeh
  • Constructor Details

    • LdapAuthenticationProvider

      public LdapAuthenticationProvider(LdapConfiguration configuration, LdapSearchService ldapSearchService, ContextBuilder contextBuilder, ContextAuthenticationMapper contextAuthenticationMapper, LdapGroupProcessor ldapGroupProcessor, @Named("io") ExecutorService executorService)
      Parameters:
      configuration - The configuration to use to authenticate
      ldapSearchService - The search service
      contextBuilder - The context builder
      contextAuthenticationMapper - The authentication mapper
      ldapGroupProcessor - The group processor
      executorService - Executor Service
  • Method Details

    • authenticate

      public org.reactivestreams.Publisher<AuthenticationResponse> authenticate(T requestContext, AuthenticationRequest<?,?> authenticationRequest)
      Description copied from interface: AuthenticationProvider
      Authenticates a user with the given request. If a successful authentication is returned, the object must be an instance of Authentication. Publishers MUST emit cold observables! This method will be called for all authenticators for each authentication request and it is assumed no work will be done until the publisher is subscribed to.
      Specified by:
      authenticate in interface AuthenticationProvider<T>
      Parameters:
      requestContext - The http request
      authenticationRequest - The credentials to authenticate
      Returns:
      A publisher that emits 0 or 1 responses
    • rejectUnknownUser

      protected AuthenticationResponse rejectUnknownUser(T requestContext, AuthenticationRequest<?,?> authenticationRequest)
      Rejects an authentication request whose username did not match any directory entry.

      To prevent username enumeration (CWE-204) the response is indistinguishable from the one returned for a wrong password: the failure reason is always AuthenticationFailureReason.CREDENTIALS_DO_NOT_MATCH, never AuthenticationFailureReason.USER_NOT_FOUND, and a bind against a decoy DN is attempted so that an unknown username costs roughly the same client-side directory round trip as a known username with a wrong password. The outcome of that bind is ignored. The decoy DN is LdapConfiguration.SearchConfiguration.getDecoyDn() when configured, otherwise a random, non-existent entry under the search base.

      Only the client-side cost is equalised. A directory may still answer faster for a non-existent DN than for a wrong password; configure a real decoy entry where that matters.

      Parameters:
      requestContext - The request context
      authenticationRequest - The authentication request, whose identity matched no entry
      Returns:
      a AuthenticationFailureReason.CREDENTIALS_DO_NOT_MATCH failure
      Since:
      4.18.2
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable