Package org.ldaptive.ad.control.util
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 Summary
Fields Modifier and Type Field Description private DirSyncControl.Flag[]
dirSyncFlags
DirSync flags.private LdapEntryHandler[]
entryHandlers
Functions to handle response entries.private ExceptionHandler
exceptionHandler
Function to handle exceptions.private ExtendedDnControl.Flag
extendedDnFlag
ExtendedDn flags.private ConnectionFactory
factory
Connection factory to get a connection from.protected Logger
logger
Logger for this class.private int
maxAttributeCount
Maximum attribute count.private SearchReferenceHandler[]
referenceHandlers
Functions to handle response references.private ResultHandler[]
resultHandlers
Functions to handle response results.private SearchResultHandler[]
searchResultHandlers
Functions to handle response results.private ResultPredicate
throwCondition
Function to test results.
-
Constructor Summary
Constructors Constructor Description DirSyncClient(ConnectionFactory cf)
Creates a new dir sync client.DirSyncClient(ConnectionFactory cf, DirSyncControl.Flag[] dsFlags)
Creates a new dir sync client.DirSyncClient(ConnectionFactory cf, DirSyncControl.Flag[] dsFlags, int count)
Creates a new dir sync client.
-
Method Summary
-
-
-
Field Detail
-
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 Detail
-
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 fromdsFlags
- 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 fromdsFlags
- to set on the dir sync controlcount
- max attribute count
-
-
Method Detail
-
getResultHandlers
public ResultHandler[] getResultHandlers()
-
setResultHandlers
public void setResultHandlers(ResultHandler... handlers)
-
getExceptionHandler
public ExceptionHandler getExceptionHandler()
-
setExceptionHandler
public void setExceptionHandler(ExceptionHandler handler)
-
getThrowCondition
public ResultPredicate getThrowCondition()
-
setThrowCondition
public void setThrowCondition(ResultPredicate function)
-
getEntryHandlers
public LdapEntryHandler[] getEntryHandlers()
-
setEntryHandlers
public void setEntryHandlers(LdapEntryHandler... handlers)
-
getReferenceHandlers
public SearchReferenceHandler[] getReferenceHandlers()
-
setReferenceHandlers
public void setReferenceHandlers(SearchReferenceHandler... handlers)
-
getSearchResultHandlers
public SearchResultHandler[] getSearchResultHandlers()
-
setSearchResultHandlers
public void setSearchResultHandlers(SearchResultHandler... 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 theDirSyncControl
. 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 theDirSyncControl
. The supplied request is modified in the following way:AbstractRequestMessage.setControls( org.ldaptive.control.RequestControl...)
is invoked withDirSyncControl
,ShowDeletedControl
, andExtendedDnControl
The cookie is extracted from the supplied response and replayed in the request.
- Parameters:
request
- search request to executeresult
- of a previous dir sync operation- Returns:
- search operation response
- Throws:
IllegalArgumentException
- if the response does not contain a dir sync cookieLdapException
- if the search fails
-
execute
public SearchResponse execute(SearchRequest request, CookieManager manager) throws LdapException
Performs a search operation with theDirSyncControl
. The supplied request is modified in the following way:AbstractRequestMessage.setControls( org.ldaptive.control.RequestControl...)
is invoked withDirSyncControl
,ShowDeletedControl
, andExtendedDnControl
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 executemanager
- for reading and writing cookies- Returns:
- search operation response
- Throws:
LdapException
- if the search fails
-
hasMore
public boolean hasMore(SearchResponse result)
Returns whetherexecute(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
Invokesexecute(SearchRequest, CookieManager)
with aDefaultCookieManager
.- 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 theDirSyncControl
. The supplied request is modified in the following way:AbstractRequestMessage.setControls( org.ldaptive.control.RequestControl...)
is invoked withDirSyncControl
,ShowDeletedControl
, andExtendedDnControl
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 executemanager
- 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
-
createRequestControls
private RequestControl[] createRequestControls(byte[] cookie)
Returns the list of request controls configured for this client.- Parameters:
cookie
- to add to the dir sync control or null- Returns:
- search request controls
-
-