Class LdapTemplate
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
,LdapOperations
Note for Active Directory (AD) users: AD servers are apparently unable to handle
referrals automatically, which causes a PartialResultException
to be
thrown whenever a referral is encountered in a search. To avoid this, set the
ignorePartialResultException
property to true
. There is
currently no way of manually handling these referrals in the form of
ReferralException
, i.e. either you get the exception (and your results are
lost) or all referrals are ignored (if the server is unable to handle them properly.
Neither is there any simple way to get notified that a
PartialResultException
has been ignored (other than in the log).
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
ANameClassPairCallbackHandler
that passes the NameClassPairs found to a NameClassPairMapper and collects the results in a list.static final class
Do-nothing implementation ofDirContextProcessor
. -
Constructor Summary
ConstructorDescriptionConstructor for bean usage.LdapTemplate
(ContextSource contextSource) Constructor to setup instance directly. -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
authenticate
(String base, String filter, String password) Utility method to perform a simple LDAP 'bind' authentication.boolean
authenticate
(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) Utility method to perform a simple LDAP 'bind' authentication.boolean
authenticate
(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication.boolean
authenticate
(String base, String filter, String password, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication.boolean
authenticate
(Name base, String filter, String password) Utility method to perform a simple LDAP 'bind' authentication.boolean
authenticate
(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) Utility method to perform a simple LDAP 'bind' authentication.boolean
authenticate
(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication.boolean
authenticate
(Name base, String filter, String password, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication.void
authenticate
(LdapQuery query, String password) Utility method to perform a simple LDAP 'bind' authentication.<T> T
authenticate
(LdapQuery query, String password, AuthenticatedLdapEntryContextMapper<T> mapper) Utility method to perform a simple LDAP 'bind' authentication.void
bind
(String dn, Object obj, Attributes attributes) Create an entry in the LDAP tree.void
bind
(Name dn, Object obj, Attributes attributes) Create an entry in the LDAP tree.void
bind
(DirContextOperations ctx) Bind the data in the supplied context in the tree.void
Create the given entry in the LDAP directory.void
Delete an entry from the LDAP directory.protected void
deleteRecursively
(DirContext ctx, Name name) Delete all subcontexts including the current one recursively.<T> T
executeReadOnly
(ContextExecutor<T> ce) Perform an operation (or series of operations) on a read-only context.<T> T
executeReadWrite
(ContextExecutor<T> ce) Perform an operation (or series of operations) on a read-write context.<T> List<T>
find
(Name base, Filter filter, SearchControls searchControls, Class<T> clazz) Find all entries in the LDAP directory of a given type that matches the specified filter.<T> List<T>
Search for entries in the LDAP directory.<T> List<T>
Find all entries in the LDAP directory of a given type.<T> List<T>
findAll
(Name base, SearchControls searchControls, Class<T> clazz) Find all entries in the LDAP directory of a given type.<T> T
Read a named entry from the LDAP directory.<T> Stream<T>
findForStream
(LdapQuery query, Class<T> clazz) Search for entries in the LDAP directory.<T> T
Search for objects in the directory tree matching the specified LdapQuery, expecting to find exactly one match.Get the ContextSource.Get the configured ObjectDirectoryMapper.Perform a non-recursive listing of the children of the givenbase
.void
list
(String base, NameClassPairCallbackHandler handler) Perform a non-recursive listing of the children of the givenbase
.<T> List<T>
list
(String base, NameClassPairMapper<T> mapper) Perform a non-recursive listing of the children of the givenbase
.Perform a non-recursive listing of the children of the givenbase
.void
list
(Name base, NameClassPairCallbackHandler handler) Perform a non-recursive listing of the children of the givenbase
.<T> List<T>
list
(Name base, NameClassPairMapper<T> mapper) Perform a non-recursive listing of the children of the givenbase
.listBindings
(String base) Perform a non-recursive listing of children of the givenbase
.<T> List<T>
listBindings
(String base, ContextMapper<T> mapper) Perform a non-recursive listing of the children of the givenbase
.void
listBindings
(String base, NameClassPairCallbackHandler handler) Perform a non-recursive listing of the children of the givenbase
.<T> List<T>
listBindings
(String base, NameClassPairMapper<T> mapper) Perform a non-recursive listing of the children of the givenbase
.listBindings
(Name base) Perform a non-recursive listing of children of the givenbase
.<T> List<T>
listBindings
(Name base, ContextMapper<T> mapper) Perform a non-recursive listing of the children of the givenbase
.void
listBindings
(Name base, NameClassPairCallbackHandler handler) Perform a non-recursive listing of the children of the givenbase
.<T> List<T>
listBindings
(Name base, NameClassPairMapper<T> mapper) Perform a non-recursive listing of the children of the givenbase
.Lookup the supplied DN and return the found object.<T> T
lookup
(String dn, String[] attributes, AttributesMapper<T> mapper) Convenience method to get the specified attributes of a specified DN and automatically pass them to anAttributesMapper
.<T> T
lookup
(String dn, String[] attributes, ContextMapper<T> mapper) Convenience method to get the specified attributes of a specified DN and automatically pass them to aContextMapper
.<T> T
lookup
(String dn, AttributesMapper<T> mapper) Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper
.<T> T
lookup
(String dn, ContextMapper<T> mapper) Convenience method to lookup a specified DN and automatically pass the found object to aContextMapper
.Lookup the supplied DN and return the found object.<T> T
lookup
(Name dn, String[] attributes, AttributesMapper<T> mapper) Convenience method to get the specified attributes of a specified DN and automatically pass them to anAttributesMapper
.<T> T
lookup
(Name dn, String[] attributes, ContextMapper<T> mapper) Convenience method to get the specified attributes of a specified DN and automatically pass them to aContextMapper
.<T> T
lookup
(Name dn, AttributesMapper<T> mapper) Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper
.<T> T
lookup
(Name dn, ContextMapper<T> mapper) Convenience method to lookup a specified DN and automatically pass the found object to aContextMapper
.lookupContext
(String dn) Convenience method to lookup the supplied DN and automatically cast it toDirContextOperations
.lookupContext
(Name dn) Convenience method to lookup the supplied DN and automatically cast it toDirContextOperations
.void
modifyAttributes
(String dn, ModificationItem[] mods) Modify an entry in the LDAP tree using the suppliedModificationItems
.void
modifyAttributes
(Name dn, ModificationItem[] mods) Modify an entry in the LDAP tree using the suppliedModificationItems
.void
Modify the attributes of the entry referenced by the suppliedDirContextOperations
instance.void
rebind
(String dn, Object obj, Attributes attributes) Remove an entry and replace it with a new one.void
rebind
(Name dn, Object obj, Attributes attributes) Remove an entry and replace it with a new one.void
Remove an entry and replace it with a new one.void
Move an entry in the LDAP tree to a new location.void
Move an entry in the LDAP tree to a new location.void
search
(String base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, int searchScope, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, int searchScope, ContextMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, SearchControls controls, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, SearchControls controls, ContextMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter.void
search
(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.void
search
(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(String base, String filter, ContextMapper<T> mapper) Search for all objects matching the supplied filter.void
search
(String base, String filter, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.void
search
(Name base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, int searchScope, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, int searchScope, ContextMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, SearchControls controls, ContextMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter.void
search
(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.void
search
(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, AttributesMapper<T> mapper) Search for all objects matching the supplied filter.<T> List<T>
search
(Name base, String filter, ContextMapper<T> mapper) Search for all objects matching the supplied filter.void
search
(Name base, String filter, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.void
search
(SearchExecutor se, NameClassPairCallbackHandler handler) Perform a search operation, such as a search(), list() or listBindings().void
search
(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor) Perform a search operation, such as a search(), list() or listBindings().<T> List<T>
search
(LdapQuery query, AttributesMapper<T> mapper) Perform a search with parameters from the specified LdapQuery.<T> List<T>
search
(LdapQuery query, ContextMapper<T> mapper) Perform a search with parameters from the specified LdapQuery.void
search
(LdapQuery query, NameClassPairCallbackHandler callbackHandler) Perform a search with parameters from the specified LdapQuery.searchForContext
(LdapQuery query) Perform a search for a unique entry matching the specified LDAP query and return the found entry as a DirContextOperation instance.<T> T
searchForObject
(String base, String filter, SearchControls searchControls, ContextMapper<T> mapper) Perform a search for a unique entry matching the specified search criteria and return the found object.<T> T
searchForObject
(String base, String filter, ContextMapper<T> mapper) Perform a search for a unique entry matching the specified search criteria and return the found object.<T> T
searchForObject
(Name base, String filter, SearchControls searchControls, ContextMapper<T> mapper) Perform a search for a unique entry matching the specified search criteria and return the found object.<T> T
searchForObject
(Name base, String filter, ContextMapper<T> mapper) Perform a search for a unique entry matching the specified search criteria and return the found object.<T> T
searchForObject
(LdapQuery query, ContextMapper<T> mapper) Perform a search for a unique entry matching the specified LDAP query and return the found object.<T> Stream<T>
searchForStream
(LdapQuery query, AttributesMapper<T> attributesMapper) Perform a search with parameters from the specified LdapQuery.<T> Stream<T>
searchForStream
(LdapQuery query, ContextMapper<T> mapper) Perform a search with parameters from the specified LdapQuery.void
setContextSource
(ContextSource contextSource) Set the ContextSource.void
setDefaultCountLimit
(int defaultCountLimit) Set the default count limit be used in searches if not explicitly specified.void
setDefaultSearchScope
(int defaultSearchScope) Set the default scope to be used in searches if not explicitly specified.void
setDefaultTimeLimit
(int defaultTimeLimit) Set the default time limit be used in searches if not explicitly specified.void
setIgnoreNameNotFoundException
(boolean ignore) Specify whetherNameNotFoundException
should be ignored in searches.void
setIgnorePartialResultException
(boolean ignore) Specify whetherPartialResultException
should be ignored in searches.void
setIgnoreSizeLimitExceededException
(boolean ignore) Specify whetherSizeLimitExceededException
should be ignored in searches.void
Set the ObjectDirectoryMapper instance to use.void
Remove an entry from the LDAP tree.void
Remove an entry from the LDAP tree, optionally removing all descendants in the process.void
Remove an entry from the LDAP tree.void
Remove an entry from the LDAP tree, optionally removing all descendants in the process.void
Update the given entry in the LDAP directory.
-
Constructor Details
-
LdapTemplate
public LdapTemplate()Constructor for bean usage. -
LdapTemplate
Constructor to setup instance directly.- Parameters:
contextSource
- the ContextSource to use.
-
-
Method Details
-
setContextSource
Set the ContextSource. Call this method when the default constructor has been used.- Parameters:
contextSource
- the ContextSource.
-
getObjectDirectoryMapper
Get the configured ObjectDirectoryMapper. For internal use.- Specified by:
getObjectDirectoryMapper
in interfaceLdapOperations
- Returns:
- the configured ObjectDirectoryMapper.
-
setObjectDirectoryMapper
Set the ObjectDirectoryMapper instance to use.- Parameters:
odm
- the ObejctDirectoryMapper to use.- Since:
- 2.0
-
getContextSource
Get the ContextSource.- Returns:
- the ContextSource.
-
setIgnoreNameNotFoundException
public void setIgnoreNameNotFoundException(boolean ignore) Specify whetherNameNotFoundException
should be ignored in searches. In previous version,NameNotFoundException
caused by the search base not being found was silently ignored. The default behavior is now to treat this as an error (as it should), and to convert and re-throw the exception. The ability to revert to the previous behavior still exists. The only difference is that the incident is in that case no longer silently ignored, but logged as a warning.- Parameters:
ignore
-true
ifNameNotFoundException
should be ignored in searches,false
otherwise. Default isfalse
.- Since:
- 1.3
-
setIgnorePartialResultException
public void setIgnorePartialResultException(boolean ignore) Specify whetherPartialResultException
should be ignored in searches. AD servers typically have a problem with referrals. Normally a referral should be followed automatically, but this does not seem to work with AD servers. The problem manifests itself with aPartialResultException
being thrown when a referral is encountered by the server. Setting this property totrue
presents a workaround to this problem by causingPartialResultException
to be ignored, so that the search method returns normally. Default value of this parameter isfalse
.- Parameters:
ignore
-true
ifPartialResultException
should be ignored in searches,false
otherwise. Default isfalse
.
-
setIgnoreSizeLimitExceededException
public void setIgnoreSizeLimitExceededException(boolean ignore) Specify whetherSizeLimitExceededException
should be ignored in searches. This is typically what you want if you specify count limit in your search controls.- Parameters:
ignore
-true
ifSizeLimitExceededException
should be ignored in searches,false
otherwise. Default istrue
.- Since:
- 2.0
-
setDefaultSearchScope
public void setDefaultSearchScope(int defaultSearchScope) Set the default scope to be used in searches if not explicitly specified. Default isSearchControls.SUBTREE_SCOPE
.- Parameters:
defaultSearchScope
- the default search scope to use in searches. One ofSearchControls.OBJECT_SCOPE
,SearchControls.ONELEVEL_SCOPE
, orSearchControls.SUBTREE_SCOPE
- Since:
- 2.0
-
setDefaultTimeLimit
public void setDefaultTimeLimit(int defaultTimeLimit) Set the default time limit be used in searches if not explicitly specified. Default is 0, indicating no time limit.- Parameters:
defaultTimeLimit
- the default time limit to use in searches.- Since:
- 2.0
-
setDefaultCountLimit
public void setDefaultCountLimit(int defaultCountLimit) Set the default count limit be used in searches if not explicitly specified. Default is 0, indicating no count limit.- Parameters:
defaultCountLimit
- the default count limit to use in searches.- Since:
- 2.0
-
search
public void search(Name base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter. EachSearchResult
is supplied to the specifiedNameClassPairCallbackHandler
. Use the specified values for search scope and return objects flag.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.returningObjFlag
- Whether the bound object should be returned in search results. Must be set totrue
if aContextMapper
is used.handler
- TheNameClassPairCallbackHandler
to supply theSearchResults
to.
-
search
public void search(String base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter. EachSearchResult
is supplied to the specifiedNameClassPairCallbackHandler
. Use the specified values for search scope and return objects flag.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.returningObjFlag
- Whether the bound object should be returned in search results. Must be set totrue
if aContextMapper
is used.handler
- TheNameClassPairCallbackHandler
to supply theSearchResults
to.
-
search
public void search(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter. EachSearchResult
is supplied to the specifiedNameClassPairCallbackHandler
. TheSearchScope
specified in the suppliedSearchControls
will be used in the search. Note that if you are using aContextMapper
, the returningObjFlag needs to be set to true in theSearchControls
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResult
to.
-
search
public void search(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter. SeeLdapOperations.search(Name, String, SearchControls, NameClassPairCallbackHandler)
for details.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResult
to.
-
search
public void search(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor) Search for all objects matching the supplied filter. EachSearchResult
is supplied to the specifiedNameClassPairCallbackHandler
. TheSearchScope
specified in the suppliedSearchControls
will be used in the search. Note that if you are using aContextMapper
, the returningObjFlag needs to be set to true in theSearchControls
. The givenDirContextProcessor
will be called before and after the search.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResult
to.processor
- TheDirContextProcessor
to use before and after the search.
-
search
public void search(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor) Search for all objects matching the supplied filter. SeeLdapOperations.search(Name, String, SearchControls, NameClassPairCallbackHandler, DirContextProcessor)
for details.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResults
to.processor
- TheDirContextProcessor
to use before and after the search.
-
search
public void search(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor) Perform a search operation, such as a search(), list() or listBindings(). This method handles all the plumbing; getting a readonly context; looping through the NamingEnumeration and closing the context and enumeration. It also calls the supplied DirContextProcessor before and after the search, respectively. This enables custom pre-processing and post-processing, like for example when handling paged results or other search controls.The actual list is delegated to the
SearchExecutor
and eachNameClassPair
(this might be a NameClassPair or a subclass thereof) is passed to the CallbackHandler. Any encountered NamingException will be translated using the NamingExceptionTranslator.- Specified by:
search
in interfaceLdapOperations
- Parameters:
se
- the SearchExecutor to use for performing the actual list.handler
- the NameClassPairCallbackHandler to which each found entry will be passed.processor
- DirContextProcessor for custom pre- and post-processing. Must not benull
. If no custom processing should take place, please use e.g.search(SearchExecutor, NameClassPairCallbackHandler)
.- Throws:
NamingException
- if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.
-
search
Perform a search operation, such as a search(), list() or listBindings(). This method handles all the plumbing; getting a readonly context; looping through the NamingEnumeration and closing the context and enumeration.The actual list is delegated to the
SearchExecutor
and eachNameClassPair
(this might be a NameClassPair or a subclass thereof) is passed to the CallbackHandler. Any encountered NamingException will be translated using the NamingExceptionTranslator.- Specified by:
search
in interfaceLdapOperations
- Parameters:
se
- the SearchExecutor to use for performing the actual list.handler
- the NameClassPairCallbackHandler to which each found entry will be passed.- Throws:
NamingException
- if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.- See Also:
-
search
Search for all objects matching the supplied filter. EachSearchResult
is supplied to the specifiedNameClassPairCallbackHandler
. The default Search scope (SearchControls.SUBTREE_SCOPE
) will be used and the returnObjects flag will be set tofalse
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResults
to.
-
search
Search for all objects matching the supplied filter. EachSearchResult
is supplied to the specifiedNameClassPairCallbackHandler
. The default Search scope (SearchControls.SUBTREE_SCOPE
) will be used and the returnObjects flag will be set tofalse
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResults
to.
-
search
public <T> List<T> search(Name base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper) Search for all objects matching the supplied filter. Only return any attributes mathing the specified attribute names. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.attrs
- The attributes to return,null
means returning all attributes.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
public <T> List<T> search(String base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper) Search for all objects matching the supplied filter. Only return any attributes mathing the specified attribute names. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.attrs
- The attributes to return,null
means returning all attributes.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
. The default search scope will be used.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
. The default search scope will be used.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
public <T> List<T> search(Name base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper) Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
. Only return the supplied attributes.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.attrs
- The attributes to return,null
means all attributes.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
public <T> List<T> search(String base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper) Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
. Only return the supplied attributes.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.attrs
- The attributes to return,null
means all attributes.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.searchScope
- The search scope to set inSearchControls
.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
. The default search scope (SearchControls.SUBTREE_SCOPE
) will be used.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
. The default search scope (SearchControls.SUBTREE_SCOPE
) will be used.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
public <T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper) Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
. The default search scope (SearchControls.SUBTREE_SCOPE
) will be used.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
public <T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper) Search for all objects matching the supplied filter. The Object returned in eachSearchResult
is supplied to the specifiedContextMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search. If the returnObjFlag is not set in theSearchControls
, this method will set it automatically, as this is required for theContextMapper
to work.mapper
- TheContextMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
public <T> List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper) Search for all objects matching the supplied filter. The Attributes returned in eachSearchResult
is supplied to the specifiedAttributesMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
public <T> List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper) Search for all objects matching the supplied filter. The Attributes returned in eachSearchResult
is supplied to the specifiedAttributesMapper
.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.mapper
- TheAttributesMapper
to use for translating each entry.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
public <T> List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
. TheSearchScope
specified in the suppliedSearchControls
will be used in the search. The givenDirContextProcessor
will be called before and after the search.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.mapper
- TheAttributesMapper
to use for translating each entry.processor
- TheDirContextProcessor
to use before and after the search.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
public <T> List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
. TheSearchScope
specified in the suppliedSearchControls
will be used in the search. The givenDirContextProcessor
will be called before and after the search.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search.mapper
- TheAttributesMapper
to use for translating each entry.processor
- TheDirContextProcessor
to use before and after the search.- Returns:
- a
List
containing all entries received from theAttributesMapper
.
-
search
public <T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter. The Object returned in eachSearchResult
is supplied to the specifiedContextMapper
. TheSearchScope
specified in the suppliedSearchControls
will be used in the search. The givenDirContextProcessor
will be called before and after the search.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search. If the returnObjFlag is not set in theSearchControls
, this method will set it automatically, as this is required for theContextMapper
to work.mapper
- TheContextMapper
to use for translating each entry.processor
- TheDirContextProcessor
to use before and after the search.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
search
public <T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor) Search for all objects matching the supplied filter. The Object returned in eachSearchResult
is supplied to the specifiedContextMapper
. TheSearchScope
specified in the suppliedSearchControls
will be used in the search. The givenDirContextProcessor
will be called before and after the search.- Specified by:
search
in interfaceLdapOperations
- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.controls
- TheSearchControls
to use in the search. If the returnObjFlag is not set in theSearchControls
, this method will set it automatically, as this is required for theContextMapper
to work.mapper
- TheContextMapper
to use for translating each entry.processor
- TheDirContextProcessor
to use before and after the search.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
list
Perform a non-recursive listing of the children of the givenbase
. Each resultingNameClassPair
is supplied to the specifiedNameClassPairCallbackHandler
.- Specified by:
list
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachNameClassPair
to.
-
list
Perform a non-recursive listing of the children of the givenbase
. Each resultingNameClassPair
is supplied to the specifiedNameClassPairCallbackHandler
.- Specified by:
list
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachNameClassPair
to.
-
list
Perform a non-recursive listing of the children of the givenbase
. Pass all the foundNameClassPair
objects to the suppliedNameClassPairMapper
and return all the returned values as aList
.- Specified by:
list
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.mapper
- TheNameClassPairMapper
to supply eachNameClassPair
to.- Returns:
- a
List
containing the Objects returned from the Mapper.
-
list
Perform a non-recursive listing of the children of the givenbase
. Pass all the foundNameClassPair
objects to the suppliedNameClassPairMapper
and return all the returned values as aList
.- Specified by:
list
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.mapper
- TheNameClassPairMapper
to supply eachNameClassPair
to.- Returns:
- a
List
containing the Objects returned from the Mapper.
-
list
Perform a non-recursive listing of the children of the givenbase
.- Specified by:
list
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a List containing the names of all the contexts bound to
base
.
-
list
Perform a non-recursive listing of the children of the givenbase
.- Specified by:
list
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a List containing the names of all the contexts bound to
base
.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. Each resultingBinding
is supplied to the specifiedNameClassPairCallbackHandler
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachBinding
to.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. Each resultingBinding
is supplied to the specifiedNameClassPairCallbackHandler
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachBinding
to.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. Pass all the foundBinding
objects to the suppliedNameClassPairMapper
and return all the returned values as aList
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.mapper
- TheNameClassPairMapper
to supply eachBinding
to.- Returns:
- a
List
containing the Objects returned from the Mapper.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. Pass all the foundBinding
objects to the suppliedNameClassPairMapper
and return all the returned values as aList
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.mapper
- TheNameClassPairMapper
to supply eachBinding
to.- Returns:
- a
List
containing the Objects returned from the Mapper.
-
listBindings
Perform a non-recursive listing of children of the givenbase
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a
List
containing the names of all the contexts bound tobase
.
-
listBindings
Perform a non-recursive listing of children of the givenbase
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a
List
containing the names of all the contexts bound tobase
.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. The Object returned in eachBinding
is supplied to the specifiedContextMapper
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. The Object returned in eachBinding
is supplied to the specifiedContextMapper
.- Specified by:
listBindings
in interfaceLdapOperations
- Parameters:
base
- The base DN where the list should be performed.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- a
List
containing all entries received from theContextMapper
.
-
executeReadOnly
Perform an operation (or series of operations) on a read-only context. This method handles the plumbing - getting aDirContext
, translating any Exceptions and closing the context afterwards. This method is not intended for searches; useLdapOperations.search(SearchExecutor, NameClassPairCallbackHandler)
or any of the overloaded search methods for this.- Specified by:
executeReadOnly
in interfaceLdapOperations
- Parameters:
ce
- TheContextExecutor
to which the actual operation on theDirContext
will be delegated.- Returns:
- the result from the ContextExecutor's operation.
- See Also:
-
executeReadWrite
Perform an operation (or series of operations) on a read-write context. This method handles the plumbing - getting aDirContext
, translating any exceptions and closing the context afterwards. This method is intended only for very particular cases, where there is no suitable method in this interface to use.- Specified by:
executeReadWrite
in interfaceLdapOperations
- Parameters:
ce
- TheContextExecutor
to which the actual operation on theDirContext
will be delegated.- Returns:
- the result from the ContextExecutor's operation.
- See Also:
-
lookup
Lookup the supplied DN and return the found object. This will typically be aDirContextAdapter
, unless theDirObjectFactory
has been modified in theContextSource
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- the found object, typically a
DirContextAdapter
instance. - See Also:
-
lookup
Lookup the supplied DN and return the found object. This will typically be aDirContextAdapter
, unless theDirObjectFactory
has been modified in theContextSource
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- the found object, typically a
DirContextAdapter
instance. - See Also:
-
lookup
Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.mapper
- TheAttributesMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
lookup
Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.mapper
- TheAttributesMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
lookup
Convenience method to lookup a specified DN and automatically pass the found object to aContextMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
lookup
Convenience method to lookup a specified DN and automatically pass the found object to aContextMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to anAttributesMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.attributes
- The names of the attributes to pass to the mapper.mapper
- TheAttributesMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to anAttributesMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.attributes
- The names of the attributes to pass to the mapper.mapper
- TheAttributesMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to aContextMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.attributes
- The names of the attributes to pass to the mapper.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to aContextMapper
.- Specified by:
lookup
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to find.attributes
- The names of the attributes to pass to the mapper.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
-
modifyAttributes
Modify an entry in the LDAP tree using the suppliedModificationItems
.- Specified by:
modifyAttributes
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name of the node to modify.mods
- The modifications to perform.- See Also:
-
modifyAttributes
Modify an entry in the LDAP tree using the suppliedModificationItems
.- Specified by:
modifyAttributes
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name of the node to modify.mods
- The modifications to perform.- See Also:
-
bind
Create an entry in the LDAP tree. The attributes used to create the entry are either retrieved from theobj
parameter or theattributes
parameter (or both). One of these parameters may benull
but not both.- Specified by:
bind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to bind the object and attributes to.obj
- The object to bind, may benull
. Typically aDirContext
implementation.attributes
- The attributes to bind, may benull
.- See Also:
-
bind
Create an entry in the LDAP tree. The attributes used to create the entry are either retrieved from theobj
parameter or theattributes
parameter (or both). One of these parameters may benull
but not both.- Specified by:
bind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to bind the object and attributes to.obj
- The object to bind, may benull
. Typically aDirContext
implementation.attributes
- The attributes to bind, may benull
.- See Also:
-
unbind
Remove an entry from the LDAP tree. The entry must not have any children - if you suspect that the entry might have descendants, useLdapOperations.unbind(Name, boolean)
in stead.- Specified by:
unbind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name of the entry to remove.
-
unbind
Remove an entry from the LDAP tree. The entry must not have any children - if you suspect that the entry might have descendants, useLdapOperations.unbind(Name, boolean)
in stead.- Specified by:
unbind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to unbind.
-
unbind
Remove an entry from the LDAP tree, optionally removing all descendants in the process.- Specified by:
unbind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to unbind.recursive
- Whether to unbind all subcontexts as well. If this parameter isfalse
and the entry has children, the operation will fail.
-
unbind
Remove an entry from the LDAP tree, optionally removing all descendants in the process.- Specified by:
unbind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to unbind.recursive
- Whether to unbind all subcontexts as well. If this parameter isfalse
and the entry has children, the operation will fail.
-
deleteRecursively
Delete all subcontexts including the current one recursively.- Parameters:
ctx
- The context to use for deleting.name
- The starting point to delete recursively.- Throws:
NamingException
- if any error occurs
-
rebind
Remove an entry and replace it with a new one. The attributes used to create the entry are either retrieved from theobj
parameter or theattributes
parameter (or both). One of these parameters may benull
but not both. This method assumes that the specified context already exists - if not it will fail.- Specified by:
rebind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to rebind.obj
- The object to bind to the DN, may benull
. Typically aDirContext
implementation.attributes
- The attributes to bind, may benull
.- See Also:
-
rebind
Remove an entry and replace it with a new one. The attributes used to create the entry are either retrieved from theobj
parameter or theattributes
parameter (or both). One of these parameters may benull
but not both. This method assumes that the specified context already exists - if not it will fail.- Specified by:
rebind
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name to rebind.obj
- The object to bind to the DN, may benull
. Typically aDirContext
implementation.attributes
- The attributes to bind, may benull
.- See Also:
-
rename
Move an entry in the LDAP tree to a new location.- Specified by:
rename
in interfaceLdapOperations
- Parameters:
oldDn
- The distinguished name of the entry to move; may not benull
or empty.newDn
- The distinguished name where the entry should be moved; may not benull
or empty.
-
rename
Move an entry in the LDAP tree to a new location.- Specified by:
rename
in interfaceLdapOperations
- Parameters:
oldDn
- The distinguished name of the entry to move; may not benull
or empty.newDn
- The distinguished name where the entry should be moved; may not benull
or empty.
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
lookupContext
Convenience method to lookup the supplied DN and automatically cast it toDirContextOperations
.- Specified by:
lookupContext
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- The found object, cast to
DirContextOperations
. - See Also:
-
lookupContext
Convenience method to lookup the supplied DN and automatically cast it toDirContextOperations
.- Specified by:
lookupContext
in interfaceLdapOperations
- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- The found object, cast to
DirContextOperations
. - See Also:
-
modifyAttributes
Modify the attributes of the entry referenced by the suppliedDirContextOperations
instance. The DN to update will be the DN of theDirContextOperations
instance, and theModificationItem
array is retrieved from theDirContextOperations
instance using a call toAttributeModificationsAware.getModificationItems()
. NB: The supplied instance needs to have been properly initialized; this means that if it hasn't been received from alookup
operation, its DN needs to be initialized and it must have been put in update mode (DirContextAdapter.setUpdateMode(boolean)
).Typical use of this method would be as follows:
public void update(Person person) { DirContextOperations ctx = ldapOperations.lookupContext(person.getDn()); ctx.setAttributeValue("description", person.getDescription()); ctx.setAttributeValue("telephoneNumber", person.getPhone()); // More modifications here ldapOperations.modifyAttributes(ctx); }
- Specified by:
modifyAttributes
in interfaceLdapOperations
- Parameters:
ctx
- the DirContextOperations instance to use in the update.- See Also:
-
bind
Bind the data in the supplied context in the tree. All specified attributesctx
in will be bound to the DN set onctx
.Example:
DirContextOperations ctx = new DirContextAdapter(dn); ctx.setAttributeValue("cn", "john doe"); ctx.setAttributeValue("description", "some description"); //More initialization here. ldapTemplate.bind(ctx);
- Specified by:
bind
in interfaceLdapOperations
- Parameters:
ctx
- the context to bind
-
rebind
Remove an entry and replace it with a new one. The attributes used to create the entry are retrieved from thectx
parameter. This method assumes that the specified context already exists - if not it will fail. The entry will be bound to the DN set onctx
.Example:
DirContextOperations ctx = new DirContextAdapter(dn); ctx.setAttributeValue("cn", "john doe"); ctx.setAttributeValue("description", "some description"); //More initialization here. ldapTemplate.rebind(ctx);
- Specified by:
rebind
in interfaceLdapOperations
- Parameters:
ctx
- the context to rebind
-
authenticate
Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry.Example:
AndFilter filter = new AndFilter(); filter.and("objectclass", "person").and("uid", userId); boolean authenticated = ldapTemplate.authenticate(LdapUtils.emptyLdapName(), filter.toString(), password);
- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.- Returns:
true
if the authentication was successful,false
otherwise.
-
authenticate
Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry.Example:
AndFilter filter = new AndFilter(); filter.and("objectclass", "person").and("uid", userId); boolean authenticated = ldapTemplate.authenticate(LdapUtils.emptyLdapName(), filter.toString(), password);
- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.- Returns:
true
if the authentication was successful,false
otherwise.
-
authenticate
public boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry. The resulting DirContext instance is then used as input to the suppliedAuthenticatedLdapEntryContextCallback
to perform any additional LDAP operations against the authenticated DirContext.- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.callback
- the callback to that will be called to perform operations on the DirContext authenticated with the found user.- Returns:
true
if the authentication was successful,false
otherwise.- See Also:
-
authenticate
public boolean authenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry. The resulting DirContext instance is then used as input to the suppliedAuthenticatedLdapEntryContextCallback
to perform any additional LDAP operations against the authenticated DirContext.- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.callback
- the callback to that will be called to perform operations on the DirContext authenticated with the found user.- Returns:
true
if the authentication was successful,false
otherwise.- See Also:
-
authenticate
public boolean authenticate(String base, String filter, String password, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry. If an exception is caught, the same exception is passed on to the givenAuthenticationErrorCallback
. This enables the caller to provide a callback that, for example, collects the exception for later processing.- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.errorCallback
- the callback that will be called if an exception is caught.- Returns:
true
if the authentication was successful,false
otherwise.
-
authenticate
public boolean authenticate(Name base, String filter, String password, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry. If an exception is caught, the same exception is passed on to the givenAuthenticationErrorCallback
. This enables the caller to provide a callback that, for example, collects the exception for later processing.- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.errorCallback
- the callback that will be called if an exception is caught.- Returns:
true
if the authentication was successful,false
otherwise.- See Also:
-
authenticate
public boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry. The resulting DirContext instance is then used as input to the suppliedAuthenticatedLdapEntryContextCallback
to perform any additional LDAP operations against the authenticated DirContext. If an exception is caught, the same exception is passed on to the givenAuthenticationErrorCallback
. This enables the caller to provide a callback that, for example, collects the exception for later processing.- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.callback
- the callback that will be called to perform operations on the DirContext authenticated with the found user.errorCallback
- the callback that will be called if an exception is caught.- Returns:
true
if the authentication was successful,false
otherwise.- See Also:
-
authenticate
public boolean authenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry. The resulting DirContext instance is then used as input to the suppliedAuthenticatedLdapEntryContextCallback
to perform any additional LDAP operations against the authenticated DirContext. If an exception is caught, the same exception is passed on to the givenAuthenticationErrorCallback
. This enables the caller to provide a callback that, for example, collects the exception for later processing.- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter - must result in a unique result.password
- the password to use for authentication.callback
- the callback that will be called to perform operations on the DirContext authenticated with the found user.errorCallback
- the callback that will be called if an exception is caught.- Returns:
true
if the authentication was successful,false
otherwise.- See Also:
-
authenticate
public <T> T authenticate(LdapQuery query, String password, AuthenticatedLdapEntryContextMapper<T> mapper) Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied LdapQuery; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry.Note: This method differs from the older authenticate methods in that encountered exceptions are thrown rather than supplied to a callback for handling.
- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
query
- the LdapQuery specifying the details of the search.password
- the password to use for authentication.mapper
- the callback that will be called to perform operations on the DirContext authenticated with the found user.false
otherwise.- Returns:
- the result from the callback.
- See Also:
-
authenticate
Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input toContextSource.getContext(String, String)
, thus authenticating the entry. If an exception is caught, the same exception is passed on to the givenAuthenticationErrorCallback
. This enables the caller to provide a callback that, for example, collects the exception for later processing.Note: This method differs from the older authenticate methods in that encountered exceptions are thrown rather than supplied to a callback for handling.
- Specified by:
authenticate
in interfaceLdapOperations
- Parameters:
query
- the LdapQuery specifying the details of the search.password
- the password to use for authentication.false
otherwise.- See Also:
-
searchForObject
Perform a search for a unique entry matching the specified search criteria and return the found object. If no entry is found or if there are more than one matching entry, anIncorrectResultSizeDataAccessException
is thrown.- Specified by:
searchForObject
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter.mapper
- the mapper to use for the search.- Returns:
- the single object returned by the mapper that matches the search criteria.
-
searchForObject
Perform a search for a unique entry matching the specified search criteria and return the found object. If no entry is found or if there are more than one matching entry, anIncorrectResultSizeDataAccessException
is thrown.- Specified by:
searchForObject
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter.mapper
- the mapper to use for the search.- Returns:
- the single object returned by the mapper that matches the search criteria.
-
searchForObject
public <T> T searchForObject(Name base, String filter, SearchControls searchControls, ContextMapper<T> mapper) Perform a search for a unique entry matching the specified search criteria and return the found object. If no entry is found or if there are more than one matching entry, anIncorrectResultSizeDataAccessException
is thrown.- Specified by:
searchForObject
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter.searchControls
- the searchControls to use for the search.mapper
- the mapper to use for the search.- Returns:
- the single object returned by the mapper that matches the search criteria.
-
searchForObject
public <T> T searchForObject(String base, String filter, SearchControls searchControls, ContextMapper<T> mapper) Perform a search for a unique entry matching the specified search criteria and return the found object. If no entry is found or if there are more than one matching entry, anIncorrectResultSizeDataAccessException
is thrown.- Specified by:
searchForObject
in interfaceLdapOperations
- Parameters:
base
- the DN to use as the base of the search.filter
- the search filter.searchControls
- the searchControls to use for the search.mapper
- the mapper to use for the search.- Returns:
- the single object returned by the mapper that matches the search criteria.
-
search
Perform a search with parameters from the specified LdapQuery. All found objects will be supplied to theNameClassPairCallbackHandler
for processing.- Specified by:
search
in interfaceLdapOperations
- Parameters:
query
- the LDAP query specification.callbackHandler
- theNameClassPairCallbackHandler
to supply all found entries to.- See Also:
-
search
Perform a search with parameters from the specified LdapQuery. All found objects will be supplied to theContextMapper
for processing, and all returned objects will be collected in a list to be returned.- Specified by:
search
in interfaceLdapOperations
- Parameters:
query
- the LDAP query specification.mapper
- theContextMapper
to supply all found entries to.- Returns:
- a
List
containing all entries received from theContextMapper
. - See Also:
-
search
Perform a search with parameters from the specified LdapQuery. The Attributes of the found entries will be supplied to theAttributesMapper
for processing, and all returned objects will be collected in a list to be returned.- Specified by:
search
in interfaceLdapOperations
- Parameters:
query
- the LDAP query specification.mapper
- theAttributes
to supply all found Attributes to.- Returns:
- a
List
containing all entries received from theAttributes
. - See Also:
-
searchForContext
Perform a search for a unique entry matching the specified LDAP query and return the found entry as a DirContextOperation instance. If no entry is found or if there are more than one matching entry, anIncorrectResultSizeDataAccessException
is thrown.- Specified by:
searchForContext
in interfaceLdapOperations
- Parameters:
query
- the LDAP query specification.- Returns:
- the single entry matching the query as a DirContextOperations instance.
- See Also:
-
searchForObject
Perform a search for a unique entry matching the specified LDAP query and return the found object. If no entry is found or if there are more than one matching entry, anIncorrectResultSizeDataAccessException
is thrown.- Specified by:
searchForObject
in interfaceLdapOperations
- Parameters:
query
- the LDAP query specification.- Returns:
- the single object returned by the mapper that matches the search criteria.
- See Also:
-
searchForStream
Perform a search with parameters from the specified LdapQuery. The Attributes of the found entries will be supplied to theAttributesMapper
for processing, and all returned objects will be collected in a list to be returned.- Specified by:
searchForStream
in interfaceLdapOperations
- Parameters:
query
- the LDAP query specification.attributesMapper
- theAttributes
to supply all found Attributes to.- Returns:
- a
Stream
of all entries received from theAttributes
. - See Also:
-
searchForStream
Perform a search with parameters from the specified LdapQuery. All found objects will be supplied to theContextMapper
for processing, and all returned objects will be collected in a list to be returned.- Specified by:
searchForStream
in interfaceLdapOperations
- Parameters:
query
- the LDAP query specification.mapper
- theContextMapper
to supply all found entries to.- Returns:
- a
Stream
of all entries received from theContextMapper
. - See Also:
-
findByDn
Read a named entry from the LDAP directory. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations.- Specified by:
findByDn
in interfaceLdapOperations
- Type Parameters:
T
- The Java type to return- Parameters:
dn
- The distinguished name of the entry to read from the LDAP directory.clazz
- The Java type to return- Returns:
- The entry as read from the directory
-
create
Create the given entry in the LDAP directory. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations. If the field annotated withId
is set in the object, this will be used as the distinguished name of the new entry. If no explicit DN is specified, an attempt will be made to calculate the name from fields annotated withDnAttribute
. If an id can be calculated, this will be populated in the supplied object.- Specified by:
create
in interfaceLdapOperations
- Parameters:
entry
- The entry to be create, it must not be null or already exist in the directory.
-
update
Update the given entry in the LDAP directory. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations. If the distinguished name is not explicitly specified (i.e. if the field annotated withId
isnull
), an attempt will be made to calculate the name from fields annotated withDnAttribute
. If theId
field and the calculated DN is different, the entry will be moved (i.e., anLdapOperations.unbind(javax.naming.Name)
followed by aLdapOperations.bind(DirContextOperations)
. Otherwise the current data of the entry will be read from the directory and aLdapOperations.modifyAttributes(DirContextOperations)
operation will be performed using theModificationItems
resulting from the changes of the entry compared to its current state in the directory. If the id of the entry has changed, i.e. if it wasn't specified from the beginning, or if it is calculated to have changed, the new value will be populated in the supplied object.- Specified by:
update
in interfaceLdapOperations
- Parameters:
entry
- The entry to update, it must already exist in the directory.
-
delete
Delete an entry from the LDAP directory. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations. If the field annotated withId
is set in the object, this will be used as the distinguished name of the new entry. If no explicit DN is specified, an attempt will be made to calculate the name from fields annotated withDnAttribute
.- Specified by:
delete
in interfaceLdapOperations
- Parameters:
entry
- The entry to delete, it must already exist in the directory.
-
findAll
Find all entries in the LDAP directory of a given type. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations.- Specified by:
findAll
in interfaceLdapOperations
- Type Parameters:
T
- The Java type to return- Parameters:
base
- The root of the sub-tree at which to begin the search.searchControls
- The search controls of the search. Note that the 'returned attributes' parameter should typically not be tampered with, since that may affect the attributes populated in returned entries.clazz
- The Java type to return- Returns:
- All entries that are of the type represented by the given Java class
-
findAll
Find all entries in the LDAP directory of a given type. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations.- Specified by:
findAll
in interfaceLdapOperations
- Type Parameters:
T
- The Java type to return- Parameters:
clazz
- The Java type to return- Returns:
- All entries that are of the type represented by the given Java class
-
find
Find all entries in the LDAP directory of a given type that matches the specified filter. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations.- Specified by:
find
in interfaceLdapOperations
- Type Parameters:
T
- The Java type to return- Parameters:
base
- The root of the sub-tree at which to begin the search.filter
- The search filter.searchControls
- The search controls of the search. Note that the 'returned attributes' parameter should typically not be tampered with, since that may affect the attributes populated in returned entries.clazz
- The Java type to return- Returns:
- All entries that are of the type represented by the given Java class
-
find
Search for entries in the LDAP directory. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations.Only those entries that both match the query search filter and are represented by the given Java class are returned.
- Specified by:
find
in interfaceLdapOperations
- Type Parameters:
T
- The Java type to return- Parameters:
query
- the LDAP query specificationclazz
- The Java type to return- Returns:
- All matching entries.
- See Also:
-
findOne
Search for objects in the directory tree matching the specified LdapQuery, expecting to find exactly one match. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations.- Specified by:
findOne
in interfaceLdapOperations
- Type Parameters:
T
- The Java type to return- Parameters:
query
- the LDAP query specificationclazz
- The Java type to return- Returns:
- The single entry matching the search specification.
-
findForStream
Search for entries in the LDAP directory. The referenced class must have object-directory mapping metadata specified usingEntry
and associated annotations.Only those entries that both match the query search filter and are represented by the given Java class are returned.
- Specified by:
findForStream
in interfaceLdapOperations
- Type Parameters:
T
- The Java type to return- Parameters:
query
- the LDAP query specificationclazz
- The Java type to return- Returns:
- All matching entries.
- See Also:
-