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 Package

directorytree/ldaprecord

LDAPRecord is a fully featured LDAP and Active Directory ORM for Laravel and PHP. It provides Eloquent-style models, querying, authentication and user sync, and tools for working with directory entries, connections, and schema—built for reliable, modern LDAP apps.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • LDAP Integration: The package provides a fully-featured LDAP ORM, aligning well with Laravel applications requiring Active Directory (AD) or LDAP integration (e.g., authentication, user/group management, directory synchronization).
  • Eloquent-like API: Mimics Laravel’s Eloquent ORM, reducing learning curve for developers familiar with Laravel’s query builder.
  • Model-Based Approach: Supports polymorphic models (e.g., mapping LDAP objects to different Laravel models based on object classes), enabling flexible directory structures.
  • Query Builder: Offers complex filtering (where, orWhere, andFilter, memberOf), pagination, and chunking, critical for large-scale LDAP operations.

Integration Feasibility

  • Laravel Compatibility: Officially supports Laravel 11–13, with backward compatibility for v3.x (Laravel 8–10). Minimal friction for adoption in existing Laravel stacks.
  • PHP Requirements: Requires PHP 8.1+, ensuring compatibility with modern Laravel versions.
  • LDAP Extensions: Mandates ext-ldap, ext-json, and ext-iconv, which are standard for LDAP operations but must be verified in the target environment.
  • Configuration Overrides: Supports custom LDAP protocols (e.g., LDAPS, LDAP over TCP) and TLS/SSL tuning, accommodating enterprise security policies.

Technical Risk

  • Breaking Changes in v4.x: Major version introduces API shifts (e.g., query builder behavior fixes in #793). Requires thorough testing if upgrading from v3.x.
  • Performance Overhead: LDAP operations (especially in large directories) may introduce latency. Mitigation strategies:
    • Caching: Leverage Laravel’s cache (e.g., simple-cache) for frequent queries.
    • Connection Pooling: Configure ldaprecord to reuse connections.
    • Chunking: Use chunk() for bulk operations to avoid memory issues.
  • Debugging Complexity: LDAP errors (e.g., #774) may require deep packet inspection. The package now includes granular debug constants (Ldap::DEBUG_*) to aid troubleshooting.
  • AD-Specific Quirks: Fixes like #779 (timestamp rounding) highlight potential Active Directory-specific edge cases that may need validation in testing.

Key Questions

  1. Use Case Alignment:
    • Is LDAP integration for authentication, directory sync, or custom attribute storage? This dictates whether LdapRecord’s features (e.g., CanAuthenticate, memberOf) are fully leveraged.
  2. Directory Size/Complexity:
    • How large is the LDAP directory? Large directories may require optimizations (e.g., indexing, connection tuning).
  3. Security Requirements:
    • Are TLS/SSL mandates strict? The package supports allow_insecure_password_changes (v3.6.0+), but this may conflict with compliance needs.
  4. Migration Path:
    • Is the team using v3.x or v4.x? v4.x introduces query builder behavior changes (e.g., #791) that may need regression testing.
  5. Testing Strategy:
    • How will LDAP-specific edge cases (e.g., UTF-8 strings, binary GUIDs) be validated? The package includes fixes like #698 that may surface in production.
  6. Monitoring:
    • Are LDAP connection metrics (e.g., latency, failures) needed? The package lacks built-in monitoring but supports debug logs (Ldap::DEBUG_*).

Integration Approach

Stack Fit

  • Laravel Ecosystem: Seamlessly integrates with Laravel’s service container, events, and authentication (e.g., CanAuthenticate trait). Works alongside Eloquent, Queues, and Cache.
  • Authentication: Supports Laravel’s auth system via getAuthIdentifier() and Failed events, enabling LDAP-backed user authentication with minimal boilerplate.
  • Testing: Includes mocking utilities (DirectoryFake) for unit/integration tests, reducing reliance on live LDAP servers.
  • Event-Driven: Emits events (e.g., Failed for authentication failures) for reactive workflows (e.g., logging, notifications).

Migration Path

  1. Assessment Phase:
    • Audit existing LDAP interactions (e.g., adldap2, custom scripts) to identify replacement candidates.
    • Map LDAP object classes to Laravel models (e.g., User, Group) using morphClass().
  2. Pilot Integration:
    • Start with read-only operations (e.g., user/group lookups) to validate query behavior.
    • Gradually introduce writes (e.g., user creation, password updates) with rollback strategies.
  3. Version Alignment:
    • For Laravel 11–13: Use v4.x for latest features (e.g., Laravel 13 support).
    • For Laravel 8–10: Use v3.x to avoid v4.x breaking changes.
  4. Configuration:
    • Replace hardcoded LDAP connections with Laravel’s config files (e.g., config/ldap.php).
    • Example:
      'connections' => [
          'ad' => [
              'host' => env('LDAP_HOST'),
              'protocol' => 'ldaps', // Custom protocol support (v3.7.0+)
              'base_dn' => env('LDAP_BASE_DN'),
              'username' => env('LDAP_USERNAME'),
              'password' => env('LDAP_PASSWORD'),
              'allow_insecure_password_changes' => env('LDAP_ALLOW_INSECURE', false),
          ],
      ],
      
  5. Model Setup:
    • Extend LdapRecord\Models\Model for custom LDAP models:
      use DirectoryTree\LdapRecord\Models\Model;
      
      class User extends Model
      {
          protected $dn = 'ou=users,dc=example,dc=com';
          protected $attributes = ['uid', 'mail', 'memberOf'];
          protected $casts = ['isActive' => 'boolean'];
      }
      
    • Use polymorphic models for dynamic object classes:
      class DirectoryEntry extends Model
      {
          public function morphClass(): string
          {
              return $this->getObjectClass() === 'group' ? Group::class : User::class;
          }
      }
      

Compatibility

  • Laravel Services: Works with Laravel’s service provider system. Publish config/assets via:
    php artisan vendor:publish --provider="DirectoryTree\LdapRecord\Laravel\LdapRecordServiceProvider"
    
  • Query Builder: Supports Eloquent-like syntax but with LDAP-specific methods:
    // Find users in a group
    $users = User::whereMemberOf('CN=Admins,DC=example,DC=com')->get();
    
    // Complex filtering
    $query = User::where(function ($q) {
        $q->where('department', 'IT')
          ->orWhere('title', 'Developer');
    })->get();
    
  • Authentication: Integrate with Laravel’s auth via:
    use DirectoryTree\LdapRecord\Laravel\Auth\CanAuthenticate;
    
    class User extends Model implements CanAuthenticate
    {
        public function getAuthIdentifier(): string
        {
            return $this->uid;
        }
    }
    
  • Testing: Use DirectoryFake for isolated tests:
    use DirectoryTree\LdapRecord\Testing\DirectoryFake;
    
    public function test_user_creation()
    {
        DirectoryFake::fake();
        $user = User::create(['uid' => 'john', 'mail' => 'john@example.com']);
        $this->assertEquals('john', $user->uid);
        DirectoryFake::assertCreated('uid=john,ou=users,dc=example,dc=com');
    }
    

Sequencing

  1. Phase 1: Read Operations
    • Implement user/group lookups, membership checks, and attribute queries.
    • Validate performance with large datasets (e.g., 10K+ entries).
  2. Phase 2: Write Operations
    • Add user creation, password updates, and group management.
    • Test transactional safety (e.g., partial LDAP updates).
  3. Phase 3: Authentication
    • Replace or extend Laravel
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