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 TypeMethodDescriptionbooleanauthenticate(String base, String filter, String password) Deprecated.booleanauthenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) booleanauthenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) booleanauthenticate(String base, String filter, String password, AuthenticationErrorCallback errorCallback) booleanauthenticate(Name base, String filter, String password) booleanauthenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback) booleanauthenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback) booleanauthenticate(Name base, String filter, String password, AuthenticationErrorCallback errorCallback) voidauthenticate(LdapQuery query, String password) Utility method to perform a simple LDAP 'bind' authentication.<T> Tauthenticate(LdapQuery query, String password, AuthenticatedLdapEntryContextMapper<T> mapper) Utility method to perform a simple LDAP 'bind' authentication.voidbind(String dn, Object obj, Attributes attributes) Create an entry in the LDAP tree.voidbind(Name dn, Object obj, Attributes attributes) Create an entry in the LDAP tree.voidbind(DirContextOperations ctx) Bind the data in the supplied context in the tree.voidCreate the given entry in the LDAP directory.voidDelete an entry from the LDAP directory.<T> TexecuteReadOnly(ContextExecutor<T> ce) Perform an operation (or series of operations) on a read-only context.<T> TexecuteReadWrite(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> TRead a named entry from the LDAP directory.<T> Stream<T>findForStream(LdapQuery query, Class<T> clazz) Search for entries in the LDAP directory.<T> TSearch 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.voidlist(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.voidlist(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.voidlistBindings(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.voidlistBindings(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> Tlookup(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> Tlookup(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> Tlookup(String dn, AttributesMapper<T> mapper) Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper.<T> Tlookup(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> Tlookup(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> Tlookup(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> Tlookup(Name dn, AttributesMapper<T> mapper) Convenience method to get the attributes of a specified DN and automatically pass them to anAttributesMapper.<T> Tlookup(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.voidmodifyAttributes(String dn, ModificationItem[] mods) Modify an entry in the LDAP tree using the suppliedModificationItems.voidmodifyAttributes(Name dn, ModificationItem[] mods) Modify an entry in the LDAP tree using the suppliedModificationItems.voidModify the attributes of the entry referenced by the suppliedDirContextOperationsinstance.voidrebind(String dn, Object obj, Attributes attributes) Remove an entry and replace it with a new one.voidrebind(Name dn, Object obj, Attributes attributes) Remove an entry and replace it with a new one.voidRemove an entry and replace it with a new one.voidMove an entry in the LDAP tree to a new location.voidMove an entry in the LDAP tree to a new location.voidsearch(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.voidsearch(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.voidsearch(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.voidsearch(String base, String filter, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.voidsearch(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.voidsearch(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.voidsearch(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.voidsearch(Name base, String filter, NameClassPairCallbackHandler handler) Search for all objects matching the supplied filter.voidsearch(SearchExecutor se, NameClassPairCallbackHandler handler) Perform a search using a particularSearchExecutor.voidsearch(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor) Perform a search using a particularSearchExecutorand 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.voidsearch(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> TsearchForObject(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> TsearchForObject(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> TsearchForObject(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> TsearchForObject(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> TsearchForObject(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.voidRemove an entry from the LDAP tree.voidRemove an entry from the LDAP tree, optionally removing all descendants in the process.voidRemove an entry from the LDAP tree.voidRemove an entry from the LDAP tree, optionally removing all descendants in the process.voidUpdate 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 particularSearchExecutorand 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 theNamingEnumerationand closing the context and enumeration. The actual search is delegated to the SearchExecutor and each foundNameClassPairis passed to theCallbackHandler. Any encounteredNamingExceptionwill be translated usingLdapUtils.convertLdapException(javax.naming.NamingException).- Parameters:
se- TheSearchExecutorto use for performing the actual search.handler- TheNameClassPairCallbackHandlerto which each found entry will be passed.processor-DirContextProcessorfor custom pre- and post-processing.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 theNamingEnumerationand closing the context and enumeration. The actual search is delegated to theSearchExecutorand each foundNameClassPairis passed to theCallbackHandler. Any encounteredNamingExceptionwill be translated using theLdapUtils.convertLdapException(javax.naming.NamingException).- Parameters:
se- TheSearchExecutorto use for performing the actual search.handler- TheNameClassPairCallbackHandlerto which each found entry will be passed.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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- TheContextExecutorto which the actual operation on theDirContextwill 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- TheContextExecutorto which the actual operation on theDirContextwill 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. EachSearchResultis supplied to the specifiedNameClassPairCallbackHandler. TheSearchScopespecified in the suppliedSearchControlswill 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- TheSearchControlsto use in the search.handler- TheNameClassPairCallbackHandlerto supply theSearchResultto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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- TheSearchControlsto use in the search.handler- TheNameClassPairCallbackHandlerto supply theSearchResultto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. EachSearchResultis supplied to the specifiedNameClassPairCallbackHandler. TheSearchScopespecified in the suppliedSearchControlswill be used in the search. Note that if you are using aContextMapper, the returningObjFlag needs to be set to true in theSearchControls. The givenDirContextProcessorwill 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- TheSearchControlsto use in the search.handler- TheNameClassPairCallbackHandlerto supply theSearchResultto.processor- TheDirContextProcessorto use before and after the search.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis supplied to the specifiedAttributesMapper. TheSearchScopespecified in the suppliedSearchControlswill be used in the search. The givenDirContextProcessorwill 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- TheSearchControlsto use in the search.mapper- TheAttributesMapperto use for translating each entry.processor- TheDirContextProcessorto use before and after the search.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis supplied to the specifiedAttributesMapper. TheSearchScopespecified in the suppliedSearchControlswill be used in the search. The givenDirContextProcessorwill 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- TheSearchControlsto use in the search.mapper- TheAttributesMapperto use for translating each entry.processor- TheDirContextProcessorto use before and after the search.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis supplied to the specifiedContextMapper. TheSearchScopespecified in the suppliedSearchControlswill be used in the search. The givenDirContextProcessorwill 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- TheSearchControlsto use in the search. If the returnObjFlag is not set in theSearchControls, this method will set it automatically, as this is required for theContextMapperto work.mapper- TheContextMapperto use for translating each entry.processor- TheDirContextProcessorto use before and after the search.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis supplied to the specifiedContextMapper. TheSearchScopespecified in the suppliedSearchControlswill be used in the search. The givenDirContextProcessorwill 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- TheSearchControlsto use in the search. If the returnObjFlag is not set in theSearchControls, this method will set it automatically, as this is required for theContextMapperto work.mapper- TheContextMapperto use for translating each entry.processor- TheDirContextProcessorto use before and after the search.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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- TheSearchControlsto use in the search.handler- TheNameClassPairCallbackHandlerto supply theSearchResultsto.processor- TheDirContextProcessorto use before and after the search.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. EachSearchResultis 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 totrueif aContextMapperis used.handler- TheNameClassPairCallbackHandlerto supply theSearchResultsto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. EachSearchResultis 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 totrueif aContextMapperis used.handler- TheNameClassPairCallbackHandlerto supply theSearchResultsto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
search
Search for all objects matching the supplied filter. EachSearchResultis 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- TheNameClassPairCallbackHandlerto supply theSearchResultsto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. EachSearchResultis 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- TheNameClassPairCallbackHandlerto supply theSearchResultsto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis 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,nullmeans returning all attributes.mapper- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis 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,nullmeans returning all attributes.mapper- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis 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- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis 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- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
search
Search for all objects matching the supplied filter. The Attributes in eachSearchResultis 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- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
search
Search for all objects matching the supplied filter. The Attributes in eachSearchResultis 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- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theAttributesMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. TheObjectreturned in eachSearchResultis 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,nullmeans all attributes.mapper- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. TheObjectreturned in eachSearchResultis 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,nullmeans all attributes.mapper- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. TheObjectreturned in eachSearchResultis 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- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. TheObjectreturned in eachSearchResultis 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- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
search
Search for all objects matching the supplied filter. TheObjectreturned in eachSearchResultis 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- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
search
Search for all objects matching the supplied filter. TheObjectreturned in eachSearchResultis 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- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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. TheObjectreturned in eachSearchResultis 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- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis supplied to the specifiedContextMapper.- Parameters:
base- The base DN where the search should begin.filter- The filter to use in the search.controls- TheSearchControlsto use in the search. If the returnObjFlag is not set in theSearchControls, this method will set it automatically, as this is required for theContextMapperto work.mapper- TheContextMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis supplied to the specifiedAttributesMapper.- Parameters:
base- The base DN where the search should begin.filter- The filter to use in the search.controls- TheSearchControlsto use in the search.mapper- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachSearchResultis supplied to the specifiedAttributesMapper.- Parameters:
base- The base DN where the search should begin.filter- The filter to use in the search.controls- TheSearchControlsto use in the search.mapper- TheAttributesMapperto use for translating each entry.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
list
Perform a non-recursive listing of the children of the givenbase. Each resultingNameClassPairis supplied to the specifiedNameClassPairCallbackHandler.- Parameters:
base- The base DN where the list should be performed.handler- TheNameClassPairCallbackHandlerto supply eachNameClassPairto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
list
Perform a non-recursive listing of the children of the givenbase. Each resultingNameClassPairis supplied to the specifiedNameClassPairCallbackHandler.- Parameters:
base- The base DN where the list should be performed.handler- TheNameClassPairCallbackHandlerto supply eachNameClassPairto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 foundNameClassPairobjects to the suppliedNameClassPairMapperand return all the returned values as aList.- Parameters:
base- The base DN where the list should be performed.mapper- TheNameClassPairMapperto supply eachNameClassPairto.- Returns:
- a
Listcontaining the Objects returned from the Mapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 foundNameClassPairobjects to the suppliedNameClassPairMapperand return all the returned values as aList.- Parameters:
base- The base DN where the list should be performed.mapper- TheNameClassPairMapperto supply eachNameClassPairto.- Returns:
- a
Listcontaining the Objects returned from the Mapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 aNameNotFoundExceptionwill 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 aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of the children of the givenbase. Each resultingBindingis supplied to the specifiedNameClassPairCallbackHandler.- Parameters:
base- The base DN where the list should be performed.handler- TheNameClassPairCallbackHandlerto supply eachBindingto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill be ignored. Instead this is interpreted that no entries were found.
-
listBindings
Perform a non-recursive listing of the children of the givenbase. Each resultingBindingis supplied to the specifiedNameClassPairCallbackHandler.- Parameters:
base- The base DN where the list should be performed.handler- TheNameClassPairCallbackHandlerto supply eachBindingto.- Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 foundBindingobjects to the suppliedNameClassPairMapperand return all the returned values as aList.- Parameters:
base- The base DN where the list should be performed.mapper- TheNameClassPairMapperto supply eachBindingto.- Returns:
- a
Listcontaining the Objects returned from the Mapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 foundBindingobjects to the suppliedNameClassPairMapperand return all the returned values as aList.- Parameters:
base- The base DN where the list should be performed.mapper- TheNameClassPairMapperto supply eachBindingto.- Returns:
- a
Listcontaining the Objects returned from the Mapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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
Listcontaining the names of all the contexts bound tobase. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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
Listcontaining the names of all the contexts bound tobase. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachBindingis supplied to the specifiedContextMapper.- Parameters:
base- The base DN where the list should be performed.mapper- TheContextMapperto use for mapping the found object.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 eachBindingis supplied to the specifiedContextMapper.- Parameters:
base- The base DN where the list should be performed.mapper- TheContextMapperto use for mapping the found object.- Returns:
- a
Listcontaining all entries received from theContextMapper. - Throws:
NamingException- if any error occurs. Note that aNameNotFoundExceptionwill 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 theDirObjectFactoryhas been modified in theContextSource.- Parameters:
dn- The distinguished name of the object to find.- Returns:
- the found object, typically a
DirContextAdapterinstance. - Throws:
NamingException- if any error occurs.- See Also:
-
lookup
Lookup the supplied DN and return the found object. This will typically be aDirContextAdapter, unless theDirObjectFactoryhas been modified in theContextSource.- Parameters:
dn- The distinguished name of the object to find.- Returns:
- the found object, typically a
DirContextAdapterinstance. - 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- TheAttributesMapperto 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- TheAttributesMapperto 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- TheContextMapperto 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- TheContextMapperto 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- TheAttributesMapperto 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- TheAttributesMapperto 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- TheContextMapperto 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- TheContextMapperto 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 theobjparameter or theattributesparameter (or both). One of these parameters may benullbut not both.- Parameters:
dn- The distinguished name to bind the object and attributes to.obj- The object to bind, may benull. Typically aDirContextimplementation.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 theobjparameter or theattributesparameter (or both). One of these parameters may benullbut not both.- Parameters:
dn- The distinguished name to bind the object and attributes to.obj- The object to bind, may benull. Typically aDirContextimplementation.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 isfalseand 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 isfalseand 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 theobjparameter or theattributesparameter (or both). One of these parameters may benullbut 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 aDirContextimplementation.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 theobjparameter or theattributesparameter (or both). One of these parameters may benullbut 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 aDirContextimplementation.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 benullor empty.newDn- The distinguished name where the entry should be moved; may not benullor 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 benullor empty.newDn- The distinguished name where the entry should be moved; may not benullor 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 alternativeDirObjectFactoryhas 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 alternativeDirObjectFactoryhas 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 suppliedDirContextOperationsinstance. The DN to update will be the DN of theDirContextOperationsinstance, and theModificationItemarray is retrieved from theDirContextOperationsinstance 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 alookupoperation, 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 attributesctxin 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 thectxparameter. 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:
trueif the authentication was successful,falseotherwise.- 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:
trueif the authentication was successful,falseotherwise.- Since:
- 1.3
-
authenticate
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 suppliedAuthenticatedLdapEntryContextCallbackto 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:
trueif the authentication was successful,falseotherwise.- Since:
- 1.3
- See Also:
-
authenticate
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 suppliedAuthenticatedLdapEntryContextCallbackto 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:
trueif the authentication was successful,falseotherwise.- Since:
- 1.3
- See Also:
-
authenticate
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 suppliedAuthenticatedLdapEntryContextCallbackto 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:
trueif the authentication was successful,falseotherwise.- Since:
- 1.3.1
- See Also:
-
authenticate
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 suppliedAuthenticatedLdapEntryContextCallbackto 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:
trueif the authentication was successful,falseotherwise.- Since:
- 1.3.1
- See Also:
-
authenticate
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:
trueif the authentication was successful,falseotherwise.- Since:
- 1.3.1
- See Also:
-
authenticate
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:
trueif the authentication was successful,falseotherwise.- 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.falseotherwise.- 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.falseotherwise.- 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, anIncorrectResultSizeDataAccessExceptionis 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, anIncorrectResultSizeDataAccessExceptionis 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, anIncorrectResultSizeDataAccessExceptionis 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, anIncorrectResultSizeDataAccessExceptionis 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 theNameClassPairCallbackHandlerfor processing.- Parameters:
query- the LDAP query specification.callbackHandler- theNameClassPairCallbackHandlerto 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 theContextMapperfor processing, and all returned objects will be collected in a list to be returned.- Parameters:
query- the LDAP query specification.mapper- theContextMapperto supply all found entries to.- Returns:
- a
Listcontaining 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 theAttributesMapperfor processing, and all returned objects will be collected in a list to be returned.- Parameters:
query- the LDAP query specification.mapper- theAttributesto supply all found Attributes to.- Returns:
- a
Listcontaining 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, anIncorrectResultSizeDataAccessExceptionis 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, anIncorrectResultSizeDataAccessExceptionis 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 theAttributesMapperfor processing, and all returned objects will be collected in a list to be returned.- Parameters:
query- the LDAP query specification.mapper- theAttributesto supply all found Attributes to.- Returns:
- a
Streamof 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 theContextMapperfor processing, and all returned objects will be collected in a list to be returned.- Parameters:
query- the LDAP query specification.mapper- theContextMapperto supply all found entries to.- Returns:
- a
Streamof 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 usingEntryand 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 usingEntryand associated annotations. If the field annotated withIdis 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 usingEntryand associated annotations. If the distinguished name is not explicitly specified (i.e. if the field annotated withIdisnull), an attempt will be made to calculate the name from fields annotated withDnAttribute. If theIdfield 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 theModificationItemsresulting 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 usingEntryand associated annotations. If the field annotated withIdis 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 usingEntryand 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 usingEntryand 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 usingEntryand 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 usingEntryand 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 usingEntryand 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 usingEntryand 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)