LDAP Search

Module Drupal Illustration Voir sur Drupal.org
Nb téléchargements : 33


  • Code
  • Documentation
  • Miscellaneous
  • User interface



permet de requêter le LDAP via une API et avoir du JSON en retour.


Status : Published
Projects : Modules
Maintenance status : Actively maintained
Development status : Under active development
Supported Branches : 4.0.
shield Stable releases for this project are covered by the security advisory policy.


This module provides a seamless way to provide an API for developers to use. The API will return the JSON formatted search result. API gives ample of facilities to developer to sort out the results and get the one matching to the requirements.

LDAP Module is a basic requirement of this module.

For Module Installation, there is no specific requirement as such. A simple extraction of directory in 'modules' directory , and install module as like that of any other module is all you need to do.

How to use

  • Calling Service from .module OR .php File :
    1. Create a basic Service Object in your module whereever required.
      $service = \Drupal::service('ldap_search.search');
    2. Set the further filters or parameters as and how you like.
      // It's Mandatory to set base_dn.

      // Optional to set any extra filter.

      // Optional to set the Record Types(Active/Inactive).
      // If skipped, by default it will take as "both".

      // Optional, if skipped, by default 1 Record would be returned.

      // Optional, if skipped, by default, only 'mail' attribute will be returned.
    3. Finally give a call to the service.
      // Returns Plain Array of Results.
      $result = $service->search_resource();
  • Calling Service from JavaScript File:

    (function ($) {
      Drupal.behaviors.MyForm = {
        attach: function(context) {
          $('.my-text-box').change(function() {
            var base_dn = "OU=People,DC=community,DC=hogwarts,DC=com";
            var type = "active";
            var attributes = "studentid, mail, displayname, title";
            var extra_filter = "(memberOf=CN=Students,OU=Groups,DC=community,DC=hogwarts,DC=com)";
            var result_count = 1;
              url: "/v1/search_ldap_endpoint",
              type: 'get',
              data: 'base_dn=' + encodeURIComponent(base_dn) + '&extra_filter=' + encodeURIComponent(extra_filter) + '&type=' + encodeURIComponent(type) + '&attributes=' + encodeURIComponent(attributes) + '&result_count=' + encodeURIComponent(result_count),
              dataType: 'json',
              error: function(XMLHttpRequest, textStatus, errorThrown) {
                console.log("Failed to pull the student's data from LDAP !");
                console.log("XMLHttpRequest: " + JSON.stringify(XMLHttpRequest));
                console.log("textStatus: " + JSON.stringify(textStatus));
                console.log("errorThrown: " + JSON.stringify(errorThrown));
              success: function (data) {
                // Since we're asking for result_count = 1,
                // we're bound to get Single Result keyed 0 on Success.
                data_result = data[0];
                if (typeof data.error == "undefined" || data.error == '' || data.error == null) {
                } else {
                  console.log("Record Not Found !!");

Toutes les informations proviennent du site drupal.org