Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Ldap Laravel Package

zendframework/zend-ldap

Zend LDAP provides PHP tools for LDAP directory operations like binding, searching, and modifying entries. This repository was abandoned on 2019-12-31 and has moved to laminas/laminas-ldap.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package via Composer:
    composer require zendframework/zend-ldap
    
  2. Start with authentication — the most common first use case. Create a minimal Ldap instance with connection and bind options:
    use Zend\Ldap\Ldap;
    
    $ldap = new Ldap([
        'host' => 'ldap.example.com',
        'port' => 389,
        'useStartTls' => true,
        'bindRequiresDn' => true,
        'baseDn' => 'DC=example,DC=com',
        'username' => 'admin@example.com',
        'password' => 'secret',
    ]);
    
  3. Test authentication of a user via authenticate():
    try {
        $ldap->authenticate('cn=John Doe,OU=Users,DC=example,DC=com', 'userPassword123');
        // Authenticated successfully
    } catch (\Zend\Ldap\Exception\LdapException $e) {
        // Handle failure (e.g., invalid credentials)
    }
    
  4. First reference: Authentication and Connecting to LDAP docs (archived, but stable API).

Implementation Patterns

  • Directory-backed authentication layer — integrate into your auth system (e.g., Laravel’s Auth::viaCallback() or custom UserProvider). Cache.Bind DN resolution separately (e.g., look up user DN first via getCanonicalAccountName() + getAccountCanonicalName()).
  • User/group lookup patterns:
    $users = $ldap->getLdap()->search(
        '(sAMAccountName=jdoe)',
        'OU=Users,DC=example,DC=com',
        Ldap::SEARCH_SCOPE_SUB
    );
    
    Use getAttributeValues() or getAttributeValue() for attribute access (handles single/multi-valued safely).
  • Dynamic binding for multi-tenant apps — switch baseDn, username, and password per tenant; avoid hard-coding credentials.
  • Schema abstraction — use Zend\Ldap\Attribute\Group and Zend\Ldap\Attribute\User to normalize AD vs. OpenLDAP differences (e.g., member vs. memberUid, objectClass values).
  • Batch operations — use add(), modify(), delete() with DN utilities (Ldap::BUILD_DN_*) to prevent injection or malformed DNs.

Gotchas and Tips

  • Don’t trust default bind behaviorbindRequiresDn = true is common in AD; set it explicitly. Otherwise, username may be interpreted as a simple username (e.g., jdoe) vs. full DN (cn=John Doe,...).
  • Escape user input in filters always — use Ldap::escapeFilter($input) or Ldap::escapeValue($input) to avoid injection and broken queries.
  • TLS vs. SSL pitfallsuseSsl opens LDAPS (port 636); useStartTls starts unencrypted and upgrades. Mix-ups cause timeout/no-reponse issues (common in Docker/containers without host network).
  • Paged results for large sets — enable pageSize in config to avoid sizelimit exceeded errors on large directories.
  • Debugging:
    • Enable logging via Zend\Logger integration or catch LdapException and inspect getLdapErrorMessage() (returns extended LDAP error codes + descriptions).
    • Use getAdapter()->getResource() to access raw LDAP connection for custom operations (e.g., ldap_get_option()).
  • This package is archived (as of 2019) — it’s stable but unmaintained. Consider migrating to laminas/laminas-ldap (the official fork). Ensure Composer prefers laminas/* over zendframework/* to avoid conflicts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests