Automatically synchronize LDAP Based on Schedule

Introduction

The Sync LDAP User Directory Manager enhances Joget Workflow by importing user objects from the LDAP server into its built-in user directory manager on demand. This integration reduces dependency on the LDAP server and boosts performance.

How does it work?

To Automate LDAP Synchronization, follow the steps below:

  1. Go to the Joget Marketplace and download the Scheduler v6 plugin.
  2. Import this plugin into your Joget installation, preparing your system for scheduled tasks.
  3. Add the scheduler userview element to your userview. This element will manage the scheduled synchronization tasks.
  4. Define how frequently LDAP synchronization should occur by setting a CRON expression in the scheduler configuration. This frequency will depend on your specific needs for data freshness and system performance.
  5. Choose the bean shell option under the Plugin settings.
  6. Click the Configure Plugin button and insert the provided bean shell script. 
    import org.joget.directory.model.service.DirectoryManagerProxyImpl;
    import org.joget.directory.model.service.DirectoryManager;
    import org.joget.apps.app.service.AppUtil;
    import org.joget.plugin.ldap.SyncLdapUserDirectoryManagerImpl;
    import org.joget.plugin.directory.SecureDirectoryManagerImpl;
     
    DirectoryManagerProxyImpl proxy = (DirectoryManagerProxyImpl) AppUtil.getApplicationContext().getBean("directoryManager");
    DirectoryManager dm = proxy.getDirectoryManagerImpl();
    if (dm != null) {
        if (dm instanceof SecureDirectoryManagerImpl) {
            dm = ((SecureDirectoryManagerImpl) dm).getEdm(1);
        }
        if (dm instanceof SyncLdapUserDirectoryManagerImpl) {
            int total = ((SyncLdapUserDirectoryManagerImpl) dm).syncUsers();
            System.out.println("Total users : " + total);
        }
    }

The script is specifically designed for the Sync LDAP User Directory Manager and can also be integrated with the Security Enhanced Directory Manager for enhanced functionality. 

Created by Marcos Last modified by Aadrian on Dec 13, 2024