Class LdapAuthenticationProvider<T,I,S>
- Type Parameters:
T- Request Context TypeI- Authentication Request Identity TypeS- Authentication Request Secret Type
- All Implemented Interfaces:
io.micronaut.core.order.Ordered, AuthenticationProvider<T,I, S>, ExecutorAuthenticationProvider<T, I, S>, Closeable, AutoCloseable
LdapConfiguration. One provider will be created for each configuration.- Since:
- 1.0
- Author:
- James Kleeh
-
Field Summary
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionLdapAuthenticationProvider(LdapConfiguration configuration, LdapSearchService ldapSearchService, ContextBuilder contextBuilder, ContextAuthenticationMapper contextAuthenticationMapper, LdapGroupProcessor ldapGroupProcessor, ExecutorService executorService) -
Method Summary
Modifier and TypeMethodDescriptionauthenticate(T requestContext, AuthenticationRequest<I, S> authenticationRequest) Authenticates a user with the given request.voidclose()protected AuthenticationResponserejectUnknownUser(T requestContext, AuthenticationRequest<I, S> authenticationRequest) Rejects an authentication request whose username did not match any directory entry.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AuthenticationProvider
authenticateMethods inherited from interface ExecutorAuthenticationProvider
getExecutorNameMethods inherited from interface io.micronaut.core.order.Ordered
getOrder
-
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 authenticateldapSearchService- The search servicecontextBuilder- The context buildercontextAuthenticationMapper- The authentication mapperldapGroupProcessor- The group processorexecutorService- Executor Service
-
-
Method Details
-
authenticate
public AuthenticationResponse authenticate(T requestContext, AuthenticationRequest<I, S> authenticationRequest) Description copied from interface:AuthenticationProviderAuthenticates a user with the given request. If authenticated successfully returnAuthenticationResponse.success(String). If not authenticated returnAuthenticationResponse.failure(). If your implementation is blocking, annotate the overriden method withBlockingand it will be safely executed on a dedicated thread in order to not block the main reactive chain of execution.- Specified by:
authenticatein interfaceAuthenticationProvider<T,I, S> - Parameters:
requestContext- The context request (typically an HTTP Request).authenticationRequest- The credentials to authenticate- Returns:
- An
AuthenticationResponseindicating either success or failure.
-
rejectUnknownUser
protected AuthenticationResponse rejectUnknownUser(T requestContext, AuthenticationRequest<I, S> 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, neverAuthenticationFailureReason.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 isLdapConfiguration.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 contextauthenticationRequest- The authentication request, whose identity matched no entry- Returns:
- a
AuthenticationFailureReason.CREDENTIALS_DO_NOT_MATCHfailure - Since:
- 5.5.2
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-