Package org.ldaptive.auth
Class Authenticator
java.lang.Object
org.ldaptive.AbstractFreezable
org.ldaptive.auth.Authenticator
- All Implemented Interfaces:
Freezable
Provides functionality to authenticate users against an ldap directory.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AuthenticationHandlerHandler to handle authentication.private DnResolverFor finding user DNs.private EntryResolverFor finding user entries.private final LoggerLogger for this class.private static final EntryResolverNoOp entry resolver.private AuthenticationRequestHandler[]Handlers to handle authentication requests.private booleanWhether to execute the entry resolver on authentication failure.private AuthenticationResponseHandler[]Handlers to handle authentication responses.private String[]User attributes to return. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Authenticator(DnResolver resolver, AuthenticationHandler handler) Creates a new authenticator. -
Method Summary
Modifier and TypeMethodDescriptionprivate AuthenticationResponseauthenticate(String dn, AuthenticationRequest request) Validates input and performs authentication using anAuthenticationHandler.authenticate(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 voidAttempts to close all the connection factories in the supplied collection.voidfreeze()Freezes this object, making it immutable.Returns the authentication handler.Returns the DN resolver.Returns the entry resolver.Returns the authentication request handlers.booleanReturns whether to execute the entry resolver on authentication failure.Returns the authentication response handlers.String[]Returns the return attributes.private AuthenticationRequestprocessRequest(String dn, AuthenticationRequest request) Creates a new authentication request applying any applicable configuration on this authenticator.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.voidSets 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.toString()private AuthenticationResponsevalidateInput(String dn, AuthenticationRequest request) Validates the authentication request and resolved DN.Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, isFrozen
-
Field Details
-
NO_OP_RESOLVER
NoOp entry resolver. -
logger
Logger for this class. -
dnResolver
For finding user DNs. -
authenticationHandler
Handler to handle authentication. -
entryResolver
For finding user entries. -
returnAttributes
User attributes to return. Concatenated toAuthenticationRequest.getReturnAttributes(). -
requestHandlers
Handlers to handle authentication requests. -
responseHandlers
Handlers to handle authentication responses. -
resolveEntryOnFailure
private boolean resolveEntryOnFailureWhether to execute the entry resolver on authentication failure.
-
-
Constructor Details
-
Authenticator
public Authenticator()Default constructor. -
Authenticator
Creates a new authenticator.- Parameters:
resolver- dn resolverhandler- authentication handler
-
-
Method Details
-
freeze
public void freeze()Description copied from interface:FreezableFreezes this object, making it immutable.- Specified by:
freezein interfaceFreezable- Overrides:
freezein classAbstractFreezable
-
getDnResolver
Returns the DN resolver.- Returns:
- DN resolver
-
setDnResolver
Sets the DN resolver.- Parameters:
resolver- for finding DNs
-
getAuthenticationHandler
Returns the authentication handler.- Returns:
- authentication handler
-
setAuthenticationHandler
Sets the authentication handler.- Parameters:
handler- for performing authentication
-
getEntryResolver
Returns the entry resolver.- Returns:
- entry resolver
-
setEntryResolver
Sets the entry resolver.- Parameters:
resolver- for finding entries
-
getResolveEntryOnFailure
public boolean getResolveEntryOnFailure()Returns whether to execute the entry resolver on authentication failure.- Returns:
- whether to execute the entry resolver on authentication failure
-
setResolveEntryOnFailure
public void setResolveEntryOnFailure(boolean b) Sets whether to execute the entry resolver on authentication failure.- Parameters:
b- whether to execute the entry resolver
-
getReturnAttributes
Returns the return attributes.- Returns:
- attributes to return
-
setReturnAttributes
Sets the return attributes.- Parameters:
attrs- return attributes
-
getRequestHandlers
Returns the authentication request handlers.- Returns:
- authentication request handlers
-
setRequestHandlers
Sets the authentication request handlers.- Parameters:
handlers- authentication request handlers
-
getResponseHandlers
Returns the authentication response handlers.- Returns:
- authentication response handlers
-
setResponseHandlers
Sets the authentication response handlers.- Parameters:
handlers- authentication response handlers
-
resolveDn
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
-
authenticate
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
-
close
public 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. -
closeConnectionFactoryManagers
Attempts to close all the connection factories in the supplied collection.- Parameters:
managers- to close connection factories for
-
authenticate
private AuthenticationResponse authenticate(String dn, AuthenticationRequest request) throws LdapException Validates input and performs authentication using anAuthenticationHandler. Executes any configuredAuthenticationResponseHandler.- Parameters:
dn- to authenticate asrequest- containing authentication parameters- Returns:
- ldap entry for the supplied DN
- Throws:
LdapException- if an LDAP error occurs
-
validateInput
Validates the authentication request and resolved DN. Returns an authentication response if validation failed.- Parameters:
dn- to validaterequest- to validate- Returns:
- authentication response if validation failed, otherwise null
-
processRequest
private 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 processrequest- to process- Returns:
- authentication request
- Throws:
LdapException- if an error occurs with a request handler
-
resolveEntry
private 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 resolverresponse- from the authentication handler- Returns:
- ldap entry
- Throws:
LdapException- if an error occurs resolving the entry
-
toString
-
builder
Creates a builder for this class.- Returns:
- new builder
-