Package org.ldaptive.auth
Class Authenticator
- java.lang.Object
- 
- org.ldaptive.AbstractFreezable
- 
- org.ldaptive.auth.Authenticator
 
 
- 
- All Implemented Interfaces:
- Freezable
 
 public final class Authenticator extends AbstractFreezable Provides functionality to authenticate users against an ldap directory.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classAuthenticator.BuilderAuthenticator builder.
 - 
Field SummaryFields Modifier and Type Field Description private AuthenticationHandlerauthenticationHandlerHandler to handle authentication.private DnResolverdnResolverFor finding user DNs.private EntryResolverentryResolverFor finding user entries.private LoggerloggerLogger for this class.private static EntryResolverNO_OP_RESOLVERNoOp entry resolver.private AuthenticationRequestHandler[]requestHandlersHandlers to handle authentication requests.private booleanresolveEntryOnFailureWhether to execute the entry resolver on authentication failure.private AuthenticationResponseHandler[]responseHandlersHandlers to handle authentication responses.private String[]returnAttributesUser attributes to return.
 - 
Constructor SummaryConstructors Constructor Description Authenticator()Default constructor.Authenticator(DnResolver resolver, AuthenticationHandler handler)Creates a new authenticator.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private AuthenticationResponseauthenticate(String dn, AuthenticationRequest request)Validates input and performs authentication using anAuthenticationHandler.AuthenticationResponseauthenticate(AuthenticationRequest request)Authenticate the user in the supplied request.static Authenticator.Builderbuilder()Creates a builder for this class.voidclose()Attempts to close any connection factories associated with this authenticator.private voidcloseConnectionFactoryManagers(Set<ConnectionFactoryManager> managers)Attempts to close all the connection factories in the supplied collection.voidfreeze()Freezes this object, making it immutable.AuthenticationHandlergetAuthenticationHandler()Returns the authentication handler.DnResolvergetDnResolver()Returns the DN resolver.EntryResolvergetEntryResolver()Returns the entry resolver.AuthenticationRequestHandler[]getRequestHandlers()Returns the authentication request handlers.booleangetResolveEntryOnFailure()Returns whether to execute the entry resolver on authentication failure.AuthenticationResponseHandler[]getResponseHandlers()Returns the authentication response handlers.String[]getReturnAttributes()Returns the return attributes.private AuthenticationRequestprocessRequest(String dn, AuthenticationRequest request)Creates a new authentication request applying any applicable configuration on this authenticator.StringresolveDn(User user)This will attempt to find the DN for the supplied user.private LdapEntryresolveEntry(AuthenticationCriteria criteria, AuthenticationHandlerResponse response)Attempts to find the ldap entry for the supplied DN.voidsetAuthenticationHandler(AuthenticationHandler handler)Sets the authentication handler.voidsetDnResolver(DnResolver resolver)Sets the DN resolver.voidsetEntryResolver(EntryResolver resolver)Sets the entry resolver.voidsetRequestHandlers(AuthenticationRequestHandler... handlers)Sets the authentication request handlers.voidsetResolveEntryOnFailure(boolean b)Sets whether to execute the entry resolver on authentication failure.voidsetResponseHandlers(AuthenticationResponseHandler... handlers)Sets the authentication response handlers.voidsetReturnAttributes(String... attrs)Sets the return attributes.StringtoString()private AuthenticationResponsevalidateInput(String dn, AuthenticationRequest request)Validates the authentication request and resolved DN.- 
Methods inherited from class org.ldaptive.AbstractFreezableassertMutable, freeze, freeze, isFrozen
 
- 
 
- 
- 
- 
Field Detail- 
NO_OP_RESOLVERprivate static final EntryResolver NO_OP_RESOLVER NoOp entry resolver.
 - 
loggerprivate final Logger logger Logger for this class.
 - 
dnResolverprivate DnResolver dnResolver For finding user DNs.
 - 
authenticationHandlerprivate AuthenticationHandler authenticationHandler Handler to handle authentication.
 - 
entryResolverprivate EntryResolver entryResolver For finding user entries.
 - 
returnAttributesprivate String[] returnAttributes User attributes to return. Concatenated toAuthenticationRequest.getReturnAttributes().
 - 
requestHandlersprivate AuthenticationRequestHandler[] requestHandlers Handlers to handle authentication requests.
 - 
responseHandlersprivate AuthenticationResponseHandler[] responseHandlers Handlers to handle authentication responses.
 - 
resolveEntryOnFailureprivate boolean resolveEntryOnFailure Whether to execute the entry resolver on authentication failure.
 
- 
 - 
Constructor Detail- 
Authenticatorpublic Authenticator() Default constructor.
 - 
Authenticatorpublic Authenticator(DnResolver resolver, AuthenticationHandler handler) Creates a new authenticator.- Parameters:
- resolver- dn resolver
- handler- authentication handler
 
 
- 
 - 
Method Detail- 
freezepublic void freeze() Description copied from interface:FreezableFreezes this object, making it immutable.- Specified by:
- freezein interface- Freezable
- Overrides:
- freezein class- AbstractFreezable
 
 - 
getDnResolverpublic DnResolver getDnResolver() Returns the DN resolver.- Returns:
- DN resolver
 
 - 
