Class DirSyncClient

java.lang.Object
org.ldaptive.ad.control.util.DirSyncClient

public class DirSyncClient extends Object
Client that simplifies using the active directory dir sync control.
  • Field Details

    • logger

      protected final Logger logger
      Logger for this class.
    • factory

      private final ConnectionFactory factory
      Connection factory to get a connection from.
    • dirSyncFlags

      private final DirSyncControl.Flag[] dirSyncFlags
      DirSync flags.
    • maxAttributeCount

      private final int maxAttributeCount
      Maximum attribute count.
    • extendedDnFlag

      private ExtendedDnControl.Flag extendedDnFlag
      ExtendedDn flags.
    • resultHandlers

      private ResultHandler[] resultHandlers
      Functions to handle response results.
    • exceptionHandler

      private ExceptionHandler exceptionHandler
      Function to handle exceptions.
    • throwCondition

      private ResultPredicate throwCondition
      Function to test results.
    • entryHandlers

      private LdapEntryHandler[] entryHandlers
      Functions to handle response entries.
    • referenceHandlers

      private SearchReferenceHandler[] referenceHandlers
      Functions to handle response references.
    • searchResultHandlers

      private SearchResultHandler[] searchResultHandlers
      Functions to handle response results.
  • Constructor Details

    • DirSyncClient

      public DirSyncClient(ConnectionFactory cf)
      Creates a new dir sync client.
      Parameters:
      cf - to get a connection from
    • DirSyncClient

      public DirSyncClient(ConnectionFactory cf, DirSyncControl.Flag[] dsFlags)
      Creates a new dir sync client.
      Parameters:
      cf - to get a connection from
      dsFlags - to set on the dir sync control
    • DirSyncClient

      public DirSyncClient(ConnectionFactory cf, DirSyncControl.Flag[] dsFlags, int count)
      Creates a new dir sync client.
      Parameters:
      cf - to get a connection from
      dsFlags - to set on the dir sync control
      count - max attribute count
  • Method Details

    • getResultHandlers

      public ResultHandler[] getResultHandlers()
      Returns the result handlers.
      Returns:
      result handlers
    • setResultHandlers

      public void setResultHandlers(ResultHandler... handlers)
      Sets the result handlers.
      Parameters:
      handlers - result handlers
    • getExceptionHandler

      public ExceptionHandler getExceptionHandler()
      Returns the exception handler.
      Returns:
      exception handler
    • setExceptionHandler

      public void setExceptionHandler(ExceptionHandler handler)
      Sets the exception handler.
      Parameters:
      handler - exception handler
    • getThrowCondition

      public ResultPredicate getThrowCondition()
      Returns the throw condition.
      Returns:
      throw condition
    • setThrowCondition

      public void setThrowCondition(ResultPredicate function)
      Sets the throw condition.
      Parameters:
      function - throw condition
    • getEntryHandlers

      public LdapEntryHandler[] getEntryHandlers()
      Returns the entry handlers.
      Returns:
      entry handlers
    • setEntryHandlers

      public void setEntryHandlers(LdapEntryHandler... handlers)
      Sets the entry handlers.
      Parameters:
      handlers - entry handlers
    • getReferenceHandlers

      public SearchReferenceHandler[] getReferenceHandlers()
      Returns the reference handlers.
      Returns:
      reference handlers
    • setReferenceHandlers

      public void setReferenceHandlers(SearchReferenceHandler... handlers)
      Sets the reference handlers.
      Parameters:
      handlers - reference handlers
    • getSearchResultHandlers

      public SearchResultHandler[] getSearchResultHandlers()
      Returns the search result handlers.
      Returns:
      search result handlers
    • setSearchResultHandlers

      public void setSearchResultHandlers(SearchResultHandler... handlers)
      Sets the search result handlers.
      Parameters:
      handlers - search result handlers
    • getExtendedDnFlag

      public ExtendedDnControl.Flag getExtendedDnFlag()
      Returns the flag that is used on the extended dn control.
      Returns:
      extended dn control flag
    • setExtendedDnFlag

      public void setExtendedDnFlag(ExtendedDnControl.Flag flag)
      Sets the flag to use on the extended dn control.
      Parameters:
      flag - to set on the extended dn control
    • execute

      public SearchResponse execute(SearchRequest request) throws LdapException
      Performs a search operation with the DirSyncControl. The supplied request is modified in the following way:
      Parameters:
      request - search request to execute
      Returns:
      search operation response
      Throws:
      LdapException - if the search fails
    • execute

      public SearchResponse execute(SearchRequest request, SearchResponse result) throws LdapException
      Performs a search operation with the DirSyncControl. The supplied request is modified in the following way:

      The cookie is extracted from the supplied response and replayed in the request.

      Parameters:
      request - search request to execute
      result - of a previous dir sync operation
      Returns:
      search operation response
      Throws:
      IllegalArgumentException - if the response does not contain a dir sync cookie
      LdapException - if the search fails
    • execute

      public SearchResponse execute(SearchRequest request, CookieManager manager) throws LdapException
      Performs a search operation with the DirSyncControl. The supplied request is modified in the following way:

      The cookie used in the request is read from the cookie manager and written to the cookie manager after a successful search, if the response contains a cookie.

      Parameters:
      request - search request to execute
      manager - for reading and writing cookies
      Returns:
      search operation response
      Throws:
      LdapException - if the search fails
    • hasMore

      public boolean hasMore(SearchResponse result)
      Returns whether execute(SearchRequest, SearchResponse) can be invoked again.
      Parameters:
      result - of a previous dir sync operation
      Returns:
      whether more dir sync results can be retrieved from the server
    • executeToCompletion

      public SearchResponse executeToCompletion(SearchRequest request) throws LdapException
      Parameters:
      request - search request to execute
      Returns:
      search operation response of the last dir sync operation
      Throws:
      LdapException - if the search fails
    • executeToCompletion

      public SearchResponse executeToCompletion(SearchRequest request, CookieManager manager) throws LdapException
      Performs a search operation with the DirSyncControl. The supplied request is modified in the following way:

      This method will continue to execute search operations until all dir sync search results have been retrieved from the server. The returned response contains the response data of the last dir sync operation plus the entries and references returned by all previous search operations.

      The cookie used for each request is read from the cookie manager and written to the cookie manager after a successful search, if the response contains a cookie.

      Parameters:
      request - search request to execute
      manager - for reading and writing cookies
      Returns:
      search operation response of the last dir sync operation
      Throws:
      LdapException - if the search fails
    • createSearchOperation

      protected SearchOperation createSearchOperation()
      Creates a new search operation configured with the properties on this client.
      Returns:
      new search operation
    • getDirSyncFlags

      protected long getDirSyncFlags(SearchResponse result)
      Returns the dir sync flags in the supplied response or -1 if no flags exists.
      Parameters:
      result - of a previous dir sync operation
      Returns:
      dir sync flags or -1
    • getDirSyncCookie

      protected byte[] getDirSyncCookie(SearchResponse result)
      Returns the dir sync cookie in the supplied response or null if no cookie exists.
      Parameters:
      result - of a previous dir sync operation
      Returns:
      dir sync cookie or null
    • appendRequestControls

      private RequestControl[] appendRequestControls(SearchRequest request, byte[] cookie)
      Creates a new array of request controls which includes the dir sync control, extended DN control and show deleted control. Any other request controls are included.
      Parameters:
      request - to read controls from
      cookie - to add to the dir sync control or null
      Returns:
      search request controls