General plugins (Local): LDAP syncing scripts

Maintained by Picture of Charles Fulton Charles Fulton, Picture of Andrew Zito Andrew Zito
This plugin synchronizes Moodle cohorts against an LDAP directory using either group memberships or attribute values.
304 sites
12 fans

This plugin synchronizes Moodle cohorts against an LDAP directory using either group memberships or attribute values. This is a continuation of Patrick Pollet's local_ldap plugin, which in turn was inspired by MDL-25011 and MDL-25054.

This plugin requires that you have either CAS or LDAP enabled as an authentication method. It officially supports OpenLDAP and Active Directory. Both have unit test coverage.

The synchronization tasks are managed as scheduled tasks and are disabled by default.


Screenshot #0


Picture of Charles Fulton
Charles Fulton (Lead maintainer)
Please login to view contributors details and/or to contact them

Comments RSS

Show comments
  • Picture of Jan Derecz
    Wed, 23 May 2018, 1:26 AM
    Ok, I think that I know the reason. If I use only cohorts creating from AD then DELETE FROM cohort_members before sync should resolve my problem?
  • Picture of Guybrush Threepwood
    Fri, 25 May 2018, 2:55 PM
    Still no change to sync cohorts from my AD groups... No cohorts are created and existing cohorts is not populated based on AD Groups... any help would be appreciated. I already asked in the related discussion:
  • Picture of Marlise Nauer
    Mon, 18 Jun 2018, 10:14 PM
    Hi Charles
    We use moodle 3.5 with your latest plugin.
    We have the same affect like Guybrush.
    Is there any solution for that problem?
    Best regards Marlise
  • Picture of Charles Fulton
    Mon, 18 Jun 2018, 10:33 PM
    Hi Marlise,

    I believe what Guybrush is experiencing is a configuration issue and not a problem with the plugin.


  • Picture of Zigor Astarbe
    Tue, 10 Jul 2018, 9:16 PM
    Hi friends, don't know where to write to make a feature request for this plugin:
    - Is it possible to make an option to delete unused cohorts? (with no users in it).
    - Is it possible to make an option to detele unsynced cohorts? (cohorts with no group in active directory).

    thanks in advance,

  • Picture of Charles Fulton
    Tue, 10 Jul 2018, 9:59 PM
    Hi Zigor, you may contribute feature requests at Best, Charles.
  • Picture of KME Support
    Wed, 22 Aug 2018, 3:48 AM
    Hi Charles. I have a similar issue to guybrush. When i run the scheduled task i get the same output but no cohorts are synced.
    I guess the issue appeared since upgrade to Moodle 3.5 but we haven‘t made any change to the configuration since then, except we changed the ldap username attribute to UPN. I already tried changing it back to samAccount name but it still doesn‘t work.

    Any ideas to trace that issue?

    Thanks for any reply and your great work.

  • Picture of Michel Rancourt
    Thu, 23 Aug 2018, 5:10 AM
    Hi Charles, since upgrade to 3.5 no cohorts updates and no cohorts creation. Same issues.

    Thank you
  • Picture of Charles Fulton
    Thu, 23 Aug 2018, 5:23 AM
    Folks, I'm not sure what to suggest. My institution is running on 3.5.1 and the plugin works. Our backend is OpenLDAP. I don't have an Active Directory environment to test against. If I had to venture a guess, the paged user queries to AD either aren't returning users or are returning them in an unexpected way.
  • Picture of KME Support
    Thu, 23 Aug 2018, 8:00 PM
    I was able to track down the issue on our side, and it was indeed NOT related to the Plugin, sorry for the confusion. Instead we had two different Problems with the Moodle LDAP Config and inconsistent Groups in Active Directory. Also since Moodle 3.5, only 100 cohorts are listed in the dropdown menu, which made our teachers first think, the cohorts where not created.

    Anyway on thing i thought would be great to have, was a debug parameter for the CLI Script sync_cohorts.php to display the results, that are fetched from LDAP. Since i had no clue what the plugin does in the background, i tried to output contents of variables by placing print_r() in different places in the code of the plugin. That's how i finally figured out, that the plugin was actually working correctly ... big grin

    Once again thanks for your work!
  • Picture of Charles Fulton
    Fri, 31 Aug 2018, 11:26 PM
    Brief update: I've obtained access to an Active Directory test environment. I've identified at least one bug which affect attribute synchronization with large environments. I hope to release an update in the next few days which corrects this problem. I appreciate everyone's patience and I'm sorry that it's taken so long to resolve this issue.
  • Picture of Charles Fulton
    Thu, 6 Sep 2018, 4:03 AM
    I've identified and fixed a couple bugs in the Active Directory code related to pagination. I can't say for sure that these changes will resolve the issues folks are seeing, but they might. The code is available here: I'd love to hear from folks on Active Directory before I publish a formal release.


  • Picture of Michel Rancourt
    Thu, 6 Sep 2018, 11:30 PM
    I've updated the plugin and a lot of cohorts are add / updated! thanks a lot.
  • Picture of Visvanath Ratnaweera
    Fri, 23 Nov 2018, 3:52 AM
    Hi Charles, I have tested v3.4.1 (2018090700) just today against an AD. It does attribute-based sync but no group-based sync. See the details here: The test system is still open, I can do more tests, if you could guide me.
  • Picture of Patrick Lemaire
    Wed, 28 Nov 2018, 4:03 AM
    Hi Charles,
    I succeed in synchronize group-based AD with v3.4.1 (2018090700) but I had to change line 391 in locallib.php :
    - $filter = '(&('.$this->config->user_attribute.'=*)'.$this->config->objectclass.')';
    + $filter = '(&('.$this->config->user_attribute.'=*))';
    Otherwise I had an error for bad syntax in ldap search query.

    Moreover some lines of codes intrigates me. For example, why are there thoses 2 lines 366 & 367?! Only line 367 is useful, isn't it?!

    Despite this half-success I want to synchronize a cohort with a group that is member of an OU. I didn't succeed so far... I activated 'Nested Group' option but nothing happens.

1 2 3 4
Please login to post comments