Package org.ldaptive.auth
Class SearchDnResolver
- java.lang.Object
-
- org.ldaptive.AbstractSearchOperationFactory
-
- org.ldaptive.auth.SearchDnResolver
-
- All Implemented Interfaces:
DnResolver,ConnectionFactoryManager
public class SearchDnResolver extends AbstractSearchOperationFactory implements DnResolver
Base implementation for search dn resolvers.- Author:
- Middleware Services
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSearchDnResolver.BuilderSearch DN resolver builder.
-
Field Summary
-
Fields inherited from class org.ldaptive.AbstractSearchOperationFactory
logger
-
-
Constructor Summary
Constructors Constructor Description SearchDnResolver()Default constructor.SearchDnResolver(ConnectionFactory cf)Creates a new search dn resolver.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static 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.booleangetAllowMultipleDns()Returns whether DN resolution should fail if multiple DNs are found.java.lang.StringgetBaseDn()Returns the base DN.DerefAliasesgetDerefAliases()Returns how to dereference aliases.java.lang.StringgetResolveFromAttribute()Gets an attribute to use to resolve the DN, if the attribute is not present the resolution fails back on the entry's DN.booleangetSubtreeSearch()Returns whether subtree searching will be used.java.lang.StringgetUserFilter()Returns the filter used to search for the user.java.lang.Object[]getUserFilterParameters()Returns the filter parameters used to search for the user.protected SearchResponseperformLdapSearch(FilterTemplate template)Executes the ldap search operation with the supplied filter.protected java.lang.StringperformResolveFromAttribute(LdapEntry entry)Resolve DN from attribute in the resolveFromAttribute property.java.lang.Stringresolve(User user)Attempts to find the DN for the supplied user.protected java.lang.StringresolveDn(LdapEntry entry)Returns the DN for the supplied ldap entry.voidsetAllowMultipleDns(boolean b)Sets whether DN resolution should fail if multiple DNs are found.voidsetBaseDn(java.lang.String dn)Sets the base DN.voidsetDerefAliases(DerefAliases da)Sets how to dereference aliases.voidsetResolveFromAttribute(java.lang.String attributeName)Sets the attribute to use to resolve the DN.voidsetSubtreeSearch(boolean b)Sets whether subtree searching will be used.voidsetUserFilter(java.lang.String filter)Sets the filter used to search for the user.voidsetUserFilterParameters(java.lang.Object[] filterParams)Sets the filter parameters used to search for the user.java.lang.StringtoString()-
Methods inherited from class org.ldaptive.AbstractSearchOperationFactory
createSearchOperation, createSearchOperation, getConnectionFactory, getEntryHandlers, getExceptionHandler, getResultHandlers, getSearchResultHandlers, setConnectionFactory, setEntryHandlers, setExceptionHandler, setResultHandlers, setSearchResultHandlers
-
-
-
-
Constructor Detail
-
SearchDnResolver
public SearchDnResolver()
Default constructor.
-
SearchDnResolver
public SearchDnResolver(ConnectionFactory cf)
Creates a new search dn resolver.- Parameters:
cf- connection factory
-
-
Method Detail
-
getBaseDn
public java.lang.String getBaseDn()
Returns the base DN.- Returns:
- base DN
-
setBaseDn
public void setBaseDn(java.lang.String dn)
Sets the base DN.- Parameters:
dn- base DN
-
getUserFilter
public java.lang.String getUserFilter()
Returns the filter used to search for the user.- Returns:
- filter for searching
-
setUserFilter
public void setUserFilter(java.lang.String filter)
Sets the filter used to search for the user.- Parameters:
filter- user filter
-
getUserFilterParameters
public java.lang.Object[] getUserFilterParameters()
Returns the filter parameters used to search for the user.- Returns:
- filter parameters
-
setUserFilterParameters
public void setUserFilterParameters(java.lang.Object[] filterParams)
Sets the filter parameters used to search for the user.- Parameters:
filterParams- filter parameters
-
getAllowMultipleDns
public 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 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 it's filter. Otherwise the first DN found is returned.- Parameters:
b- whether multiple DNs are allowed
-
getSubtreeSearch
public boolean getSubtreeSearch()
Returns whether subtree searching will be used.- Returns:
- whether the DN will be searched for over the entire base
-
setSubtreeSearch
public 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
public DerefAliases getDerefAliases()
Returns how to dereference aliases.- Returns:
- how to dereference aliases
-
setDerefAliases
public void setDerefAliases(DerefAliases da)
Sets how to dereference aliases.- Parameters:
da- how to dereference aliases
-
getResolveFromAttribute
public java.lang.String 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
public void setResolveFromAttribute(java.lang.String attributeName)
Sets the attribute to use to resolve the DN. If null, the resolver will use the entry's DN.- Parameters:
attributeName- attribute name
-
resolve
public java.lang.String resolve(User user) throws LdapException
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
protected java.lang.String resolveDn(LdapEntry entry)
Returns the DN for the supplied ldap entry.- Parameters:
entry- to retrieve the DN from- Returns:
- dn
-
performResolveFromAttribute
protected java.lang.String performResolveFromAttribute(LdapEntry entry)
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
protected FilterTemplate createFilterTemplate(User user)
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
protected SearchRequest createSearchRequest(FilterTemplate template)
Returns a search request for searching for a single entry in an LDAP, returning no attributes.- Parameters:
template- to execute- Returns:
- search request
-
performLdapSearch
protected SearchResponse performLdapSearch(FilterTemplate template) throws LdapException
Executes the ldap search operation with the supplied filter.- Parameters:
template- to execute- Returns:
- ldap search result
- Throws:
LdapException- if an error occurs
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
builder
public static SearchDnResolver.Builder builder()
Creates a builder for this class.- Returns:
- new builder
-
-