Class LdapTemplate

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

public class LdapTemplate extends 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).

See Also:
  • Constructor Details

    • LdapTemplate

      public LdapTemplate()
      Constructor for bean usage.
    • LdapTemplate

      public LdapTemplate(ContextSource contextSource)
      Constructor to setup instance directly.
      Parameters:
      contextSource - the ContextSource to use.
  • Method Details

    • setContextSource

      public void setContextSource(ContextSource contextSource)
      Set the ContextSource. Call this method when the default constructor has been used.
      Parameters:
      contextSource - the ContextSource.
    • getObjectDirectoryMapper

      public ObjectDirectoryMapper getObjectDirectoryMapper()
      Get the configured ObjectDirectoryMapper. For internal use.
      Specified by:
      getObjectDirectoryMapper in interface LdapOperations
      Returns:
      the configured ObjectDirectoryMapper.
    • setObjectDirectoryMapper

      public void setObjectDirectoryMapper(ObjectDirectoryMapper odm)
      Set the ObjectDirectoryMapper instance to use.
      Parameters:
      odm - the ObejctDirectoryMapper to use.
      Since:
      2.0
    • getContextSource

      public ContextSource getContextSource()
      Get the ContextSource.
      Returns:
      the ContextSource.
    • setIgnoreNameNotFoundException

      public void setIgnoreNameNotFoundException(boolean ignore)
      Specify whether NameNotFoundException should be ignored in searches. In previous version, NameNotFoundException caused by the search base not being found was silently ignored. The default behavior is now to treat this as an error (as it should), and to convert and re-throw the exception. The ability to revert to the previous behavior still exists. The only difference is that the incident is in that case no longer silently ignored, but logged as a warning.
      Parameters:
      ignore - true if NameNotFoundException should be ignored in searches, false otherwise. Default is false.
      Since:
      1.3
    • 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 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.
    • setIgnoreSizeLimitExceededException

      public void setIgnoreSizeLimitExceededException(boolean ignore)
      Specify whether SizeLimitExceededException should be ignored in searches. This is typically what you want if you specify count limit in your search controls.
      Parameters:
      ignore - true if SizeLimitExceededException should be ignored in searches, false otherwise. Default is true.
      Since:
      2.0
    • setDefaultSearchScope

      public void setDefaultSearchScope(int defaultSearchScope)
      Set the default scope to be used in searches if not explicitly specified. Default is SearchControls.SUBTREE_SCOPE.
      Parameters:
      defaultSearchScope - the default search scope to use in searches. One of SearchControls.OBJECT_SCOPE, SearchControls.ONELEVEL_SCOPE, or SearchControls.SUBTREE_SCOPE
      Since:
      2.0
    • setDefaultTimeLimit

      public void setDefaultTimeLimit(int defaultTimeLimit)
      Set the default time limit be used in searches if not explicitly specified. Default is 0, indicating no time limit.
      Parameters:
      defaultTimeLimit - the default time limit to use in searches.
      Since:
      2.0
    • setDefaultCountLimit

      public void setDefaultCountLimit(int defaultCountLimit)
      Set the default count limit be used in searches if not explicitly specified. Default is 0, indicating no count limit.
      Parameters:
      defaultCountLimit - the default count limit to use in searches.
      Since:
      2.0
    • search

      public void search(Name base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler)
      Search for all objects matching the supplied filter. 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(String base, String filter, int searchScope, boolean returningObjFlag, NameClassPairCallbackHandler handler)
      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(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler)
      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 SearchResult to.
    • search

      public void search(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler)
      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 SearchResult to.
    • search

      public void search(Name base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor)
      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. The given DirContextProcessor will be called before and after the search.
      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 SearchResult to.
      processor - The DirContextProcessor to use before and after the search.
    • search

      public void search(String base, String filter, SearchControls controls, NameClassPairCallbackHandler handler, DirContextProcessor processor)
      Search for all objects matching the supplied filter. See LdapOperations.search(Name, String, SearchControls, NameClassPairCallbackHandler, DirContextProcessor) 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.
      processor - The DirContextProcessor to use before and after the search.
    • search

      public void search(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor)
      Perform a search operation, such as a search(), list() or listBindings(). This method handles all the plumbing; getting a readonly context; looping through the NamingEnumeration and closing the context and enumeration. It also calls the supplied DirContextProcessor before and after the search, respectively. This enables custom pre-processing and post-processing, like for example when handling paged results or other search controls.

      The actual list is delegated to the SearchExecutor and 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.
      processor - DirContextProcessor for custom pre- and post-processing. Must not be null. If no custom processing should take place, please use e.g. search(SearchExecutor, NameClassPairCallbackHandler).
      Throws:
      NamingException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.
    • search

      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:
      NamingException - if any error occurs. Note that a NameNotFoundException will be ignored. Instead this is interpreted that no entries were found.
      See Also:
    • search

      public void search(Name base, String filter, NameClassPairCallbackHandler handler)
      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.
    • search

      public void search(String base, String filter, NameClassPairCallbackHandler handler)
      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.
    • search

      public <T> List<T> search(Name base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper)
      Search for all objects matching the supplied filter. Only return any attributes mathing the specified attribute names. The Attributes in 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.
    • search

      public <T> List<T> search(String base, String filter, int searchScope, String[] attrs, AttributesMapper<T> mapper)
      Search for all objects matching the supplied filter. Only return any attributes mathing the specified attribute names. The Attributes in 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.
    • search

      public <T> List<T> search(Name base, String filter, int searchScope, AttributesMapper<T> mapper)
      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 <T> List<T> search(String base, String filter, int searchScope, AttributesMapper<T> mapper)
      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 <T> List<T> search(Name base, String filter, AttributesMapper<T> mapper)
      Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper. The default search 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.
    • search

      public <T> List<T> search(String base, String filter, AttributesMapper<T> mapper)
      Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper. The default search 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.
    • search

      public <T> List<T> search(Name base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper)
      Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. Only return 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.
    • search

      public <T> List<T> search(String base, String filter, int searchScope, String[] attrs, ContextMapper<T> mapper)
      Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. Only return 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.
    • search

      public <T> List<T> search(Name base, String filter, int searchScope, ContextMapper<T> mapper)
      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 <T> List<T> search(String base, String filter, int searchScope, ContextMapper<T> mapper)
      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 <T> List<T> search(Name base, String filter, ContextMapper<T> mapper)
      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.
    • search

      public <T> List<T> search(String base, String filter, ContextMapper<T> mapper)
      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.
    • search

      public <T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper)
      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.
    • search

      public <T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper)
      Search for all objects matching the supplied filter. The Object returned in 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 <T> List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper)
      Search for all objects matching the supplied filter. The Attributes returned in 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 <T> List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper)
      Search for all objects matching the supplied filter. The Attributes returned in 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 <T> List<T> search(String base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor)
      Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper. The SearchScope specified in the supplied SearchControls will be used in the search. The given DirContextProcessor will be called before and after the search.
      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.
      processor - The DirContextProcessor to use before and after the search.
      Returns:
      a List containing all entries received from the AttributesMapper.
    • search

      public <T> List<T> search(Name base, String filter, SearchControls controls, AttributesMapper<T> mapper, DirContextProcessor processor)
      Search for all objects matching the supplied filter. The Attributes in each SearchResult is supplied to the specified AttributesMapper. The SearchScope specified in the supplied SearchControls will be used in the search. The given DirContextProcessor will be called before and after the search.
      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.
      processor - The DirContextProcessor to use before and after the search.
      Returns:
      a List containing all entries received from the AttributesMapper.
    • search

      public <T> List<T> search(String base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor)
      Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. The SearchScope specified in the supplied SearchControls will be used in the search. The given DirContextProcessor will be called before and after the search.
      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.
      processor - The DirContextProcessor to use before and after the search.
      Returns:
      a List containing all entries received from the ContextMapper.
    • search

      public <T> List<T> search(Name base, String filter, SearchControls controls, ContextMapper<T> mapper, DirContextProcessor processor)
      Search for all objects matching the supplied filter. The Object returned in each SearchResult is supplied to the specified ContextMapper. The SearchScope specified in the supplied SearchControls will be used in the search. The given DirContextProcessor will be called before and after the search.
      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.
      processor - The DirContextProcessor to use before and after the search.
      Returns:
      a List containing all entries received from the ContextMapper.
    • list

      public void list(String base, NameClassPairCallbackHandler handler)
      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(Name base, NameClassPairCallbackHandler handler)
      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 <T> List<T> list(String base, NameClassPairMapper<T> mapper)
      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 <T> List<T> list(Name base, NameClassPairMapper<T> mapper)
      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 List<String> list(Name base)
      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.
    • list

      public List<String> list(String base)
      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(String base, NameClassPairCallbackHandler handler)
      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(Name base, NameClassPairCallbackHandler handler)
      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 <T> List<T> listBindings(String base, NameClassPairMapper<T> mapper)
      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 <T> List<T> listBindings(Name base, NameClassPairMapper<T> mapper)
      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 List<String> listBindings(String base)
      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 List<String> listBindings(Name base)
      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 <T> List<T> listBindings(String base, ContextMapper<T> mapper)
      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 <T> List<T> listBindings(Name base, ContextMapper<T> mapper)
      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 <T> T executeReadOnly(ContextExecutor<T> ce)
      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.
      See Also:
    • executeReadWrite

      public <T> T executeReadWrite(ContextExecutor<T> ce)
      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. This method is intended only for very particular cases, where there is no suitable method in this interface to use.
      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.
      See Also:
    • lookup

      public Object lookup(Name dn)
      Lookup the supplied DN and return the found object. This will typically be a DirContextAdapter, unless the DirObjectFactory has been modified in the ContextSource.
      Specified by:
      lookup in interface LdapOperations
      Parameters:
      dn - The distinguished name of the object to find.
      Returns:
      the found object, typically a DirContextAdapter instance.
      See Also:
    • lookup

      public Object lookup(String dn)
      Lookup the supplied DN and return the found object. This will typically be a DirContextAdapter, unless the DirObjectFactory has been modified in the ContextSource.
      Specified by:
      lookup in interface LdapOperations
      Parameters:
      dn - The distinguished name of the object to find.
      Returns:
      the found object, typically a DirContextAdapter instance.
      See Also:
    • lookup

      public <T> T lookup(Name dn, AttributesMapper<T> mapper)
      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 <T> T lookup(String dn, AttributesMapper<T> mapper)
      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 <T> T lookup(Name dn, ContextMapper<T> mapper)
      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 <T> T lookup(String dn, ContextMapper<T> mapper)
      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 <T> T lookup(Name dn, String[] attributes, AttributesMapper<T> mapper)
      Convenience method to get the specified attributes of a specified DN and automatically pass them to an AttributesMapper.
      Specified by:
      lookup in interface LdapOperations
      Parameters:
      dn - The distinguished name to find.
      attributes - The names of the attributes to pass to the mapper.
      mapper - The AttributesMapper to use for mapping the found object.
      Returns:
      the object returned from the mapper.
    • lookup

      public <T> T lookup(String dn, String[] attributes, AttributesMapper<T> mapper)
      Convenience method to get the specified attributes of a specified DN and automatically pass them to an AttributesMapper.
      Specified by:
      lookup in interface LdapOperations
      Parameters:
      dn - The distinguished name to find.
      attributes - The names of the attributes to pass to the mapper.
      mapper - The AttributesMapper to use for mapping the found object.
      Returns:
      the object returned from the mapper.
    • lookup

      public <T> T lookup(Name dn, String[] attributes, ContextMapper<T> mapper)
      Convenience method to get the specified attributes of a specified DN and automatically pass them to a ContextMapper.
      Specified by:
      lookup in interface LdapOperations
      Parameters:
      dn - The distinguished name to find.
      attributes - The names of the attributes to pass to the mapper.
      mapper - The ContextMapper to use for mapping the found object.
      Returns:
      the object returned from the mapper.
    • lookup

      public <T> T lookup(String dn, String[] attributes, ContextMapper<T> mapper)
      Convenience method to get the specified attributes of a specified DN and automatically pass them to a ContextMapper.
      Specified by:
      lookup in interface LdapOperations
      Parameters:
      dn - The distinguished name to find.
      attributes - The names of the attributes to pass to the mapper.
      mapper - The ContextMapper to use for mapping the found object.
      Returns:
      the object returned from the mapper.
    • modifyAttributes

      public void modifyAttributes(Name dn, ModificationItem[] mods)
      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.
      See Also:
    • modifyAttributes

      public void modifyAttributes(String dn, ModificationItem[] mods)
      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.
      See Also:
    • bind

      public void bind(Name dn, Object obj, Attributes attributes)
      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.
      See Also:
    • bind

      public void bind(String dn, Object obj, Attributes attributes)
      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.
      See Also:
    • unbind

      public void unbind(Name dn)
      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(String dn)
      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.
    • unbind

      public void unbind(Name dn, boolean recursive)
      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.
    • unbind

      public void unbind(String dn, boolean recursive)
      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.
    • deleteRecursively

      protected void deleteRecursively(DirContext ctx, Name name)
      Delete all subcontexts including the current one recursively.
      Parameters:
      ctx - The context to use for deleting.
      name - The starting point to delete recursively.
      Throws:
      NamingException - if any error occurs
    • rebind

      public void rebind(Name dn, Object obj, Attributes attributes)
      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.
      See Also:
    • rebind

      public void rebind(String dn, Object obj, Attributes attributes)
      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.
      See Also:
    • rename

      public void rename(Name oldDn, Name newDn)
      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.
    • rename

      public void rename(String oldDn, String newDn)
      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.
    • afterPropertiesSet

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

      public DirContextOperations lookupContext(Name dn)
      Convenience method to lookup the supplied DN and automatically cast it to DirContextOperations.
      Specified by:
      lookupContext in interface LdapOperations
      Parameters:
      dn - The distinguished name of the object to find.
      Returns:
      The found object, cast to DirContextOperations.
      See Also:
    • lookupContext

      public DirContextOperations lookupContext(String dn)
      Convenience method to lookup the supplied DN and automatically cast it to DirContextOperations.
      Specified by:
      lookupContext in interface LdapOperations
      Parameters:
      dn - The distinguished name of the object to find.
      Returns:
      The found object, cast to DirContextOperations.
      See Also:
    • modifyAttributes

      public void modifyAttributes(DirContextOperations ctx)
      Modify the attributes of the entry referenced by the supplied DirContextOperations instance. The DN to update will be the DN of the DirContextOperationsinstance, and the ModificationItem array is retrieved from the DirContextOperations instance using a call to AttributeModificationsAware.getModificationItems(). NB: The supplied instance needs to have been properly initialized; this means that if it hasn't been received from a lookup operation, its DN needs to be initialized and it must have been put in update mode ( DirContextAdapter.setUpdateMode(boolean)).

      Typical use of this method would be as follows:

       public void update(Person person) {
              DirContextOperations ctx = ldapOperations.lookupContext(person.getDn());
      
              ctx.setAttributeValue("description", person.getDescription());
              ctx.setAttributeValue("telephoneNumber", person.getPhone());
              // More modifications here
      
              ldapOperations.modifyAttributes(ctx);
       }
       
      Specified by:
      modifyAttributes in interface LdapOperations
      Parameters:
      ctx - the DirContextOperations instance to use in the update.
      See Also:
    • bind

      public void bind(DirContextOperations ctx)
      Bind the data in the supplied context in the tree. All specified attributes ctxin will be bound to the DN set on ctx.

      Example:

       DirContextOperations ctx = new DirContextAdapter(dn);
       ctx.setAttributeValue("cn", "john doe");
       ctx.setAttributeValue("description", "some description");
       //More initialization here.
      
       ldapTemplate.bind(ctx);
       
      Specified by:
      bind in interface LdapOperations
      Parameters:
      ctx - the context to bind
    • rebind

      public void rebind(DirContextOperations ctx)
      Remove an entry and replace it with a new one. The attributes used to create the entry are retrieved from the ctx parameter. This method assumes that the specified context already exists - if not it will fail. The entry will be bound to the DN set on ctx.

      Example:

       DirContextOperations ctx = new DirContextAdapter(dn);
       ctx.setAttributeValue("cn", "john doe");
       ctx.setAttributeValue("description", "some description");
       //More initialization here.
      
       ldapTemplate.rebind(ctx);
       
      Specified by:
      rebind in interface LdapOperations
      Parameters:
      ctx - the context to rebind
    • authenticate

      public boolean authenticate(Name base, String filter, String password)
      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 to ContextSource.getContext(String, String), thus authenticating the entry.

      Example:

       AndFilter filter = new AndFilter();
       filter.and("objectclass", "person").and("uid", userId);
       boolean authenticated = ldapTemplate.authenticate(LdapUtils.emptyLdapName(), filter.toString(), password);
       
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      Returns:
      true if the authentication was successful, false otherwise.
    • authenticate

      public boolean authenticate(String base, String filter, String password)
      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 to ContextSource.getContext(String, String), thus authenticating the entry.

      Example:

       AndFilter filter = new AndFilter();
       filter.and("objectclass", "person").and("uid", userId);
       boolean authenticated = ldapTemplate.authenticate(LdapUtils.emptyLdapName(), filter.toString(), password);
       
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      Returns:
      true if the authentication was successful, false otherwise.
    • authenticate

      public boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback)
      Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input to ContextSource.getContext(String, String), thus authenticating the entry. The resulting DirContext instance is then used as input to the supplied AuthenticatedLdapEntryContextCallback to perform any additional LDAP operations against the authenticated DirContext.
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      callback - the callback to that will be called to perform operations on the DirContext authenticated with the found user.
      Returns:
      true if the authentication was successful, false otherwise.
      See Also:
    • authenticate

      public boolean authenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback)
      Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input to ContextSource.getContext(String, String), thus authenticating the entry. The resulting DirContext instance is then used as input to the supplied AuthenticatedLdapEntryContextCallback to perform any additional LDAP operations against the authenticated DirContext.
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      callback - the callback to that will be called to perform operations on the DirContext authenticated with the found user.
      Returns:
      true if the authentication was successful, false otherwise.
      See Also:
    • authenticate

      public boolean authenticate(String base, String filter, String password, AuthenticationErrorCallback errorCallback)
      Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input to ContextSource.getContext(String, String), thus authenticating the entry. If an exception is caught, the same exception is passed on to the given AuthenticationErrorCallback. This enables the caller to provide a callback that, for example, collects the exception for later processing.
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      errorCallback - the callback that will be called if an exception is caught.
      Returns:
      true if the authentication was successful, false otherwise.
    • authenticate

      public boolean authenticate(Name base, String filter, String password, AuthenticationErrorCallback errorCallback)
      Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input to ContextSource.getContext(String, String), thus authenticating the entry. If an exception is caught, the same exception is passed on to the given AuthenticationErrorCallback. This enables the caller to provide a callback that, for example, collects the exception for later processing.
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      errorCallback - the callback that will be called if an exception is caught.
      Returns:
      true if the authentication was successful, false otherwise.
      See Also:
    • authenticate

      public boolean authenticate(String base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback)
      Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input to ContextSource.getContext(String, String), thus authenticating the entry. The resulting DirContext instance is then used as input to the supplied AuthenticatedLdapEntryContextCallback to perform any additional LDAP operations against the authenticated DirContext. If an exception is caught, the same exception is passed on to the given AuthenticationErrorCallback. This enables the caller to provide a callback that, for example, collects the exception for later processing.
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      callback - the callback that will be called to perform operations on the DirContext authenticated with the found user.
      errorCallback - the callback that will be called if an exception is caught.
      Returns:
      true if the authentication was successful, false otherwise.
      See Also:
    • authenticate

      public boolean authenticate(Name base, String filter, String password, AuthenticatedLdapEntryContextCallback callback, AuthenticationErrorCallback errorCallback)
      Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied base DN and filter; use the DN of the found entry together with the password as input to ContextSource.getContext(String, String), thus authenticating the entry. The resulting DirContext instance is then used as input to the supplied AuthenticatedLdapEntryContextCallback to perform any additional LDAP operations against the authenticated DirContext. If an exception is caught, the same exception is passed on to the given AuthenticationErrorCallback. This enables the caller to provide a callback that, for example, collects the exception for later processing.
      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter - must result in a unique result.
      password - the password to use for authentication.
      callback - the callback that will be called to perform operations on the DirContext authenticated with the found user.
      errorCallback - the callback that will be called if an exception is caught.
      Returns:
      true if the authentication was successful, false otherwise.
      See Also:
    • authenticate

      public <T> T authenticate(LdapQuery query, String password, AuthenticatedLdapEntryContextMapper<T> mapper)
      Utility method to perform a simple LDAP 'bind' authentication. Search for the LDAP entry to authenticate using the supplied LdapQuery; use the DN of the found entry together with the password as input to ContextSource.getContext(String, String), thus authenticating the entry.

      Note: This method differs from the older authenticate methods in that encountered exceptions are thrown rather than supplied to a callback for handling.

      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      query - the LdapQuery specifying the details of the search.
      password - the password to use for authentication.
      mapper - the callback that will be called to perform operations on the DirContext authenticated with the found user. false otherwise.
      Returns:
      the result from the callback.
      See Also:
    • authenticate

      public void authenticate(LdapQuery query, String password)
      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 to ContextSource.getContext(String, String), thus authenticating the entry. If an exception is caught, the same exception is passed on to the given AuthenticationErrorCallback. This enables the caller to provide a callback that, for example, collects the exception for later processing.

      Note: This method differs from the older authenticate methods in that encountered exceptions are thrown rather than supplied to a callback for handling.

      Specified by:
      authenticate in interface LdapOperations
      Parameters:
      query - the LdapQuery specifying the details of the search.
      password - the password to use for authentication. false otherwise.
      See Also:
    • searchForObject

      public <T> T searchForObject(Name base, String filter, ContextMapper<T> mapper)
      Perform a search for a unique entry matching the specified search criteria and return the found object. If no entry is found or if there are more than one matching entry, an IncorrectResultSizeDataAccessException is thrown.
      Specified by:
      searchForObject in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter.
      mapper - the mapper to use for the search.
      Returns:
      the single object returned by the mapper that matches the search criteria.
    • searchForObject

      public <T> T searchForObject(String base, String filter, 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, an IncorrectResultSizeDataAccessException is thrown.
      Specified by:
      searchForObject in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter.
      mapper - the mapper to use for the search.
      Returns:
      the single object returned by the mapper that matches the search criteria.
    • searchForObject

      public <T> T searchForObject(Name base, String filter, SearchControls searchControls, ContextMapper<T> mapper)
      Perform a search for a unique entry matching the specified search criteria and return the found object. If no entry is found or if there are more than one matching entry, an IncorrectResultSizeDataAccessException is thrown.
      Specified by:
      searchForObject in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter.
      searchControls - the searchControls to use for the search.
      mapper - the mapper to use for the search.
      Returns:
      the single object returned by the mapper that matches the search criteria.
    • searchForObject

      public <T> T searchForObject(String base, String filter, SearchControls searchControls, ContextMapper<T> mapper)
      Perform a search for a unique entry matching the specified search criteria and return the found object. If no entry is found or if there are more than one matching entry, an IncorrectResultSizeDataAccessException is thrown.
      Specified by:
      searchForObject in interface LdapOperations
      Parameters:
      base - the DN to use as the base of the search.
      filter - the search filter.
      searchControls - the searchControls to use for the search.
      mapper - the mapper to use for the search.
      Returns:
      the single object returned by the mapper that matches the search criteria.
    • search

      public void search(LdapQuery query, NameClassPairCallbackHandler callbackHandler)
      Perform a search with parameters from the specified LdapQuery. All found objects will be supplied to the NameClassPairCallbackHandler for processing.
      Specified by:
      search in interface LdapOperations
      Parameters:
      query - the LDAP query specification.
      callbackHandler - the NameClassPairCallbackHandler to supply all found entries to.
      See Also:
    • search

      public <T> List<T> search(LdapQuery query, ContextMapper<T> mapper)
      Perform a search with parameters from the specified LdapQuery. All found objects will be supplied to the ContextMapper for processing, and all returned objects will be collected in a list to be returned.
      Specified by:
      search in interface LdapOperations
      Parameters:
      query - the LDAP query specification.
      mapper - the ContextMapper to supply all found entries to.
      Returns:
      a List containing all entries received from the ContextMapper.
      See Also:
    • search

      public <T> List<T> search(LdapQuery query, AttributesMapper<T> mapper)
      Perform a search with parameters from the specified LdapQuery. The Attributes of the found entries will be supplied to the AttributesMapper for processing, and all returned objects will be collected in a list to be returned.
      Specified by:
      search in interface LdapOperations
      Parameters:
      query - the LDAP query specification.
      mapper - the Attributes to supply all found Attributes to.
      Returns:
      a List containing all entries received from the Attributes.
      See Also:
    • searchForContext

      public DirContextOperations searchForContext(LdapQuery query)
      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, an IncorrectResultSizeDataAccessException is thrown.
      Specified by:
      searchForContext in interface LdapOperations
      Parameters:
      query - the LDAP query specification.
      Returns:
      the single entry matching the query as a DirContextOperations instance.
      See Also:
    • searchForObject

      public <T> T searchForObject(LdapQuery query, ContextMapper<T> mapper)
      Perform a search for a unique entry matching the specified LDAP query and return the found object. If no entry is found or if there are more than one matching entry, an IncorrectResultSizeDataAccessException is thrown.
      Specified by:
      searchForObject in interface LdapOperations
      Parameters:
      query - the LDAP query specification.
      Returns:
      the single object returned by the mapper that matches the search criteria.
      See Also:
    • searchForStream

      public <T> Stream<T> searchForStream(LdapQuery query, AttributesMapper<T> attributesMapper)
      Perform a search with parameters from the specified LdapQuery. The Attributes of the found entries will be supplied to the AttributesMapper for processing, and all returned objects will be collected in a list to be returned.
      Specified by:
      searchForStream in interface LdapOperations
      Parameters:
      query - the LDAP query specification.
      attributesMapper - the Attributes to supply all found Attributes to.
      Returns:
      a Stream of all entries received from the Attributes.
      See Also:
    • searchForStream

      public <T> Stream<T> searchForStream(LdapQuery query, ContextMapper<T> mapper)
      Perform a search with parameters from the specified LdapQuery. All found objects will be supplied to the ContextMapper for processing, and all returned objects will be collected in a list to be returned.
      Specified by:
      searchForStream in interface LdapOperations
      Parameters:
      query - the LDAP query specification.
      mapper - the ContextMapper to supply all found entries to.
      Returns:
      a Stream of all entries received from the ContextMapper.
      See Also:
    • findByDn

      public <T> T findByDn(Name dn, Class<T> clazz)
      Read a named entry from the LDAP directory. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations.
      Specified by:
      findByDn in interface LdapOperations
      Type Parameters:
      T - The Java type to return
      Parameters:
      dn - The distinguished name of the entry to read from the LDAP directory.
      clazz - The Java type to return
      Returns:
      The entry as read from the directory
    • create

      public void create(Object entry)
      Create the given entry in the LDAP directory. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations. If the field annotated with Id is set in the object, this will be used as the distinguished name of the new entry. If no explicit DN is specified, an attempt will be made to calculate the name from fields annotated with DnAttribute. If an id can be calculated, this will be populated in the supplied object.
      Specified by:
      create in interface LdapOperations
      Parameters:
      entry - The entry to be create, it must not be null or already exist in the directory.
    • update

      public void update(Object entry)
      Update the given entry in the LDAP directory. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations. If the distinguished name is not explicitly specified (i.e. if the field annotated with Id is null), an attempt will be made to calculate the name from fields annotated with DnAttribute. If the Id field and the calculated DN is different, the entry will be moved (i.e., an LdapOperations.unbind(javax.naming.Name) followed by a LdapOperations.bind(DirContextOperations). Otherwise the current data of the entry will be read from the directory and a LdapOperations.modifyAttributes(DirContextOperations) operation will be performed using the ModificationItems resulting from the changes of the entry compared to its current state in the directory. If the id of the entry has changed, i.e. if it wasn't specified from the beginning, or if it is calculated to have changed, the new value will be populated in the supplied object.
      Specified by:
      update in interface LdapOperations
      Parameters:
      entry - The entry to update, it must already exist in the directory.
    • delete

      public void delete(Object entry)
      Delete an entry from the LDAP directory. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations. If the field annotated with Id is set in the object, this will be used as the distinguished name of the new entry. If no explicit DN is specified, an attempt will be made to calculate the name from fields annotated with DnAttribute.
      Specified by:
      delete in interface LdapOperations
      Parameters:
      entry - The entry to delete, it must already exist in the directory.
    • findAll

      public <T> List<T> findAll(Name base, SearchControls searchControls, Class<T> clazz)
      Find all entries in the LDAP directory of a given type. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations.
      Specified by:
      findAll in interface LdapOperations
      Type Parameters:
      T - The Java type to return
      Parameters:
      base - The root of the sub-tree at which to begin the search.
      searchControls - The search controls of the search. Note that the 'returned attributes' parameter should typically not be tampered with, since that may affect the attributes populated in returned entries.
      clazz - The Java type to return
      Returns:
      All entries that are of the type represented by the given Java class
    • findAll

      public <T> List<T> findAll(Class<T> clazz)
      Find all entries in the LDAP directory of a given type. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations.
      Specified by:
      findAll in interface LdapOperations
      Type Parameters:
      T - The Java type to return
      Parameters:
      clazz - The Java type to return
      Returns:
      All entries that are of the type represented by the given Java class
    • find

      public <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. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations.
      Specified by:
      find in interface LdapOperations
      Type Parameters:
      T - The Java type to return
      Parameters:
      base - The root of the sub-tree at which to begin the search.
      filter - The search filter.
      searchControls - The search controls of the search. Note that the 'returned attributes' parameter should typically not be tampered with, since that may affect the attributes populated in returned entries.
      clazz - The Java type to return
      Returns:
      All entries that are of the type represented by the given Java class
    • find

      public <T> List<T> find(LdapQuery query, Class<T> clazz)
      Search for entries in the LDAP directory. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations.

      Only those entries that both match the query search filter and are represented by the given Java class are returned.

      Specified by:
      find in interface LdapOperations
      Type Parameters:
      T - The Java type to return
      Parameters:
      query - the LDAP query specification
      clazz - The Java type to return
      Returns:
      All matching entries.
      See Also:
    • findOne

      public <T> T findOne(LdapQuery query, Class<T> clazz)
      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 using Entry and associated annotations.
      Specified by:
      findOne in interface LdapOperations
      Type Parameters:
      T - The Java type to return
      Parameters:
      query - the LDAP query specification
      clazz - The Java type to return
      Returns:
      The single entry matching the search specification.
    • findForStream

      public <T> Stream<T> findForStream(LdapQuery query, Class<T> clazz)
      Search for entries in the LDAP directory. The referenced class must have object-directory mapping metadata specified using Entry and associated annotations.

      Only those entries that both match the query search filter and are represented by the given Java class are returned.

      Specified by:
      findForStream in interface LdapOperations
      Type Parameters:
      T - The Java type to return
      Parameters:
      query - the LDAP query specification
      clazz - The Java type to return
      Returns:
      All matching entries.
      See Also: