Package com.nimbusds.ldapsync
Class SyncTask
- java.lang.Object
-
- java.util.TimerTask
-
- com.nimbusds.ldapsync.SyncTask
-
- All Implemented Interfaces:
Runnable
public class SyncTask extends TimerTask
Routine for uploading and updating entries from a source LDAP v3 directory to a target LDAP v3 directory accessed by means of a Json2Ldap web API.The routine performs the following steps:
- Retrieves the source directory entries for upload / update by
making an LDAP search request using the specified
Configuration.SourceDirectory.Searchcriteria. - Retrieves all previously uploaded entries in the target directory
under the
Configuration.TargetDirectory.baseDnbranch (using LDAP search). - Uploads the source directory entries that are missing in the target
branch (using LDAP add). They receive an RDN attribute
Configuration.TargetDirectory.rdnAttribute. The attributes to upload and their source name -> target name mapping is given byConfiguration.Sync.attributeMap. - Updates the target entries whose corresponding mapped source entry attributes have changed (using LDAP modify).
- Deletes the target directory entries that don't have a corresponding source entry (using LDAP delete).
The
run()method performs the upload and update algorithm. TheTimerTaskinterface of this class can be used to run the synchronisation periodically on a dedicated thread.During the run of a sync task
subscribedobjects receive events that allow the progress and any exceptions to be monitored. The event types are described in therun()method comments.
-
-
Constructor Summary
Constructors Constructor Description SyncTask(Configuration config)Creates a new synchronisation task with the specified configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddListener(SyncTaskEventListener listener)Registers a new listener for synchronisation task events.protected List<ModifySpec>compareForUpdate(com.unboundid.ldap.sdk.Entry sourceEntry, com.unboundid.ldap.sdk.Entry targetEntry)Compares the attributes of the specified source (reference) entry and target entry and if they differ returns a non-empty list of modification specifications to apply to the target entry.booleanremoveListener(SyncTaskEventListener listener)Unregisters a listener for synchronisation task events.voidrun()Runs the synchronisation task.-
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
-
-
-
Constructor Detail
-
SyncTask
public SyncTask(Configuration config)
Creates a new synchronisation task with the specified configuration.- Parameters:
config- The configuration parameters.
-
-
Method Detail
-
addListener
public boolean addListener(SyncTaskEventListener listener)
Registers a new listener for synchronisation task events.- Parameters:
listener- The listener.- Returns:
trueif the listener is not already registered.
-
removeListener
public boolean removeListener(SyncTaskEventListener listener)
Unregisters a listener for synchronisation task events.- Parameters:
listener- The listener.- Returns:
trueif the specified listener was registered.
-
compareForUpdate
protected List<ModifySpec> compareForUpdate(com.unboundid.ldap.sdk.Entry sourceEntry, com.unboundid.ldap.sdk.Entry targetEntry)
Compares the attributes of the specified source (reference) entry and target entry and if they differ returns a non-empty list of modification specifications to apply to the target entry.- Parameters:
sourceEntry- The source (reference) directory entry, with any required attribute name mapping applied.targetEntry- The corresponding target directory entry.- Returns:
- The necessary modification specifications, empty if the attributes of the two entries match.
-
run
public void run()
Runs the synchronisation task.Emits the following events to registered listeners:
SyncTaskStartEventStart of the synchronisation task.SyncTaskEventSimple messages to indicate events such as the opening of a connection to the source or target directory, successful authentication, etc.SourceEntryRetrievalEventRetrieval of a particular matching search result entry from the source directory.SourceSearchCompleteEventCompletion of the retrieval of the matching source directory entries.TargetEntryRetrievalEventRetrieval of a particular matching search result entry from the target directory.TargetSearchCompleteEventCompletion of the retrieval of the matching target directory entries.AddEntryEventUpload of an entry from the source directory that did't exist in the target directory.UpdateEntryEventUpdate of an entry in the target directory.DeleteEntryEventRemoval of an entry in the target directory that no longer exists in the source directory.SyncTaskCompleteEventSuccessful completion of the synchronisation task.SyncTaskExceptionEventIf an exception if encountered.
-
-