Skip to content

Repository files navigation

CD-LaravelLdap

A Laravel package for retrieving Cornell University LDAP data.

This package provides two main classes:

  • LdapSearch: Handles LDAP queries and caching
  • LdapData: An immutable data object that encapsulates Cornell LDAP attributes in a well-defined structure

Installation

composer require cornell-custom-dev/laravel-ldap
php artisan vendor:publish --tag=ldap-config
# File: .env
LDAP_USER=username
LDAP_PASS=password

See config/ldap.php for additional settings.

Usage

Single lookup

use CornellCustomDev\LaravelStarterKit\Ldap\LdapSearch;

try {
  $ldapData = LdapSearch::getByNetid($netid);
  $displayName = $ldapData->name();
} catch (LdapDataException $e) {
  // Handle exceptions
}

Collection of search results

use CornellCustomDev\LaravelStarterKit\Ldap\LdapSearch;
use CornellCustomDev\LaravelStarterKit\Ldap\LdapData;

try {
    $searchFilter = "(|(uid=$this->search*)(displayname=*$this->search*)(mail=$this->search*))";
    return LdapSearch::search($searchFilter)
        ?->mapWithKeys(fn (LdapData $ldapData) => [
            'name'  => $ldapData->name(),
            'email' => $ldapData->email(),
        ]);
} catch (LdapDataException $e) {
  // Handle exceptions
}

LdapSearch caches queries for a configurable duration (default 300 seconds), so multiple calls for the same ldap filter are not expensive.

Documentation of all currently parsed fields can be found in LdapData.php.


Additional LDAP Attributes

LdapSearch::getByNetid($netid)->returnedData is an array of all LDAP attributes returned, keyed by attribute name. The set of attributes is a subset of the attributes documented at https://confluence.cornell.edu/pages/viewpage.action?spaceKey=IDM&title=Attributes.

Legacy Compatibility

LdapData has a property to provide compatibility with the LDAP::data() method from the legacy App\Helpers\LDAP class that exists on many Cornell Laravel sites.

$ldapData = LdapSearch::getByNetid($netid)?->ldapData;

The value of this property matches the output of LDAP::data($netid), but with the 'count' and 'count_values' keys removed.

About

A Laravel package for retrieving Cornell University LDAP data

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages