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 an LDAP directory and Active Directory ORM for Laravel and PHP. It provides fluent models, query builder, authentication and user sync, event-driven operations, and easy integration with Laravel apps for managing and searching directory entries.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Eloquent-like API: Seamlessly integrates with Laravel’s Eloquent ORM, reducing learning curve for PHP/Laravel developers. Models LDAP entries as Eloquent models (e.g., User, Group), enabling familiar CRUD operations (find(), create(), update()) and relationships.
    • Query Builder Abstraction: Provides a fluent, chainable query builder (e.g., where(), orWhere(), whereIn()) that maps to LDAP filters, abstracting low-level LDAP syntax (e.g., (objectClass=person)). Aligns with Laravel’s query builder patterns.
    • Global Scopes: Supports Laravel’s global scopes for tenant-specific or role-based query constraints (e.g., applyScopesTo()), critical for multi-tenant SaaS or enterprise applications. Fixes for global scope query mutations (v4.0.6) ensure reliability.
    • Authentication Integration: Built-in Laravel authentication support (e.g., CanAuthenticate, getAuthIdentifier()), enabling LDAP-backed auth out-of-the-box (e.g., Auth::attempt(['username' => 'john', 'password' => 'secret'])).
    • Connection Management: Supports multiple LDAP connections with failover, configurable providers, and TLS/SSL options. Fixes for TLS state tracking (v3.6.0) and secure flag reset (v3.8.3) improve production reliability.
    • Testing Utilities: Includes DirectoryFake for unit testing, reducing flaky test failures (e.g., mock LDAP responses without scope inconsistencies).
  • Weaknesses:

    • LDAP-Specific Complexity: Abstracts LDAP intricacies but may still require understanding of LDAP schemas, DNs, and filters (e.g., (&(objectClass=user)(memberOf=CN=IT,OU=Groups))). Not a "black box" for non-LDAP experts.
    • Performance Overhead: Adds abstraction layer over raw ldap_* functions, which may introduce latency for high-frequency operations (e.g., sub-millisecond requirements). Benchmark against raw LDAP for critical paths.
    • Schema Rigidity: Assumes a stable LDAP schema. Dynamic or highly custom schemas may require workarounds (e.g., attribute casting overrides).
    • No Built-in Caching Layer: Relies on Laravel’s cache (e.g., remember()) for manual caching; no native LDAP query caching (e.g., ttl for frequent reads).
  • Fit for Laravel Ecosystem:

    • Pros: Native Laravel integration (service provider, config, events), Eloquent compatibility, and Laravel-specific features (e.g., CanAuthenticate). Works alongside Laravel’s authentication, caching, and testing tools.
    • Cons: Tight coupling with Laravel may limit reuse in non-Laravel PHP projects. Requires Laravel 11+ (or 12/13 with specific versions).

