General plugins (Local): LDAP syncing scripts

local_ldap
Maintained by Picture of Charles Fulton Charles Fulton
This plugin synchronizes Moodle cohorts against an LDAP directory using either group memberships or attribute values.
243 sites
250 downloads
8 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, although only the former has unit test coverage. I do not have access to an AD environment and cannot guarantee that it will continue to work.

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

Screenshots

Screenshot #0

Contributors

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 Charles Fulton
    Tue, 12 Dec 2017, 10:11 PM
    Thanks for digging in to that issue. I'll try to add some tests which account for nested groups. There's an ongoing discussion at https://github.com/LafColITS/moodle-local_ldap/issues/6 about formal support for targeting specific OUs for group sync.
  • Picture of Bryan South
    Thu, 11 Jan 2018, 3:36 AM
    I have had ldap sync working for quite a while, but when I run the task for this sync, I get the following error.

    Scheduled task failed: Synchronize cohorts from LDAP groups (local_ldap\task\group_sync_task),LDAP-module cannot connect to any servers: No LDAP Host URL, Version or User Type specified in your LDAP settings
  • Picture of Bryan South
    Sat, 13 Jan 2018, 5:31 AM
    OK so I had to disable CAS, and then it used the LDAP settings instead. I still cant get anything to sync however.

    ... started 13:28:06. Current memory use 6.8MB.
    ... used 0 dbqueries
    ... used 0.042673110961914 seconds
    Scheduled task complete: Synchronize cohorts from LDAP groups (local_ldap\task\group_sync_task)

    I have tried various settings, but no luck. I do have a context set in the ldap settings, and I'm not sure if that would impact the group sync, as the groups are in a different OU in AD than the users and what OU the contact is limited to.
  • Picture of Admir Djana
    Tue, 6 Feb 2018, 3:38 PM
    how should be organized LDAP groups and users? does need to be inside groups a user? And when I run attribute_sync_task it doesnt show me any errors...but sql...

    [root@vlms01muc cli]# php schedule_task.php --execute=\\local_ldap\\task\\attribute_sync_task --showsql
    --------------------------------
    SELECT * FROM mdl_task_scheduled WHERE classname = ?
    [array (
    0 => '\\local_ldap\\task\\attribute_sync_task',
    )]
    --------------------------------
    Query took: 0.00036311149597168 seconds.
    --------------------------------
    --------------------------------
    SELECT * FROM mdl_user WHERE id = ? AND deleted = ?
    [array (
    0 => '2',
    1 => 0,
    )]
    --------------------------------
    Query took: 0.00069880485534668 seconds.
    --------------------------------
    --------------------------------
    SELECT * FROM mdl_context WHERE contextlevel = ? AND instanceid = ?
    [array (
    0 => 50,
    1 => '1',
    )]
    --------------------------------
    Query took: 0.00028586387634277 seconds.
    --------------------------------
    Execute scheduled task: Synchronize cohorts from LDAP attributes (local_ldap\task\attribute_sync_task)
    ... used 0 dbqueries
    ... used 0.012280941009521 seconds
    Scheduled task complete: Synchronize cohorts from LDAP attributes (local_ldap\task\attribute_sync_task)
    --------------------------------
    SELECT * FROM mdl_task_scheduled WHERE classname = ?
    [array (
    0 => '\\local_ldap\\task\\attribute_sync_task',
    )]
    --------------------------------
    Query took: 0.00031399726867676 seconds.
    --------------------------------
    --------------------------------
    UPDATE mdl_task_scheduled SET component = ?,classname = ?,lastruntime = ?,nextruntime = ?,blocking = ?,minute = ?,hour = ?,day = ?,month = ?,dayofweek = ?,faildelay = ?,customised = ?,disabled = ? WHERE id=?
    [array (
    0 => 'local_ldap',
    1 => '\\local_ldap\\task\\attribute_sync_task',
    2 => 1517901351,
    3 => 1517904060,
    4 => '0',
    5 => '1',
    6 => '*',
    7 => '*',
    8 => '*',
    9 => '*',
    10 => 0,
    11 => '1',
    12 => '0',
    13 => '66',
    )]
    --------------------------------
    Query took: 0.00055789947509766 seconds.
    --------------------------------
    [root@vlms01muc cli]# ^C
    [root@vlms01muc cli]# ^C
    [root@vlms01muc cli]# php schedule_task.php --execute=\\local_ldap\\task\\attribute_sync_task --showsql --showdebugging
    --------------------------------
    SELECT * FROM mdl_task_scheduled WHERE classname = ?
    [array (
    0 => '\\local_ldap\\task\\attribute_sync_task',
    )]
    --------------------------------
    Query took: 0.00047183036804199 seconds.
    --------------------------------
    --------------------------------
    SELECT * FROM mdl_user WHERE id = ? AND deleted = ?
    [array (
    0 => '2',
    1 => 0,
    )]
    --------------------------------
    Query took: 0.0005490779876709 seconds.
    --------------------------------
    --------------------------------
    SELECT * FROM mdl_context WHERE contextlevel = ? AND instanceid = ?
    [array (
    0 => 50,
    1 => '1',
    )]
    --------------------------------
    Query took: 0.0002899169921875 seconds.
    --------------------------------
    Execute scheduled task: Synchronize cohorts from LDAP attributes (local_ldap\task\attribute_sync_task)
    ... used 0 dbqueries
    ... used 0.011369943618774 seconds
    Scheduled task complete: Synchronize cohorts from LDAP attributes (local_ldap\task\attribute_sync_task)
    --------------------------------
    SELECT * FROM mdl_task_scheduled WHERE classname = ?
    [array (
    0 => '\\local_ldap\\task\\attribute_sync_task',
    )]
    --------------------------------
    Query took: 0.00028300285339355 seconds.
    --------------------------------
    --------------------------------
    UPDATE mdl_task_scheduled SET component = ?,classname = ?,lastruntime = ?,nextruntime = ?,blocking = ?,minute = ?,hour = ?,day = ?,month = ?,dayofweek = ?,faildelay = ?,customised = ?,disabled = ? WHERE id=?
    [array (
    0 => 'local_ldap',
    1 => '\\local_ldap\\task\\attribute_sync_task',
    2 => 1517901876,
    3 => 1517904060,
    4 => '0',
    5 => '1',
    6 => '*',
    7 => '*',
    8 => '*',
    9 => '*',
    10 => 0,
    11 => '1',
    12 => '0',
    13 => '66',
    )]
    --------------------------------
    Query took: 0.00051116943359375 seconds.
    --------------------------------


    how can i change sql request? I try every setting option on local plugin, but still nothing...i sync users with no problem...does anybody have any idea what should be? Thank you in advance
  • Picture of Andrei Vida-Rațiu
    Mon, 19 Mar 2018, 8:45 PM
    Hello

    I would like to install this plugin in Moodle 3.4 but I get this error:
    Install plugin from ZIP file
    Validating local_ldap ... Error
    [Error] Required Moodle version [2017051501]
    Installation aborted due to validation failure
  • Picture of Charles Fulton
    Mon, 19 Mar 2018, 9:55 PM
    Hi Andrei, that error indicates that you're not running a high enough version of Moodle. The plugin is looking for Moodle 3.3.1 or higher.
  • Picture of Guybrush Threepwood
    Thu, 5 Apr 2018, 2:44 PM
    Hi,

    The cohort sync with our AD groups is not working for me.

    Using latest moodle version 3.4.2+

    Users sync is working well however.

    Here are the config I used:
    group_attribute: cn
    group_class: group
    real_user_attribure: sAMAccountName (also tried empty)
    process_nested_groups: disabled (also tried enabled)
    cohort_synching_ldap_groups_autocreate_cohorts: enabled.

    When I launche the scheduled task, I have many warnings:
    PHP Notice: Undefined index: memberof;range=0-* in [...]\root\local\ldap\locallib.php on line 312
    PHP Warning: count(): Parameter must be an array or an object that implements Countable in [...]\root\local\ldap\locallib.php on line 312

    The cohorts are not even created.

    I tried to create a cohort with "Cohort ID" as same as the group name, it's not populated.

    The test script root\local\ldap\tests\sync_test.php don't give any output...

    Is there a way to have a verbal output like the previons version using "\root\local\ldap\cli\sync_cohorts.php"?

    Any help will be appreciated!
  • Picture of khalid mahmood
    Mon, 23 Apr 2018, 6:17 PM
    please can any one help by write steps about how i can integrate moodle with ldap (freeipa) , it's very important for me
  • Picture of Guybrush Threepwood
    Mon, 14 May 2018, 7:34 PM
    Hi,

    with the new version of the plugin as of today (2018050400), the output is slighty different:

    Execute scheduled task: Synchronize cohorts from LDAP groups (local_ldap\task\group_sync_task)
    ... started 12:56:49. Current memory use 6.2Mo.
    ... used 1358 dbqueries
    ... used 48.352494955063 seconds
    Scheduled task complete: Synchronize cohorts from LDAP groups (local_ldap\task\group_sync_task)


    But the result is still the same: no cohort is created (or even synchronized for existing correlating one).




    If I run the script using --showsql parameter, I can see that it is enumerating the different AD Groups:

    SELECT * FROM mdl_cohort WHERE idnumber = ?
    [array (
    0 => 'GGM_S2M_ET_Classes_2HMI',
    )]
    --------------------------------
    Query took: 0.0034809112548828 seconds.




    What is going wrong?
  • Picture of Jan Derecz
    Tue, 22 May 2018, 6:46 PM
    Hi,

    Great plugin!

    but I've one problem. I use sync cohorts by attribute ("department"). I've user A with value "Dep1" for attribute "department" so he's add to cohorte "Dep1" - it's OK. I changed for this user value of department to "Dep2" and he shows in cohort Dep1 and Dep2

    Regards
    Jan
  • Picture of Charles Fulton
    Tue, 22 May 2018, 8:59 PM
    Hi Jan,

    That's unexpected. Are there any other users with the department attribute set to Dep1, or is User A the only one now?

    Charles
  • Picture of Jan Derecz
    Tue, 22 May 2018, 9:08 PM
    only one
  • Picture of Charles Fulton
    Tue, 22 May 2018, 9:11 PM
    Hi Jan,

    As there are no users in LDAP with the Dep1 attribute, the plugin isn't syncing the Dep1 cohort at all. If you manually remove User A he shouldn't be re-added.

    Charles
  • 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: https://moodle.org/mod/forum/discuss.php?d=160751.
1 2 3
Please login to post comments