setDnResolverpublic void setDnResolver(DnResolver resolver) Sets the DN resolver.- Parameters:
- resolver- for finding DNs
 
 - 
getAuthenticationHandlerpublic AuthenticationHandler getAuthenticationHandler() Returns the authentication handler.- Returns:
- authentication handler
 
 - 
setAuthenticationHandlerpublic void setAuthenticationHandler(AuthenticationHandler handler) Sets the authentication handler.- Parameters:
- handler- for performing authentication
 
 - 
getEntryResolverpublic EntryResolver getEntryResolver() Returns the entry resolver.- Returns:
- entry resolver
 
 - 
setEntryResolverpublic void setEntryResolver(EntryResolver resolver) Sets the entry resolver.- Parameters:
- resolver- for finding entries
 
 - 
getResolveEntryOnFailurepublic boolean getResolveEntryOnFailure() Returns whether to execute the entry resolver on authentication failure.- Returns:
- whether to execute the entry resolver on authentication failure
 
 - 
setResolveEntryOnFailurepublic void setResolveEntryOnFailure(boolean b) Sets whether to execute the entry resolver on authentication failure.- Parameters:
- b- whether to execute the entry resolver
 
 - 
getReturnAttributespublic String[] getReturnAttributes() Returns the return attributes.- Returns:
- attributes to return
 
 - 
setReturnAttributespublic void setReturnAttributes(String... attrs) Sets the return attributes.- Parameters:
- attrs- return attributes
 
 - 
getRequestHandlerspublic AuthenticationRequestHandler[] getRequestHandlers() Returns the authentication request handlers.- Returns:
- authentication request handlers
 
 - 
setRequestHandlerspublic void setRequestHandlers(AuthenticationRequestHandler... handlers) Sets the authentication request handlers.- Parameters:
- handlers- authentication request handlers
 
 - 
getResponseHandlerspublic AuthenticationResponseHandler[] getResponseHandlers() Returns the authentication response handlers.- Returns:
- authentication response handlers
 
 - 
setResponseHandlerspublic void setResponseHandlers(AuthenticationResponseHandler... handlers) Sets the authentication response handlers.- Parameters:
- handlers- authentication response handlers
 
 - 
resolveDnpublic String resolveDn(User user) throws LdapException This will attempt to find the DN for the supplied user.DnResolver.resolve(User)is invoked to perform this operation.- Parameters:
- user- to find DN for
- Returns:
- user DN
- Throws:
- LdapException- if an LDAP error occurs during resolution
 
 - 
authenticatepublic AuthenticationResponse authenticate(AuthenticationRequest request) throws LdapException Authenticate the user in the supplied request.- Parameters:
- request- authentication request
- Returns:
- response containing the ldap entry of the user authenticated
- Throws:
- LdapException- if an LDAP error occurs
 
 - 
closepublic void close() Attempts to close any connection factories associated with this authenticator. Inspects thednResolver,authenticationHandlerandentryResolverfor typeConnectionFactoryManager. If found, those underlying connection factories are closed.AggregateDnResolver,AggregateAuthenticationHandlerandAggregateEntryResolverare handled as well. Note that custom components that contain connection factories but do not implementConnectionFactoryManagerwill not be closed by this method.
 - 
closeConnectionFactoryManagersprivate void closeConnectionFactoryManagers(Set<ConnectionFactoryManager> managers) Attempts to close all the connection factories in the supplied collection.- Parameters:
- managers- to close connection factories for
 
 - 
authenticateprivate AuthenticationResponse authenticate(String dn, AuthenticationRequest request) throws LdapException Validates input and performs authentication using anAuthenticationHandler. Executes any configuredAuthenticationResponseHandler.- Parameters:
- dn- to authenticate as
- request- containing authentication parameters
- Returns:
- ldap entry for the supplied DN
- Throws:
- LdapException- if an LDAP error occurs
 
 - 
validateInputprivate AuthenticationResponse validateInput(String dn, AuthenticationRequest request) Validates the authentication request and resolved DN. Returns an authentication response if validation failed.- Parameters:
- dn- to validate
- request- to validate
- Returns:
- authentication response if validation failed, otherwise null
 
 - 
processRequestprivate AuthenticationRequest processRequest(String dn, AuthenticationRequest request) throws LdapException Creates a new authentication request applying any applicable configuration on this authenticator. Returns the supplied request if no configuration is applied.- Parameters:
- dn- to process
- request- to process
- Returns:
- authentication request
- Throws:
- LdapException- if an error occurs with a request handler
 
 - 
resolveEntryprivate LdapEntry resolveEntry(AuthenticationCriteria criteria, AuthenticationHandlerResponse response) throws LdapException Attempts to find the ldap entry for the supplied DN. If an entry resolver has been configured it is used. ASearchEntryResolveris used if return attributes have been requested. If none of these criteria is met, aNoOpDnResolveris used.- Parameters:
- criteria- needed by the entry resolver
- response- from the authentication handler
- Returns:
- ldap entry
- Throws:
- LdapException- if an error occurs resolving the entry
 
 - 
builderpublic static Authenticator.Builder builder() Creates a builder for this class.- Returns:
- new builder
 
 
- 
 
-