org.springframework.ldap
Class LdapTemplate

java.lang.Object
  extended byorg.springframework.ldap.LdapTemplate
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, LdapOperations

public class LdapTemplate
extends java.lang.Object
implements LdapOperations, org.springframework.beans.factory.InitializingBean

Executes core LDAP functionality and helps to avoid common errors, relieving the user of the burden of looking up contexts, looping through NamingEnumerations and closing contexts.

Note for Active Directory (AD) users: AD servers are apparently unable to handle referrals automatically, which causes a PartialResultException to be thrown whenever a referral is encountered in a search. To avoid this, set the ignorePartialResultException property to true. There is currently no way of manually handling these referrals in the form of ReferralException, i.e. either you get the exception (and your results are lost) or all referrals are ignored (if the server is unable to handle them properly. Neither is there any simple way to get notified that a PartialResultException has been ignored (other than in the log).

Author:
Mattias Arthursson, Ulrik Sandberg
See Also:
ContextSource

Nested Class Summary
 class LdapTemplate.AttributesMapperCallbackHandler
          A CollectingNameClassPairCallbackHandler to wrap an AttributesMapper.
 class LdapTemplate.ContextMapperCallbackHandler
          A CollectingNameClassPairCallbackHandler to wrap a ContextMapper.
 class LdapTemplate.MappingCollectingNameClassPairCallbackHandler
          A NameClassPairCallbackHandler that passes the NameClassPairs found to a NameClassPairMapper and collects the results in a list.
 
Constructor Summary
LdapTemplate()
          Constructor for bean usage.
LdapTemplate(ContextSource contextSource)
          Constructor to setup instance directly.
 
Method Summary
 void afterPropertiesSet()
           
 void bind(javax.naming.Name dn, java.lang.Object obj, javax.naming.directory.Attributes attributes)
          Create an entry in the LDAP tree.
 void bind(java.lang.String dn, java.lang.Object obj, javax.naming.directory.Attributes attributes)
          Create an entry in the LDAP tree.
protected  void deleteRecursively(javax.naming.directory.DirContext ctx, DistinguishedName name)
          Delete all subcontexts including the current one recursively.
 java.lang.Object executeReadOnly(ContextExecutor ce)
          Perform an operation (or series of operations) on a read-only context.
 java.lang.Object executeReadWrite(ContextExecutor ce)
          Perform an operation (or series of operations) on a read-write context.
 NamingExceptionTranslator getExceptionTranslator()
          Get the NamingExceptionTranslator that will be used by this instance.
 java.util.List list(javax.naming.Name base)
          Perform a non-recursive listing of the contexts bound to the given base.
 void list(javax.naming.Name base, NameClassPairCallbackHandler handler)
          Perform a non-recursive listing of the children of the given base.
 java.util.List list(javax.naming.Name base, NameClassPairMapper mapper)
          Perform a non-recursive listing of the children of the given base.
 java.util.List list(java.lang.String base)
          Perform a non-recursive listing of the children of the given base.
 void list(java.lang.String base, NameClassPairCallbackHandler handler)
          Perform a non-recursive listing of the children of the given base.
 java.util.List list(java.lang.String base, NameClassPairMapper mapper)
          Perform a non-recursive listing of the children of the given base.
 java.util.List listBindings(javax.naming.Name base)
          Perform a non-recursive listing of the children of the given base.
 java.util.List listBindings(javax.naming.Name base, ContextMapper mapper)
          Perform a non-recursive listing of the children of the given base.
 void listBindings(javax.naming.Name base, NameClassPairCallbackHandler handler)
          Perform a non-recursive listing of the children of the given base.
 java.util.List listBindings(javax.naming.Name base, NameClassPairMapper mapper)
          Perform a non-recursive listing of the children of the given base.
 java.util.List listBindings(java.lang.String base)
          Perform a non-recursive listing of children of the given base.
 java.util.List listBindings(java.lang.String base, ContextMapper mapper)
          Perform a non-recursive listing of the children of the given base.
 void listBindings(java.lang.String base, NameClassPairCallbackHandler handler)
          Perform a non-recursive listing of the children of the given base.
 java.util.List listBindings(java.lang.String base, NameClassPairMapper mapper)
          Perform a non-recursive listing of the children of the given base.
 java.lang.Object lookup(javax.naming.Name dn)
          Lookup the supplied DN and return the found object.
 java.lang.Object lookup(javax.naming.Name dn, AttributesMapper mapper)
          Convenience method to get the attributes of a specified DN and automatically pass them to an AttributesMapper.
 java.lang.Object lookup(javax.naming.Name dn, ContextMapper mapper)
          Convenience method to lookup a specified DN and automatically pass the found object to a ContextMapper.
 java.lang.Object lookup(java.lang.String dn)
          Lookup the supplied DN and return the found object.
 java.lang.Object lookup(java.lang.String dn, AttributesMapper mapper)
          Convenience method to get the attributes of a specified DN and automatically pass them to an AttributesMapper.
 java.lang.Object lookup(java.lang.String dn, ContextMapper mapper)
          Convenience method to lookup a specified DN and automatically pass the found object to a ContextMapper.
 void modifyAttributes(javax.naming.Name dn, javax.naming.directory.ModificationItem[] mods)
          Modify an entry in the LDAP tree using the supplied ModificationItems.
 void modifyAttributes(java.lang.String dn, javax.naming.directory.ModificationItem[] mods)
          Modify an entry in the LDAP tree using the supplied ModificationItems.
 void rebind(javax.naming.Name dn, java.lang.Object obj, javax.naming.directory.Attributes attributes)
          Remove an entry and replace it with a new one.
 void rebind(java.lang.String dn, java.lang.Object obj, javax.naming.directory.Attributes attributes)
          Remove an entry and replace it with a new one.
 void rename(javax.naming.Name oldDn, javax.naming.Name newDn)
          Move an entry in the LDAP tree to a new location.
 void rename(java.lang.String oldDn, java.lang.String newDn)
          Move an entry in the LDAP tree to a new location.
 java.util.List search(javax.naming.Name base, java.lang.String filter, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(javax.naming.Name base, java.lang.String filter, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(javax.naming.Name base, java.lang.String filter, int searchScope, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 void search(javax.naming.Name base, java.lang.String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler)
          Search for all objects matching the supplied filter.
 java.util.List search(javax.naming.Name base, java.lang.String filter, int searchScope, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(javax.naming.Name base, java.lang.String filter, int searchScope, java.lang.String[] attrs, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(javax.naming.Name base, java.lang.String filter, int searchScope, java.lang.String[] attrs, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 void search(javax.naming.Name base, java.lang.String filter, NameClassPairCallbackHandler handler)
          Search for all objects matching the supplied filter.
 java.util.List search(javax.naming.Name base, java.lang.String filter, javax.naming.directory.SearchControls controls, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(javax.naming.Name base, java.lang.String filter, javax.naming.directory.SearchControls controls, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 void search(javax.naming.Name base, java.lang.String filter, javax.naming.directory.SearchControls controls, NameClassPairCallbackHandler handler)
          Search for all objects matching the supplied filter.
 void search(SearchExecutor se, NameClassPairCallbackHandler handler)
          Perform a search operation, such as a search(), list() or listBindings().
 java.util.List search(java.lang.String base, java.lang.String filter, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(java.lang.String base, java.lang.String filter, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(java.lang.String base, java.lang.String filter, int searchScope, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 void search(java.lang.String base, java.lang.String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler)
          Search for all objects matching the supplied filter.
 java.util.List search(java.lang.String base, java.lang.String filter, int searchScope, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(java.lang.String base, java.lang.String filter, int searchScope, java.lang.String[] attrs, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(java.lang.String base, java.lang.String filter, int searchScope, java.lang.String[] attrs, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 void search(java.lang.String base, java.lang.String filter, NameClassPairCallbackHandler handler)
          Search for all objects matching the supplied filter.
 java.util.List search(java.lang.String base, java.lang.String filter, javax.naming.directory.SearchControls controls, AttributesMapper mapper)
          Search for all objects matching the supplied filter.
 java.util.List search(java.lang.String base, java.lang.String filter, javax.naming.directory.SearchControls controls, ContextMapper mapper)
          Search for all objects matching the supplied filter.
 void search(java.lang.String base, java.lang.String filter, javax.naming.directory.SearchControls controls, NameClassPairCallbackHandler handler)
          Search for all objects matching the supplied filter.
 void setContextSource(ContextSource contextSource)
          Set the ContextSource.
 void setExceptionTranslator(NamingExceptionTranslator exceptionTranslator)
          Set the NamingExceptionTranslator to be used by this instance.
 void setIgnorePartialResultException(boolean ignore)
          Specify whether PartialResultException should be ignored in searches.
 void unbind(javax.naming.Name dn)
          Remove an entry from the LDAP tree.
 void unbind(javax.naming.Name dn, boolean recursive)
          Remove an entry from the LDAP tree, optionally removing all descendants in the process.
 void unbind(java.lang.String dn)
          Remove an entry from the LDAP tree.
 void unbind(java.lang.String dn, boolean recursive)
          Remove an entry from the LDAP tree, optionally removing all descendants in the process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LdapTemplate

public LdapTemplate()
Constructor for bean usage.


LdapTemplate

public LdapTemplate(ContextSource contextSource)
Constructor to setup instance directly.

Parameters:
contextSource - the ContextSource to use.
Method Detail

setContextSource

public void setContextSource(ContextSource contextSource)
Set the ContextSource. Call this method when the default constructor has been used.

Parameters:
contextSource - the ContextSource.

setIgnorePartialResultException

public void setIgnorePartialResultException(boolean ignore)
Specify whether PartialResultException should be ignored in searches. AD servers typically have a problem with referrals. Normally a referral should be followed automatically, but this does not seem to work with AD servers. The problem manifests itself with a a PartialResultException being thrown when a referral is encountered by the server. Setting this property to true presents a workaround to this problem by causing PartialResultException to be ignored, so that the search method returns normally. Default value of this parameter is false.

Parameters:
ignore - true if PartialResultException should be ignored in searches, false otherwise. Default is false.

search

public void search(javax.naming.Name base,
                   java.lang.String filter,
                   int searchScope,
                   boolean returningObjFlag,
                   NameClassPairCallbackHandler handler)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. Each SearchResult is supplied to the specified NameClassPairCallbackHandler. Use the specified values for search scope and return objects flag.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
returningObjFlag - Whether the bound object should be returned in search results. Must be set to true if a ContextMapper is used.
handler - The NameClassPairCallbackHandler to supply the SearchResults to.

search

public void search(java.lang.String base,
                   java.lang.String filter,
                   int searchScope,
                   boolean returningObjFlag,
                   NameClassPairCallbackHandler handler)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. Each SearchResult is supplied to the specified NameClassPairCallbackHandler. Use the specified search scope and return objects flag in search controls.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
returningObjFlag - whether the bound object should be returned in search results.
handler - The NameClassPairCallbackHandler to supply the SearchResults to.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public void search(javax.naming.Name base,
                   java.lang.String filter,
                   javax.naming.directory.SearchControls controls,
                   NameClassPairCallbackHandler handler)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. Each SearchResult is supplied to the specified NameClassPairCallbackHandler. The SearchScope specified in the supplied SearchControls will be used in the search. Note that if you are using a ContextMapper, the returningObjFlag needs to be set to true in the SearchControls.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
controls - The SearchControls to use in the search.
handler - The NameClassPairCallbackHandler to supply the SearchResults to.

search

public void search(java.lang.String base,
                   java.lang.String filter,
                   javax.naming.directory.SearchControls controls,
                   NameClassPairCallbackHandler handler)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. See LdapOperations.search(Name, String, SearchControls, NameClassPairCallbackHandler) for details.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
controls - The SearchControls to use in the search.
handler - The NameClassPairCallbackHandler to supply the SearchResults to.

search

public void search(SearchExecutor se,
                   NameClassPairCallbackHandler handler)
Perform a search operation, such as a search(), list() or listBindings(). This method handles all the plumbing; getting a readonly context; looping through the NamingEnumeration and closing the context and enumeration. The actual list is delegated to the SearchExecutor and each NameClassPair (this might be a NameClassPair or a subclass thereof) is passed to the CallbackHandler. Any encountered NamingException will be translated using the NamingExceptionTranslator.

Specified by:
search in interface LdapOperations
Parameters:
se - the SearchExecutor to use for performing the actual list.
handler - the NameClassPairCallbackHandler to which each found entry will be passed.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public void search(javax.naming.Name base,
                   java.lang.String filter,
                   NameClassPairCallbackHandler handler)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. Each SearchResult is supplied to the specified NameClassPairCallbackHandler. The default Search scope (SearchControls.SUBTREE_SCOPE) will be used and the returnObjects flag will be set to false.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
handler - The NameClassPairCallbackHandler to supply the SearchResults to.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public void search(java.lang.String base,
                   java.lang.String filter,
                   NameClassPairCallbackHandler handler)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. Each SearchResult is supplied to the specified NameClassPairCallbackHandler. The default Search scope (SearchControls.SUBTREE_SCOPE) will be used and no the returnObjects will be set to false.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
handler - The NameClassPairCallbackHandler to supply the SearchResults to.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             int searchScope,
                             java.lang.String[] attrs,
                             AttributesMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. Only search for the specified attributes. The Attributes in each SearchResult is supplied to the specified AttributesMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
attrs - The attributes to return, null means returning all attributes.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the AttributesMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             int searchScope,
                             java.lang.String[] attrs,
                             AttributesMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. Only search for the specified attributes. The Attributes in each SearchResult is supplied to the specified AttributesMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
attrs - The attributes to return, null means returning all attributes.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the AttributesMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             int searchScope,
                             AttributesMapper mapper)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the AttributesMapper.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             int searchScope,
                             AttributesMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the AttributesMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             AttributesMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper. The default seach scope will be used.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the AttributesMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             AttributesMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper. The default seach scope will be used.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the AttributesMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             int searchScope,
                             java.lang.String[] attrs,
                             ContextMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. Only look for the supplied attributes.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
attrs - The attributes to return, null means all attributes.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             int searchScope,
                             java.lang.String[] attrs,
                             ContextMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. Only look for the supplied attributes.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
attrs - The attributes to return, null means all attributes.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             int searchScope,
                             ContextMapper mapper)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             int searchScope,
                             ContextMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
searchScope - The search scope to set in SearchControls.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             ContextMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. The default search scope (SearchControls.SUBTREE_SCOPE) will be used.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             ContextMapper mapper)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. The default search scope (SearchControls.SUBTREE_SCOPE) will be used.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             javax.naming.directory.SearchControls controls,
                             ContextMapper mapper)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
controls - The SearchControls to use in the search. If the returnObjFlag is not set in the SearchControls, this method will set it automatically, as this is required for the ContextMapper to work.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             javax.naming.directory.SearchControls controls,
                             ContextMapper mapper)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
controls - The SearchControls to use in the search. If the returnObjFlag is not set in the SearchControls, this method will set it automatically, as this is required for the ContextMapper to work.
mapper - The ContextMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.

search

public java.util.List search(javax.naming.Name base,
                             java.lang.String filter,
                             javax.naming.directory.SearchControls controls,
                             AttributesMapper mapper)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified AttributesMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
controls - The SearchControls to use in the search.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.

search

public java.util.List search(java.lang.String base,
                             java.lang.String filter,
                             javax.naming.directory.SearchControls controls,
                             AttributesMapper mapper)
Description copied from interface: LdapOperations
Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified AttributesMapper.

Specified by:
search in interface LdapOperations
Parameters:
base - The base DN where the search should begin.
filter - The filter to use in the search.
controls - The SearchControls to use in the search.
mapper - The AttributesMapper to use for translating each entry.
Returns:
a List containing all entries received from the ContextMapper.

list

public void list(java.lang.String base,
                 NameClassPairCallbackHandler handler)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Each resulting NameClassPair is supplied to the specified NameClassPairCallbackHandler.

Specified by:
list in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
handler - The NameClassPairCallbackHandler to supply each NameClassPair to.

list

public void list(javax.naming.Name base,
                 NameClassPairCallbackHandler handler)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Each resulting NameClassPair is supplied to the specified NameClassPairCallbackHandler.

Specified by:
list in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
handler - The NameClassPairCallbackHandler to supply each NameClassPair to.

list

public java.util.List list(java.lang.String base,
                           NameClassPairMapper mapper)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Pass all the found NameClassPair objects to the supplied NameClassPairMapper and return all the returned values as a List.

Specified by:
list in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
mapper - The NameClassPairMapper to supply each NameClassPair to.
Returns:
a List containing the Objects returned from the Mapper.

list

public java.util.List list(javax.naming.Name base,
                           NameClassPairMapper mapper)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Pass all the found NameClassPair objects to the supplied NameClassPairMapper and return all the returned values as a List.

Specified by:
list in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
mapper - The NameClassPairMapper to supply each NameClassPair to.
Returns:
a List containing the Objects returned from the Mapper.

list

public java.util.List list(javax.naming.Name base)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the contexts bound to the given base.

Specified by:
list in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
Returns:
a List containing the names of all the contexts bound to base.

list

public java.util.List list(java.lang.String base)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base.

Specified by:
list in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
Returns:
a List containing the names of all the contexts bound to base.

listBindings

public void listBindings(java.lang.String base,
                         NameClassPairCallbackHandler handler)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Each resulting Binding is supplied to the specified NameClassPairCallbackHandler.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
handler - The NameClassPairCallbackHandler to supply each Binding to.

listBindings

public void listBindings(javax.naming.Name base,
                         NameClassPairCallbackHandler handler)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Each resulting Binding is supplied to the specified NameClassPairCallbackHandler.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
handler - The NameClassPairCallbackHandler to supply each Binding to.

listBindings

public java.util.List listBindings(java.lang.String base,
                                   NameClassPairMapper mapper)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Pass all the found Binding objects to the supplied NameClassPairMapper and return all the returned values as a List.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
mapper - The NameClassPairMapper to supply each Binding to.
Returns:
a List containing the Objects returned from the Mapper.

listBindings

public java.util.List listBindings(javax.naming.Name base,
                                   NameClassPairMapper mapper)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. Pass all the found Binding objects to the supplied NameClassPairMapper and return all the returned values as a List.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
mapper - The NameClassPairMapper to supply each Binding to.
Returns:
a List containing the Objects returned from the Mapper.

listBindings

public java.util.List listBindings(java.lang.String base)
Description copied from interface: LdapOperations
Perform a non-recursive listing of children of the given base.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
Returns:
a List containing the names of all the contexts bound to base.

listBindings

public java.util.List listBindings(javax.naming.Name base)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
Returns:
a List containing the names of all the contexts bound to base.

listBindings

public java.util.List listBindings(java.lang.String base,
                                   ContextMapper mapper)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. The Object returned in each Binding is supplied to the specified ContextMapper.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
mapper - The ContextMapper to use for mapping the found object.
Returns:
a List containing all entries received from the ContextMapper.

listBindings

public java.util.List listBindings(javax.naming.Name base,
                                   ContextMapper mapper)
Description copied from interface: LdapOperations
Perform a non-recursive listing of the children of the given base. The Object returned in each Binding is supplied to the specified ContextMapper.

Specified by:
listBindings in interface LdapOperations
Parameters:
base - The base DN where the list should be performed.
mapper - The ContextMapper to use for mapping the found object.
Returns:
a List containing all entries received from the ContextMapper.

executeReadOnly

public java.lang.Object executeReadOnly(ContextExecutor ce)
Description copied from interface: LdapOperations
Perform an operation (or series of operations) on a read-only context. This method handles the plumbing - getting a DirContext, translating any Exceptions and closing the context afterwards. This method is not intended for searches; use LdapOperations.search(SearchExecutor, NameClassPairCallbackHandler) or any of the overloaded search methods for this.

Specified by:
executeReadOnly in interface LdapOperations
Parameters:
ce - The ContextExecutor to which the actual operation on the DirContext will be delegated.
Returns:
the result from the ContextExecutor's operation.

executeReadWrite

public java.lang.Object executeReadWrite(ContextExecutor ce)
Description copied from interface: LdapOperations
Perform an operation (or series of operations) on a read-write context. This method handles the plumbing - getting a DirContext, translating any exceptions and closing the context afterwards.

Specified by:
executeReadWrite in interface LdapOperations
Parameters:
ce - The ContextExecutor to which the actual operation on the DirContext will be delegated.
Returns:
the result from the ContextExecutor's operation.

lookup

public java.lang.Object lookup(javax.naming.Name dn)
Description copied from interface: LdapOperations
Lookup the supplied DN and return the found object. WARNING: This method should only be used if a DirObjectFactory has been specified on the ContextFactory. If this is not the case, you will get a new instance of the actual DirContext, which is probably not what you want. If, however this is what you want, be careful to close the context after you finished working with it.

Specified by:
lookup in interface LdapOperations
Parameters:
dn - The distinguished name of the object to find.
Returns:
the found object.

lookup

public java.lang.Object lookup(java.lang.String dn)
                        throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Lookup the supplied DN and return the found object. WARNING: This method should only be used if a DirObjectFactory has been specified on the ContextFactory. If this is not the case, you will get a new instance of the actual DirContext, which is probably not what you want. If, however this is what you want, be careful to close the context after you finished working with it.

Specified by:
lookup in interface LdapOperations
Parameters:
dn - The distinguished name of the object to find.
Returns:
the found object.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

lookup

public java.lang.Object lookup(javax.naming.Name dn,
                               AttributesMapper mapper)
Description copied from interface: LdapOperations
Convenience method to get the attributes of a specified DN and automatically pass them to an AttributesMapper.

Specified by:
lookup in interface LdapOperations
Parameters:
dn - The distinguished name to find.
mapper - The AttributesMapper to use for mapping the found object.
Returns:
the object returned from the mapper.

lookup

public java.lang.Object lookup(java.lang.String dn,
                               AttributesMapper mapper)
                        throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Convenience method to get the attributes of a specified DN and automatically pass them to an AttributesMapper.

Specified by:
lookup in interface LdapOperations
Parameters:
dn - The distinguished name to find.
mapper - The AttributesMapper to use for mapping the found object.
Returns:
the object returned from the mapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

lookup

public java.lang.Object lookup(javax.naming.Name dn,
                               ContextMapper mapper)
Description copied from interface: LdapOperations
Convenience method to lookup a specified DN and automatically pass the found object to a ContextMapper.

Specified by:
lookup in interface LdapOperations
Parameters:
dn - The distinguished name to find.
mapper - The ContextMapper to use for mapping the found object.
Returns:
the object returned from the mapper.

lookup

public java.lang.Object lookup(java.lang.String dn,
                               ContextMapper mapper)
                        throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Convenience method to lookup a specified DN and automatically pass the found object to a ContextMapper.

Specified by:
lookup in interface LdapOperations
Parameters:
dn - The distinguished name to find.
mapper - The ContextMapper to use for mapping the found object.
Returns:
the object returned from the mapper.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

modifyAttributes

public void modifyAttributes(javax.naming.Name dn,
                             javax.naming.directory.ModificationItem[] mods)
Description copied from interface: LdapOperations
Modify an entry in the LDAP tree using the supplied ModificationItems.

Specified by:
modifyAttributes in interface LdapOperations
Parameters:
dn - The distinguished name of the node to modify.
mods - The modifications to perform.

modifyAttributes

public void modifyAttributes(java.lang.String dn,
                             javax.naming.directory.ModificationItem[] mods)
                      throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Modify an entry in the LDAP tree using the supplied ModificationItems.

Specified by:
modifyAttributes in interface LdapOperations
Parameters:
dn - The distinguished name of the node to modify.
mods - The modifications to perform.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

bind

public void bind(javax.naming.Name dn,
                 java.lang.Object obj,
                 javax.naming.directory.Attributes attributes)
Description copied from interface: LdapOperations
Create an entry in the LDAP tree. The attributes used to create the entry are either retrieved from the obj parameter or the attributes parameter (or both). One of these parameters may be null but not both.

Specified by:
bind in interface LdapOperations
Parameters:
dn - The distinguished name to bind the object and attributes to.
obj - The object to bind, may be null. Typically a DirContext implementation.
attributes - The attributes to bind, may be null.

bind

public void bind(java.lang.String dn,
                 java.lang.Object obj,
                 javax.naming.directory.Attributes attributes)
          throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Create an entry in the LDAP tree. The attributes used to create the entry are either retrieved from the obj parameter or the attributes parameter (or both). One of these parameters may be null but not both.

Specified by:
bind in interface LdapOperations
Parameters:
dn - The distinguished name to bind the object and attributes to.
obj - The object to bind, may be null. Typically a DirContext implementation.
attributes - The attributes to bind, may be null.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

unbind

public void unbind(javax.naming.Name dn)
Description copied from interface: LdapOperations
Remove an entry from the LDAP tree. The entry must not have any children - if you suspect that the entry might have descendants, use LdapOperations.unbind(Name, boolean) in stead.

Specified by:
unbind in interface LdapOperations
Parameters:
dn - The distinguished name of the entry to remove.

unbind

public void unbind(java.lang.String dn)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Remove an entry from the LDAP tree. The entry must not have any children - if you suspect that the entry might have descendants, use LdapOperations.unbind(Name, boolean) in stead.

Specified by:
unbind in interface LdapOperations
Parameters:
dn - The distinguished name to unbind.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

unbind

public void unbind(javax.naming.Name dn,
                   boolean recursive)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Remove an entry from the LDAP tree, optionally removing all descendants in the process.

Specified by:
unbind in interface LdapOperations
Parameters:
dn - The distinguished name to unbind.
recursive - Whether to unbind all subcontexts as well. If this parameter is false and the entry has children, the operation will fail.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

unbind

public void unbind(java.lang.String dn,
                   boolean recursive)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Remove an entry from the LDAP tree, optionally removing all descendants in the process.

Specified by:
unbind in interface LdapOperations
Parameters:
dn - The distinguished name to unbind.
recursive - Whether to unbind all subcontexts as well. If this parameter is false and the entry has children, the operation will fail.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

deleteRecursively

protected void deleteRecursively(javax.naming.directory.DirContext ctx,
                                 DistinguishedName name)
                          throws org.springframework.dao.DataAccessException
Delete all subcontexts including the current one recursively.

Parameters:
ctx - The context to use for deleting.
name - The starting point to delete recursively.
Throws:
org.springframework.dao.DataAccessException - if any error occurs

rebind

public void rebind(javax.naming.Name dn,
                   java.lang.Object obj,
                   javax.naming.directory.Attributes attributes)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Remove an entry and replace it with a new one. The attributes used to create the entry are either retrieved from the obj parameter or the attributes parameter (or both). One of these parameters may be null but not both. This method assumes that the specified context already exists - if not it will fail.

Specified by:
rebind in interface LdapOperations
Parameters:
dn - The distinguished name to rebind.
obj - The object to bind to the DN, may be null. Typically a DirContext implementation.
attributes - The attributes to bind, may be null.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

rebind

public void rebind(java.lang.String dn,
                   java.lang.Object obj,
                   javax.naming.directory.Attributes attributes)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Remove an entry and replace it with a new one. The attributes used to create the entry are either retrieved from the obj parameter or the attributes parameter (or both). One of these parameters may be null but not both. This method assumes that the specified context already exists - if not it will fail.

Specified by:
rebind in interface LdapOperations
Parameters:
dn - The distinguished name to rebind.
obj - The object to bind to the DN, may be null. Typically a DirContext implementation.
attributes - The attributes to bind, may be null.
Throws:
org.springframework.dao.DataAccessException - if any error occurs.

rename

public void rename(javax.naming.Name oldDn,
                   javax.naming.Name newDn)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Move an entry in the LDAP tree to a new location.

Specified by:
rename in interface LdapOperations
Parameters:
oldDn - The distinguished name of the entry to move; may not be null or empty.
newDn - The distinguished name where the entry should be moved; may not be null or empty.
Throws:
org.springframework.dao.DataAccessException - if any other error occurs.

rename

public void rename(java.lang.String oldDn,
                   java.lang.String newDn)
            throws org.springframework.dao.DataAccessException
Description copied from interface: LdapOperations
Move an entry in the LDAP tree to a new location.

Specified by:
rename in interface LdapOperations
Parameters:
oldDn - The distinguished name of the entry to move; may not be null or empty.
newDn - The distinguished name where the entry should be moved; may not be null or empty.
Throws:
org.springframework.dao.DataAccessException - if any other error occurs.

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

getExceptionTranslator

public NamingExceptionTranslator getExceptionTranslator()
Get the NamingExceptionTranslator that will be used by this instance. If no exceptionTranslator has been set, a default instance will be created.

Returns:
the NamingExceptionTranslator to be used by this instance.

setExceptionTranslator

public void setExceptionTranslator(NamingExceptionTranslator exceptionTranslator)
Set the NamingExceptionTranslator to be used by this instance.

Parameters:
exceptionTranslator - the NamingExceptionTranslator to use.


Copyright 2002-2006. All Rights Reserved.