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

Ldaprecord Laravel Laravel Package

directorytree/ldaprecord-laravel

Integrate LDAP authentication and directory access into Laravel with LdapRecord. Provides user sync, login, Eloquent-style models for LDAP entries, configuration for multiple connections, and utilities for Active Directory and OpenLDAP environments.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • LDAP Integration: The package provides a seamless bridge between Laravel’s Eloquent ORM and LDAP directories (e.g., Active Directory), enabling authentication, user management, and synchronization without reinventing LDAP logic. This aligns well with systems requiring hybrid identity management (e.g., on-prem LDAP + Laravel apps).
  • Eloquent Compatibility: Leverages Laravel’s query builder and Eloquent models, reducing friction for teams already using Laravel’s ecosystem. Supports soft deletes, relationships, and query scopes, making it feel native.
  • Directory Emulator: Includes a local testing mode (Directory Emulator) for development, eliminating dependency on live LDAP servers during CI/CD or local testing.
  • Event-Driven: Emits authentication events (RulePassed, RuleFailed) and integrates with Laravel’s logging system, enabling observability and extensibility.

Integration Feasibility

  • Authentication: Replaces or augments Laravel’s default Auth system with LDAP-backed providers (e.g., LdapUserProvider). Supports multi-factor authentication (MFA) via custom rules.
  • User Sync: LdapImporter and ldap:import commands enable one-way or bidirectional sync between LDAP and Laravel databases, with support for scoped imports (v2.7.0+).
  • Customization: Attribute mapping, password hashing, and access control are configurable via model bindings and service providers.
  • CLI Tools: Includes ldap:browse, ldap:import, and ldap:sync commands for ad-hoc management without UI overhead.

Technical Risk

  • LDAP Complexity: LDAP schemas vary by provider (e.g., Active Directory vs. OpenLDAP). Misconfigured base DNs, attribute mappings, or filter queries can cause silent failures or performance issues.
  • Performance: LDAP queries can be slow if not optimized (e.g., nested memberof lookups). The package mitigates this with caching and query scopes, but benchmarking is recommended for large directories.
  • Dependency Lock: Ties to directorytree/ldaprecord (v4.0+) and Laravel’s Illuminate components. Major version upgrades (e.g., Laravel 13) may require testing.
  • Password Handling: LDAP password policies (e.g., expiration, complexity) must align with Laravel’s rehashPasswordIfRequired logic (fixed in v3.3.1). Custom providers may need adjustments.
  • Testing: Directory Emulator is powerful but may not cover all edge cases (e.g., replication delays, referral chasing). Integration tests with a staging LDAP server are critical.

Key Questions

  1. LDAP Provider Compatibility:
    • Which LDAP server (AD, OpenLDAP, 389DS) and version will be used? Are there schema-specific quirks (e.g., memberof vs. uniqueMember)?
    • Are referrals or global catalogs required? The package supports these, but configuration may vary.
  2. Authentication Flow:
    • Will LDAP be the sole auth source, or will it augment Laravel’s database auth (e.g., hybrid mode)?
    • Are custom auth rules (e.g., role-based access) needed beyond LDAP group memberships?
  3. Sync Strategy:
    • Is one-way sync (LDAP → DB) or bidirectional sync required? The package supports both, but bidirectional sync adds complexity (e.g., conflict resolution).
    • What’s the expected sync frequency? High-frequency syncs may require queue-based processing.
  4. Performance:
    • How large is the LDAP directory? For >100K users, consider paging or async imports.
    • Are real-time updates needed (e.g., WebSocket events on LDAP changes), or is batch sync sufficient?
  5. Fallback Mechanisms:
    • What’s the offline strategy if LDAP is unavailable? The package supports graceful degradation (e.g., caching), but policies must be defined.
  6. Compliance:
    • Are there audit/logging requirements for LDAP operations? The package supports configurable logging levels and events.
  7. Upgrade Path:
    • What’s the Laravel version roadmap? The package supports v8–v13, but future versions may require adjustments.

Integration Approach

Stack Fit

  • Laravel Versions: Officially supports v8–v13. If using Laravel 14+, check for compatibility or fork the package.
  • PHP Requirements: PHP 8.1+ (LDAP extension required). Ensure ext-ldap is enabled and configured.
  • Database: Works with any Eloquent-supported DB (MySQL, PostgreSQL, SQL Server). No direct DB dependency beyond Laravel’s ORM.
  • LDAP Extensions:
    • Core: ext-ldap (required).
    • Optional: ext-openssl (for TLS), ext-intl (for UTF-8 handling).
  • Dependencies:
    • directorytree/ldaprecord (v4.0+): Underlying LDAP library.
    • ramsey/uuid: For GUID handling (if using LDAP’s entryUUID).
    • No jQuery/JS dependencies: Pure PHP/Laravel integration.

Migration Path

  1. Assessment Phase:
    • Audit existing authentication (e.g., Auth::attempt()) and user management (e.g., User model) logic.
    • Map LDAP attributes to Laravel models (e.g., cnname, memberOfgroups).
  2. Setup:
    • Install via Composer:
      composer require directorytree/ldaprecord-laravel
      
    • Publish config and migrations:
      php artisan vendor:publish --provider="DirectoryTree\LdapRecordLaravel\LdapRecordLaravelServiceProvider"
      php artisan migrate
      
  3. Configuration:
    • Define LDAP connection in config/ldap.php:
      'connections' => [
          'ad' => [
              'host' => 'ldap.example.com',
              'port' => 389,
              'use_ssl' => true,
              'base_dn' => 'dc=example,dc=com',
              'username' => 'cn=admin,dc=example,dc=com',
              'password' => 'password',
          ],
      ],
      
    • Bind a Laravel model to LDAP (e.g., User):
      use DirectoryTree\LdapRecordLaravel\Traits\LdapRecord;
      
      class User extends Authenticatable {
          use LdapRecord;
          protected $ldapConnection = 'ad';
          protected $ldapModel = 'user';
          protected $ldapAttributes = [
              'uid' => 'username',
              'cn' => 'name',
              'mail' => 'email',
          ];
      }
      
  4. Authentication:
    • Replace Auth::provider() with LdapUserProvider in config/auth.php:
      'providers' => [
          'ldap' => [
              'driver' => 'ldap',
              'model' => User::class,
          ],
      ],
      
    • Update LoginController to use LDAP rules:
      use DirectoryTree\LdapRecordLaravel\Rules\LdapRule;
      
      public function rules() {
          return [
              'username' => ['required', new LdapRule($this->ldapConnection, 'user')],
          ];
      }
      
  5. Synchronization:
    • Run initial sync:
      php artisan ldap:import --model=User --connection=ad
      
    • Schedule periodic syncs (e.g., via Laravel Tasks or cron).
  6. Testing:
    • Use Directory Emulator for unit tests:
      $this->actingAsLdapUser('testuser', 'password');
      
    • Test with a staging LDAP server for integration tests.

Compatibility

  • Laravel Packages:
    • Sanctum/Passport: Works with LDAP users (treat them as Eloquent models).
    • Nova/Vue: LDAP users appear as Eloquent resources; no special handling needed.
    • Queues: Sync operations can be queued (e.g., ldap:import with dispatchSync).
  • Third-Party LDAP Tools:
    • Compatible with AD, OpenLDAP, and 389DS if schemas are mapped correctly.
    • May require adjustments for non-standard attributes (e.g., custom extensions).
  • Legacy Systems:
    • If migrating from adldap2 or custom LDAP logic, the package provides drop-in replacements for common operations
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
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
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