Integration Feasibility

  • Laravel Compatibility:

    • Officially supports Laravel 11–13 (v3.8.6+). Backward-compatible with Laravel 10 (v3.0+). No breaking changes in v4.x for core functionality; major version focuses on query builder alignment.
    • Service Provider: Registers as a Laravel package with configurable connections (e.g., config/ldap.php). Example:
      'connections' => [
          'ad' => [
              'url' => 'ldap://ad.example.com',
              'base_dn' => 'dc=example,dc=com',
              'username' => 'cn=admin,dc=example,dc=com',
              'password' => 'password',
              'use_ssl' => true,
          ],
      ],
      
    • Model Binding: Binds LDAP models to Laravel’s IoC container (e.g., app()->make(User::class)). Supports polymorphic relationships (e.g., morphing models by object class).
  • Migration Path:

    • From Raw LDAP: Replace ldap_connect(), ldap_search(), etc., with LdapRecord models and query builder. Example:
      // Before (raw LDAP)
      $ldap = ldap_connect('ldap://ad.example.com');
      $result = ldap_search($ldap, 'ou=users,dc=example,dc=com', '(objectClass=user)');
      $entries = ldap_get_entries($ldap, $result);
      
      // After (LdapRecord)
      $users = User::where('objectClass', 'user')->get();
      
    • From Other LDAP Libraries: Migrate from adldap2, phpLDAPadmin, or custom LDAP wrappers by mapping their queries to LdapRecord’s syntax. Example:
      // adldap2 → LdapRecord
      $adldap->search()->users()->where()->equality('department', 'IT');
      // becomes
      User::where('department', 'IT')->get();
      
    • From Eloquent: Extend existing Eloquent models with LDAP traits (e.g., LdapRecord\Traits\Authenticatable). Example:
      use LdapRecord\Auth\Authenticatable;
      
      class User extends Model implements Authenticatable {
          use \Laravel\Sanctum\HasApiTokens;
          use \LdapRecord\Auth\Authenticatable;
      }
      
  • Compatibility Risks:

    • PHP Version: Requires PHP 8.1+ (v4.0+). Test for PHP 8.4 compatibility (added in v3.8.0).
    • LDAP Server: Primarily tested with Active Directory and OpenLDAP. May require adjustments for other servers (e.g., 389 Directory Server).
    • Schema Differences: Custom LDAP schemas may need attribute casting overrides (e.g., protected $casts = ['binaryGuid' => 'binary']).

Technical Risk

  • Critical Risks:

    • Query Mutation Bugs: Historical issues with global scopes (fixed in v4.0.6) could reintroduce if not thoroughly tested. Validate with complex nested queries (e.g., where()->where()->orWhere()).
    • TLS/SSL Issues: Fixes for TLS state tracking (v3.6.0) and secure flag reset (v3.8.3) mitigate but don’t eliminate risks in production. Test with:
      • Self-signed certificates.
      • LDAPS connections (ldap:// vs. ldaps://).
      • Mixed-mode TLS (e.g., start_tls).
    • 32-bit PHP: Fix for UNIX timestamps (v4.0.4) addresses 32-bit PHP, but ensure your deployment environment is 64-bit.
    • Date Handling: Edge cases with LDAP timestamps (e.g., milliseconds format, v3.7.6) may affect applications relying on precise time comparisons.
  • Moderate Risks:

    • Performance: Abstraction overhead may impact high-frequency operations. Benchmark against raw LDAP for critical paths (e.g., authentication).
    • Schema Evolution: LDAP schema changes (e.g., new attributes) may require model updates. Use morphTo() for dynamic object classes.
    • Connection Pooling: No built-in connection pooling; rely on Laravel’s service container or external tools (e.g., ldap_extended_control).
  • Mitigation Strategies:

    • Testing: Use DirectoryFake for unit tests and integration tests with real LDAP servers.
    • Monitoring: Log LDAP queries and errors (e.g., Ldap::DEBUG_FILTER, Ldap::DEBUG_ERROR).
    • Fallbacks: Implement retry logic for transient failures (e.g., LdapRecord\Exceptions\ConnectionException).
    • Gradual Rollout: Start with non-critical LDAP operations (e.g., reads) before migrating writes.
  • Key Questions for the Team:

    1. LDAP Complexity: What is the complexity of your LDAP schema? Are there custom object classes or attributes that require special handling?
    2. Query Patterns: Do you rely on complex nested queries (e.g., where()->orWhere()->where()) or global scopes? If so, validate with the latest fixes (v4.0.6+).
    3. Performance Requirements: Are there latency-sensitive operations (e.g., authentication) where raw LDAP would be preferable?
    4. Multi-Tenancy: Do you need tenant-specific LDAP connections or query scopes? If so, test the global scope mutation fixes.
    5. Schema Stability: How frequently does your LDAP schema change? Plan for model updates if the schema evolves.
    6. Error Handling: How will you handle LDAP-specific errors (e.g., LDAP_INVALID_CREDENTIALS) in your application?
    7. Testing Coverage: Do you have a strategy for testing LDAP interactions (e.g., DirectoryFake, mock LDAP servers)?

Integration Approach

Stack Fit

  • **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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata