Package org.springframework.ldap.core
Interface LdapOperations
- All Known Implementing Classes:
LdapTemplate
public interface LdapOperations
Interface that specifies a basic set of LDAP operations. Implemented by LdapTemplate,
but it might be a useful option to use this interface in order to enhance testability.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
authenticate
(String base, String filter, String password) Deprecated.boolean
authenticate
(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) boolean
authenticate
(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) boolean
authenticate
(String base, String filter, String password, AuthenticationErrorCallback errorCallback) boolean
authenticate
(Name base, String filter, String password) boolean
authenticate
(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) boolean
authenticate
(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) boolean
authenticate
(Name base, String filter, String password, AuthenticationErrorCallback errorCallback) 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.<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 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 using a particularSearchExecutor
.void
search
(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor) Perform a search using a particularSearchExecutor
and context processor.<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> mapper) 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
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.
-
Method Details
-
search
void search(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor) throws NamingException Perform a search using a particularSearchExecutor
and context processor. Use this method only if especially needed - for the most cases there is an overloaded convenience method which calls this one with suitable argments. This method handles all the plumbing; getting a readonly context; looping through theNamingEnumeration
and closing the context and enumeration. The actual search is delegated to the SearchExecutor and each foundNameClassPair
is passed to theCallbackHandler
. Any encounteredNamingException
will be translated usingLdapUtils.convertLdapException(javax.naming.NamingException)
.- Parameters:
se
- TheSearchExecutor
to use for performing the actual search.handler
- TheNameClassPairCallbackHandler
to which each found entry will be passed.processor
-DirContextProcessor
for custom pre- and post-processing.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted as no entries being found.
-
search
Perform a search using a particularSearchExecutor
. Use this method only if especially needed - for the most cases there is an overloaded convenience method which calls this one with suitable argments. This method handles all the plumbing; getting a readonly context; looping through theNamingEnumeration
and closing the context and enumeration. The actual search is delegated to theSearchExecutor
and each foundNameClassPair
is passed to theCallbackHandler
. Any encounteredNamingException
will be translated using theLdapUtils.convertLdapException(javax.naming.NamingException)
.- Parameters:
se
- TheSearchExecutor
to use for performing the actual search.handler
- TheNameClassPairCallbackHandler
to which each found entry will be passed.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted as no entries being found.- See Also:
-
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; usesearch(SearchExecutor, NameClassPairCallbackHandler)
or any of the overloaded search methods for this.- Parameters:
ce
- TheContextExecutor
to which the actual operation on theDirContext
will be delegated.- Returns:
- the result from the ContextExecutor's operation.
- Throws:
NamingException
- if the operation resulted in aNamingException
.- 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.- Parameters:
ce
- TheContextExecutor
to which the actual operation on theDirContext
will be delegated.- Returns:
- the result from the ContextExecutor's operation.
- Throws:
NamingException
- if the operation resulted in aNamingException
.- See Also:
-
search
void search(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) throws NamingException 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
.- 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.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
void search(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) throws NamingException Search for all objects matching the supplied filter. Seesearch(Name, String, SearchControls, NameClassPairCallbackHandler)
for details.- 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.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
void search(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor) throws NamingException 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.- 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.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor) throws NamingException 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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor) throws NamingException 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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor) throws NamingException 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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor) throws NamingException 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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
void search(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor) throws NamingException Search for all objects matching the supplied filter. Seesearch(Name, String, SearchControls, NameClassPairCallbackHandler, DirContextProcessor)
for details.- 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.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
void search(Name base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler) throws NamingException 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.- 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.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
void search(String base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler) throws NamingException 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.- 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.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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
.- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResults
to.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
void search(String base, String filter, NameClassPairCallbackHandler handler) throws NamingException 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
.- Parameters:
base
- The base DN where the search should begin.filter
- The filter to use in the search.handler
- TheNameClassPairCallbackHandler
to supply theSearchResults
to.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper) throws NamingException 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
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper) throws NamingException 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
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, int searchScope, AttributesMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, int searchScope, AttributesMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. The Attributes in eachSearchResult
is supplied to the specifiedAttributesMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
. Only return the supplied attributes.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
. Only return the supplied attributes.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, int searchScope, ContextMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, int searchScope, ContextMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. TheObject
returned in eachSearchResult
is supplied to the specifiedContextMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper) throws NamingException 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.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. The Object returned in eachSearchResult
is supplied to the specifiedContextMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. The Attributes returned in eachSearchResult
is supplied to the specifiedAttributesMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
search
<T> List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper) throws NamingException Search for all objects matching the supplied filter. The Attributes returned in eachSearchResult
is supplied to the specifiedAttributesMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
list
Perform a non-recursive listing of the children of the givenbase
. Each resultingNameClassPair
is supplied to the specifiedNameClassPairCallbackHandler
.- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachNameClassPair
to.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
list
Perform a non-recursive listing of the children of the givenbase
. Each resultingNameClassPair
is supplied to the specifiedNameClassPairCallbackHandler
.- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachNameClassPair
to.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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
.- 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. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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
.- 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. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
list
Perform a non-recursive listing of the children of the givenbase
.- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a List containing the names of all the contexts bound to
base
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
list
Perform a non-recursive listing of the children of the givenbase
.- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a List containing the names of all the contexts bound to
base
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. Each resultingBinding
is supplied to the specifiedNameClassPairCallbackHandler
.- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachBinding
to.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. Each resultingBinding
is supplied to the specifiedNameClassPairCallbackHandler
.- Parameters:
base
- The base DN where the list should be performed.handler
- TheNameClassPairCallbackHandler
to supply eachBinding
to.- Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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
.- 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. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
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
.- 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. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of children of the givenbase
.- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a
List
containing the names of all the contexts bound tobase
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of children of the givenbase
.- Parameters:
base
- The base DN where the list should be performed.- Returns:
- a
List
containing the names of all the contexts bound tobase
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. The Object returned in eachBinding
is supplied to the specifiedContextMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of the children of the givenbase
. The Object returned in eachBinding
is supplied to the specifiedContextMapper
.- 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
. - Throws:
NamingException
- if any error occurs. Note that aNameNotFoundException
will be ignored. Instead this is interpreted that no entries were found.
-
lookup
Lookup the supplied DN and return the found object. This will typically be aDirContextAdapter
, unless theDirObjectFactory
has been modified in theContextSource
.- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- the found object, typically a
DirContextAdapter
instance. - Throws:
NamingException
- if any error occurs.- See Also:
-
lookup
Lookup the supplied DN and return the found object. This will typically be aDirContextAdapter
, unless theDirObjectFactory
has been modified in theContextSource
.- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- the found object, typically a
DirContextAdapter
instance. - Throws:
NamingException
- if any error occurs.- See Also:
-
lookup
Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper
.- Parameters:
dn
- The distinguished name to find.mapper
- TheAttributesMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
- Throws:
NamingException
- if any error occurs.
-
lookup
Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper
.- Parameters:
dn
- The distinguished name to find.mapper
- TheAttributesMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
- Throws:
NamingException
- if any error occurs.
-
lookup
Convenience method to lookup a specified DN and automatically pass the found object to aContextMapper
.- Parameters:
dn
- The distinguished name to find.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
- Throws:
NamingException
- if any error occurs.
-
lookup
Convenience method to lookup a specified DN and automatically pass the found object to aContextMapper
.- Parameters:
dn
- The distinguished name to find.mapper
- TheContextMapper
to use for mapping the found object.- Returns:
- the object returned from the mapper.
- Throws:
NamingException
- if any error occurs.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to anAttributesMapper
.- 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.
- Throws:
NamingException
- if any error occurs.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to anAttributesMapper
.- 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.
- Throws:
NamingException
- if any error occurs.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to aContextMapper
.- 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.
- Throws:
NamingException
- if any error occurs.
-
lookup
Convenience method to get the specified attributes of a specified DN and automatically pass them to aContextMapper
.- 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.
- Throws:
NamingException
- if any error occurs.
-
modifyAttributes
Modify an entry in the LDAP tree using the suppliedModificationItems
.- Parameters:
dn
- The distinguished name of the node to modify.mods
- The modifications to perform.- Throws:
NamingException
- if any error occurs.- See Also:
-
modifyAttributes
Modify an entry in the LDAP tree using the suppliedModificationItems
.- Parameters:
dn
- The distinguished name of the node to modify.mods
- The modifications to perform.- Throws:
NamingException
- if any error occurs.- 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.- 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
.- Throws:
NamingException
- if any error occurs.- 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.- 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
.- Throws:
NamingException
- if any error occurs.- 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, useunbind(Name, boolean)
in stead.- Parameters:
dn
- The distinguished name of the entry to remove.- Throws:
NamingException
- if any error occurs.
-
unbind
Remove an entry from the LDAP tree. The entry must not have any children - if you suspect that the entry might have descendants, useunbind(Name, boolean)
in stead.- Parameters:
dn
- The distinguished name to unbind.- Throws:
NamingException
- if any error occurs.
-
unbind
Remove an entry from the LDAP tree, optionally removing all descendants in the process.- 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.- Throws:
NamingException
- if any error occurs.
-
unbind
Remove an entry from the LDAP tree, optionally removing all descendants in the process.- 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.- 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.- 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
.- Throws:
NamingException
- if any error occurs.- 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.- 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
.- Throws:
NamingException
- if any error occurs.- See Also:
-
rename
Move an entry in the LDAP tree to a new location.- 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.- Throws:
ContextNotEmptyException
- if newDn is already boundNamingException
- if any other error occurs.
-
rename
Move an entry in the LDAP tree to a new location.- 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.- Throws:
ContextNotEmptyException
- if newDn is already boundNamingException
- if any other error occurs.
-
lookupContext
Convenience method to lookup the supplied DN and automatically cast it toDirContextOperations
.- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- The found object, cast to
DirContextOperations
. - Throws:
ClassCastException
- if an alternativeDirObjectFactory
has been registered with theContextSource
, causing the actual class of the returned object to be something else thanDirContextOperations
.NamingException
- if any other error occurs.- Since:
- 1.2
- See Also:
-
lookupContext
Convenience method to lookup the supplied DN and automatically cast it toDirContextOperations
.- Parameters:
dn
- The distinguished name of the object to find.- Returns:
- The found object, cast to
DirContextOperations
. - Throws:
ClassCastException
- if an alternativeDirObjectFactory
has been registered with theContextSource
, causing the actual class of the returned object to be something else thanDirContextOperations
.NamingException
- if any other error occurs.- Since:
- 1.2
- 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); }
- Parameters:
ctx
- the DirContextOperations instance to use in the update.- Throws:
IllegalStateException
- if the supplied instance is not in update mode or has not been properly initialized.NamingException
- if any other error occurs.- Since:
- 1.2
- 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);
- Parameters:
ctx
- the context to bind- Throws:
IllegalStateException
- if no DN is set or if the instance is in update mode.- Since:
- 1.3
-
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);
- Parameters:
ctx
- the context to rebind- Throws:
IllegalStateException
- if no DN is set or if the instance is in update mode.- Since:
- 1.3
-
authenticate
Deprecated.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);
- 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.- Since:
- 1.3
-
authenticate
Deprecated.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);
- 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.- Since:
- 1.3
-
authenticate
@Deprecated boolean authenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) Deprecated.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.- 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.- Since:
- 1.3
- See Also:
-
authenticate
@Deprecated boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) Deprecated.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.- 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.- Since:
- 1.3
- See Also:
-
authenticate
@Deprecated boolean authenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) Deprecated.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.- 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.- Since:
- 1.3.1
- See Also:
-
authenticate
@Deprecated boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) Deprecated.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.- 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.- Since:
- 1.3.1
- See Also:
-
authenticate
@Deprecated boolean authenticate(Name base, String filter, String password, AuthenticationErrorCallback errorCallback) Deprecated.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.- 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.- Since:
- 1.3.1
- See Also:
-
authenticate
@Deprecated boolean authenticate(String base, String filter, String password, AuthenticationErrorCallback errorCallback) Deprecated.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.- 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.- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if more than one users were found- Since:
- 1.3.1
-
authenticate
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.
- 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.
- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if more than one users were foundorg.springframework.dao.EmptyResultDataAccessException
- if only one user was foundNamingException
- if something went wrong in authentication.- Since:
- 2.0
- 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.
- Parameters:
query
- the LdapQuery specifying the details of the search.password
- the password to use for authentication.false
otherwise.- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if more than one users were foundorg.springframework.dao.EmptyResultDataAccessException
- if only one user was foundNamingException
- if something went wrong in authentication.- Since:
- 2.0
- 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.- 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.
- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if the result is not one unique entry- Since:
- 1.3
-
searchForObject
<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.- 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.
- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if the result is not one unique entry- Since:
- 2.0
-
searchForObject
<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.- 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.
- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if the result is not one unique entry- Since:
- 2.0
-
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.- 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.
- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if the result is not one unique entry- Since:
- 1.3
-
search
Perform a search with parameters from the specified LdapQuery. All found objects will be supplied to theNameClassPairCallbackHandler
for processing.- Parameters:
query
- the LDAP query specification.callbackHandler
- theNameClassPairCallbackHandler
to supply all found entries to.- Throws:
NamingException
- if any error occurs.- Since:
- 2.0
- 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.- Parameters:
query
- the LDAP query specification.mapper
- theContextMapper
to supply all found entries to.- Returns:
- a
List
containing all entries received from theContextMapper
. - Throws:
NamingException
- if any error occurs.- Since:
- 2.0
- 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.- Parameters:
query
- the LDAP query specification.mapper
- theAttributes
to supply all found Attributes to.- Returns:
- a
List
containing all entries received from theAttributes
. - Throws:
NamingException
- if any error occurs.- Since:
- 2.0
- 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.- Parameters:
query
- the LDAP query specification.- Returns:
- the single entry matching the query as a DirContextOperations instance.
- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if the result is not one unique entry- Since:
- 2.0
- 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.- Parameters:
query
- the LDAP query specification.- Returns:
- the single object returned by the mapper that matches the search criteria.
- Throws:
org.springframework.dao.IncorrectResultSizeDataAccessException
- if the result is not one unique entry- Since:
- 2.0
- 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.- Parameters:
query
- the LDAP query specification.mapper
- theAttributes
to supply all found Attributes to.- Returns:
- a
Stream
of all entries received from theAttributes
. - Throws:
NamingException
- if any error occurs.- Since:
- 3.0
- 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.- Parameters:
query
- the LDAP query specification.mapper
- theContextMapper
to supply all found entries to.- Returns:
- a
Stream
of all entries received from theContextMapper
. - Throws:
NamingException
- if any error occurs.- Since:
- 3.0
- 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.- 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
- Throws:
NamingException
- on error.- Since:
- 2.0
-
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.- Parameters:
entry
- The entry to be create, it must not be null or already exist in the directory.- Throws:
NamingException
- on error.IllegalArgumentException
- if the entry is null or on failure to determine the distinguished name.- Since:
- 2.0
-
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., anunbind(javax.naming.Name)
followed by abind(DirContextOperations)
. Otherwise the current data of the entry will be read from the directory and amodifyAttributes(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.- Parameters:
entry
- The entry to update, it must already exist in the directory.- Throws:
NamingException
- on error.IllegalArgumentException
- if the entry is null or on failure to determine the distinguished name.- Since:
- 2.0
-
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
.- Parameters:
entry
- The entry to delete, it must already exist in the directory.- Throws:
NamingException
- on error.IllegalArgumentException
- if the entry is null or on failure to determine the distinguished name.- Since:
- 2.0
-
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.- 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
- Throws:
NamingException
- on error.- Since:
- 2.0
-
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.- 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
- Throws:
NamingException
- on error.- Since:
- 2.0
-
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.- 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
- Throws:
NamingException
- on error.- Since:
- 2.0
-
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.
- Type Parameters:
T
- The Java type to return- Parameters:
query
- the LDAP query specificationclazz
- The Java type to return- Returns:
- All matching entries.
- Throws:
NamingException
- on error.- Since:
- 2.0
- 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.- 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.
- Throws:
NamingException
- on LDAP error.org.springframework.dao.EmptyResultDataAccessException
- if no matching entry can be foundorg.springframework.dao.IncorrectResultSizeDataAccessException
- if more than one matching entry is found- Since:
- 2.0
-
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.
- Type Parameters:
T
- The Java type to return- Parameters:
query
- the LDAP query specificationclazz
- The Java type to return- Returns:
- All matching entries.
- Throws:
NamingException
- on error.- Since:
- 3.0
- See Also:
-
getObjectDirectoryMapper
ObjectDirectoryMapper getObjectDirectoryMapper()Get the configured ObjectDirectoryMapper. For internal use.- Returns:
- the configured ObjectDirectoryMapper.
- Since:
- 2.0
-
authenticate(org.springframework.ldap.query.LdapQuery, String)
orauthenticate(org.springframework.ldap.query.LdapQuery, String, AuthenticatedLdapEntryContextMapper)