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.Search
criteria. - Retrieves all previously uploaded entries in the target directory
under the
Configuration.TargetDirectory.baseDn
branch (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. TheTimerTask
interface of this class can be used to run the synchronisation periodically on a dedicated thread.During the run of a sync task
subscribed
objects 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 boolean
addListener(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.boolean
removeListener(SyncTaskEventListener listener)
Unregisters a listener for synchronisation task events.void
run()
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:
true
if the listener is not already registered.
-
removeListener
public boolean removeListener(SyncTaskEventListener listener)
Unregisters a listener for synchronisation task events.- Parameters:
listener
- The listener.- Returns:
true
if 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:
SyncTaskStartEvent
Start of the synchronisation task.SyncTaskEvent
Simple messages to indicate events such as the opening of a connection to the source or target directory, successful authentication, etc.SourceEntryRetrievalEvent
Retrieval of a particular matching search result entry from the source directory.SourceSearchCompleteEvent
Completion of the retrieval of the matching source directory entries.TargetEntryRetrievalEvent
Retrieval of a particular matching search result entry from the target directory.TargetSearchCompleteEvent
Completion of the retrieval of the matching target directory entries.AddEntryEvent
Upload of an entry from the source directory that did't exist in the target directory.UpdateEntryEvent
Update of an entry in the target directory.DeleteEntryEvent
Removal of an entry in the target directory that no longer exists in the source directory.SyncTaskCompleteEvent
Successful completion of the synchronisation task.SyncTaskExceptionEvent
If an exception if encountered.
-
-