Outils pour utilisateurs

Outils du site


local:entinstaller:ldapapi

Additional API for LDAP Reading

Full LDAP Synchronisation for ENTs

This documentation gives some details on the additional libraries for reading LDAP entities through the ENT synchroniser configuration. The synchroniser brings additional libraries specific to reading the LDAP data corresponding to each synchronised entity. The construction of the libraries is strongly inspired by the standard /lib/ldaplib.php library and can rely on it where appropriate.

The following documentation will allow developers to directly invoke the reading APIs, rather than redeveloping their own connector.

Prerequisites

Getting an LDAP connection

Any API manoeuvre assumes having beforehand an open connection to the LDAP with a read user. The definition of the LDAP connection used is that of the auth/ldap module, even if it is not used or enabled in Moodle.

The following code gets an open connection instance:

    // Get ldap params from real ldap plugin.
    $ldapauth = get_auth_plugin('ldap');
    $ldapconnection = $ldapauth->ldap_connect();

At the end of the session it is recommended to close the LDAP link:

    $ldapauth->ldap_close(true);

Course entity

Getting a course DN

Assuming courses are recorded as LDAP groups, they have a unique, fully qualified DN in the directory. The match between Moodle and LDAP is done by matching the course identification number (Moodle) with the course identifier attribute configured in the ENT synchroniser (LDAP side)

  • Location: /local/ent_installer/ldap/ldaplib_courses.php
  • Function: local_ent_installer_find_course_dn($ldapconnection, $extcoursedn)
  • Parameters:
    • $ldapconnection: An open ldap connection.
    • $extcoursedn: The join identifier between Moodle and LDAP (the course identification number)

Preformatting the course identifier

In some cases the form of the course join identifier may not be the same between LDAP and Moodle (suffixes or prefixes or other transformation). It may therefore be necessary to convert the identification number known to Moodle into its LDAP form.

The LDAP ENT synchroniser has parameters to do this conversion:

The configuration parameter 'course_id_pattern' defines a configurable substitution pattern to preform the identifier from the Moodle value of the course's internal identification number (%CID%) and possibly an institution number for multi-tenant directories (%ID%).

  $config = get_config('local_ent_installer');
  $courseldapidentifier = $config->course_id_pattern;
  $courseldapidentifier = str_replace('%CID%', $COURSE->idnumber, $courseldapidentifier);
  $courseldapidentifier = str_replace('%ID%', $config->institution_id, $courseldapidentifier);

Synopsis:

  • the synchroniser configuration is retrieved
  • the substitution pattern is loaded
  • the local IDNumber value is injected
  • the institution identifier value is injected (optional)

$courseldapidentifier is the LDAP-transposed course identifier.

Getting an LDAP description of the course

  • Location:
  • Function1: local_ent_installer_get_courseinfo($ldapauth, $courseidentifier, $extracourseattributes, $options)
  • Parameters:
    • $ldapauth: A bootstrapped LDAP authentication plugin instance.
    • $courseidentifier: The join identifier between Moodle and LDAP (the course identification number)
    • $extracourseattributes: an associative array giving the 'course attribute' ⇒ 'ldap attribute' pairs to add to the default attribute set2 (WARNING!! All LDAP attribute names must be lowercased).

Note 2: Alternative function: local_ent_installer_get_courseinfo_asobj, same signature, to receive the course description as an object and not as an array.

Note 2: Retrieving a course entity retrieves the following attributes by default:

    $courseattributes = array(
        'fullname' => core_text::strtolower($config->course_fullname_attribute),
        'shortname' => core_text::strtolower($config->course_shortname_attribute),
        'summary' => core_text::strtolower($config->course_summary_attribute),
        'idnumber' => core_text::strtolower($config->course_idnumber_attribute),
        'category' => core_text::strtolower($config->course_category_attribute),
        'teachers' => core_text::strtolower($config->course_teachers_attribute),
    );

The default attributes are mapped by the ENT synchroniser configuration.


Back to the technical guide index - Back to the component index - Back to the plugin index - Back to the catalog

local/entinstaller/ldapapi.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki