Package org.ldaptive.auth
Class SearchDnResolver
java.lang.Object
org.ldaptive.AbstractFreezable
org.ldaptive.AbstractOperationFactory<SearchRequest,SearchResponse>
org.ldaptive.AbstractSearchOperationFactory
org.ldaptive.auth.SearchDnResolver
- All Implemented Interfaces:
DnResolver,ConnectionFactoryManager,Freezable
Base implementation for search dn resolvers.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSearch DN resolver builder. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether to throw an exception if multiple DNs are found.private StringDN to search.private DerefAliasesHow to handle aliases.private StringResolve DN from alternative attribute nameprivate booleanWhether to use a subtree search when resolving DNs.private StringFilter for searching for the user.private Object[]Filter parameters for searching for the user.Fields inherited from class org.ldaptive.AbstractOperationFactory
logger -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Creates a new search dn resolver. -
Method Summary
Modifier and TypeMethodDescriptionstatic SearchDnResolver.Builderbuilder()Creates a builder for this class.protected FilterTemplatecreateFilterTemplate(User user) Returns a filter template usinguserFilteranduserFilterParameters.protected SearchRequestcreateSearchRequest(FilterTemplate template) Returns a search request for searching for a single entry in an LDAP, returning no attributes.final booleanReturns whether DN resolution should fail if multiple DNs are found.final StringReturns the base DN.final DerefAliasesReturns how to dereference aliases.final StringGets an attribute to use to resolve the DN, if the attribute is not present the resolution fails back on the entry's DN.final booleanReturns whether subtree searching will be used.final StringReturns the filter used to search for the user.final Object[]Returns the filter parameters used to search for the user.protected SearchResponseperformLdapSearch(FilterTemplate template) Executes the ldap search operation with the supplied filter.protected StringResolve DN from attribute in the resolveFromAttribute property.Attempts to find the DN for the supplied user.protected StringReturns the DN for the supplied ldap entry.final voidsetAllowMultipleDns(boolean b) Sets whether DN resolution should fail if multiple DNs are found.final voidSets the base DN.final voidSets how to dereference aliases.final voidsetResolveFromAttribute(String attributeName) Sets the attribute to use to resolve the DN.final voidsetSubtreeSearch(boolean b) Sets whether subtree searching will be used.final voidsetUserFilter(String filter) Sets the filter used to search for the user.final voidsetUserFilterParameters(Object[] filterParams) Sets the filter parameters used to search for the user.toString()Methods inherited from class org.ldaptive.AbstractSearchOperationFactory
createSearchOperation, createSearchOperation, freeze, getEntryHandlers, getReferenceHandlers, getSearchResultHandlers, setEntryHandlers, setReferenceHandlers, setSearchResultHandlersMethods inherited from class org.ldaptive.AbstractOperationFactory
getConnectionFactory, getControlHandlers, getExceptionHandler, getIntermediateResponseHandlers, getReferralHandlers, getRequestHandlers, getResultHandlers, getThrowCondition, getUnsolicitedNotificationHandlers, initializeOperation, setConnectionFactory, setControlHandlers, setExceptionHandler, setIntermediateResponseHandlers, setReferralHandlers, setRequestHandlers, setResultHandlers, setThrowCondition, setUnsolicitedNotificationHandlersMethods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, isFrozen
-
Field Details
-
baseDn
DN to search. -
userFilter
Filter for searching for the user. -
userFilterParameters
Filter parameters for searching for the user. -
allowMultipleDns
private boolean allowMultipleDnsWhether to throw an exception if multiple DNs are found. -
subtreeSearch
private boolean subtreeSearchWhether to use a subtree search when resolving DNs. -
derefAliases
How to handle aliases. -
resolveFromAttribute
Resolve DN from alternative attribute name
-
-
Constructor Details
-
SearchDnResolver
public SearchDnResolver()Default constructor. -
SearchDnResolver
Creates a new search dn resolver.- Parameters:
cf- connection factory
-
-
Method Details
-
getBaseDn
Returns the base DN.- Returns:
- base DN
-
setBaseDn
Sets the base DN.- Parameters:
dn- base DN
-
getUserFilter
Returns the filter used to search for the user.- Returns:
- filter for searching
-
setUserFilter
Sets the filter used to search for the user.- Parameters:
filter- user filter
-
getUserFilterParameters
Returns the filter parameters used to search for the user.- Returns:
- filter parameters
-
setUserFilterParameters
Sets the filter parameters used to search for the user.- Parameters:
filterParams- filter parameters
-
getAllowMultipleDns
public final boolean getAllowMultipleDns()Returns whether DN resolution should fail if multiple DNs are found.- Returns:
- whether an exception will be thrown if multiple DNs are found
-
setAllowMultipleDns
public final void setAllowMultipleDns(boolean b) Sets whether DN resolution should fail if multiple DNs are found. If false an exception will be thrown ifresolve(User)finds more than one DN matching its filter. Otherwise, the first DN found is returned.- Parameters:
b- whether multiple DNs are allowed
-
getSubtreeSearch
public final boolean getSubtreeSearch()Returns whether subtree searching will be used.- Returns:
- whether the DN will be searched for over the entire base
-
setSubtreeSearch
public final void setSubtreeSearch(boolean b) Sets whether subtree searching will be used. If true, the DN used for authenticating will be searched for over the entiregetBaseDn(). Otherwise, the DN will be searched for in thegetBaseDn()context.- Parameters:
b- whether the DN will be searched for over the entire base
-
getDerefAliases
Returns how to dereference aliases.- Returns:
- how to dereference aliases
-
setDerefAliases
Sets how to dereference aliases.- Parameters:
da- how to dereference aliases
-
getResolveFromAttribute
Gets an attribute to use to resolve the DN, if the attribute is not present the resolution fails back on the entry's DN.- Returns:
- the attribute name
-
setResolveFromAttribute
Sets the attribute to use to resolve the DN. If null, the resolver will use the entry's DN.- Parameters:
attributeName- attribute name
-
resolve
Attempts to find the DN for the supplied user.createFilterTemplate(User)is used to create the search filter. If more than one entry matches the search, the result is controlled bysetAllowMultipleDns(boolean).- Specified by:
resolvein interfaceDnResolver- Parameters:
user- to find DN for- Returns:
- user DN
- Throws:
LdapException- if the entry resolution fails
-
resolveDn
Returns the DN for the supplied ldap entry.- Parameters:
entry- to retrieve the DN from- Returns:
- dn
-
performResolveFromAttribute
Resolve DN from attribute in the resolveFromAttribute property.- Parameters:
entry- containing an attribute with the DN- Returns:
- first and singled value in resolveFromAttribute, or null if not valid
-
createFilterTemplate
Returns a filter template usinguserFilteranduserFilterParameters. The user parameter is injected as a named parameter of 'user'.- Parameters:
user- to resolve DN- Returns:
- filter template
-
createSearchRequest
Returns a search request for searching for a single entry in an LDAP, returning no attributes.- Parameters:
template- to execute- Returns:
- search request
-
performLdapSearch
Executes the ldap search operation with the supplied filter.- Parameters:
template- to execute- Returns:
- ldap search result
- Throws:
LdapException- if an error occurs
-
toString
- Overrides:
toStringin classAbstractSearchOperationFactory
-
builder
Creates a builder for this class.- Returns:
- new builder
-