LdapRecord Documentation

website·Indexed 32 days ago

https://ldaprecord.com

A PHP LDAP library and ORM featuring an ActiveRecord implementation for working with LDAP models. It provides tools for user and group management in Active Directory, OpenLDAP, FreeIPA, and Directory Server, including a fluent query builder, filter parser, and query caching. Includes dedicated integration for Laravel (LdapRecord-Laravel) supporting multi-domain authentication, LDAP user importing, and compatibility with Laravel Breeze, Sanctum, and UI.

Tokens
88.1K
Snippets
555
Records
605
Agent score
62%

What's inside LdapRecord

  1. Introduction to LdapRecord PHP package

    v4
    LdapRecord is a PHP package that implements the ActiveRecord pattern for interacting with LDAP servers. It maps LDAP object types (determined by their object classes) to corresponding PHP "Models". These models are used to perform search operations, create new objects, and modify existing objects on the LDAP server.
  2. Overview of the LdapRecord Directory Emulator

    v4
    The Directory Emulator replaces a specified LDAP connection with a fake one backed by an SQLite database. This allows developers to store, update, delete, move, rename, and query LDAP objects during testing without a live LDAP server. LdapRecord dynamically converts LDAP query filters into Eloquent SQL queries to interact with the emulated directory.
  3. Introduction to LdapRecord-Laravel

    v4
    LdapRecord-Laravel is a package that integrates LDAP directory capabilities into Laravel applications. It allows developers to search LDAP directories, perform directory operations, and authenticate LDAP users. The package is designed to mirror the experience of Laravel's Eloquent ORM but for LDAP. It is built on top of the core LdapRecord package; therefore, understanding the core LdapRecord documentation is recommended for a full understanding of the underlying mechanics.
  4. Overview of LdapRecord ORM

    LdapRecord is a fully-featured Active Record ORM for PHP designed to simplify working with LDAP directories. Key capabilities include a fluent filter builder for querying LDAP objects, built-in connection management for multi-domain environments, and an Active Record implementation for creating and modifying LDAP objects with minimal code.
  5. Introduction to LdapRecord PHP package

    v3
    LdapRecord is a PHP package that provides a full ActiveRecord implementation for interacting with LDAP servers. It maps LDAP object types (determined by their object classes) to corresponding "Model" classes. These Models are used to perform search operations, create new objects, and modify existing objects on the LDAP server.
  6. Choose between LdapRecord Core and LdapRecord-Laravel

    Depending on the project architecture, developers should choose one of two packages:

    1. LdapRecord Core: Use this for standalone PHP applications or any PHP framework other than Laravel. It provides the full ActiveRecord implementation for LDAP server interaction.
    2. LdapRecord-Laravel: Use this for Laravel applications. It extends the core package to provide LDAP authentication, user synchronization, and directory operations integrated directly into the Laravel ecosystem.
  7. Choose between Plain and Synchronized Database Authentication in LdapRecord-Laravel

    v4

    LdapRecord-Laravel provides two primary authentication strategies based on application requirements:

    Plain Authentication is best when:

    • No additional local data needs to be attached to LDAP users.
    • The application can be offline if the LDAP server is down.
    • The application relies heavily on real-time LDAP roles, status (enabled/disabled), and group memberships.

    Synchronized Database Authentication is best when:

    • Local data must be attached to LDAP users in the application database.
    • The application must support both LDAP and non-LDAP (local) users.
    • The application must remain accessible even if the LDAP server is unavailable.
  8. Understand LdapRecord Event Dispatcher scopes

    v4

    LdapRecord uses two different event dispatchers depending on the event's namespace. You must use the correct dispatcher to listen for specific events:

    1. Core LdapRecord Events: Events residing in the core LdapRecord framework cannot be listened for via Laravel's event dispatcher. They must be handled using the core LdapRecord event dispatcher.
    2. LdapRecord-Laravel Events: Events residing in the LdapRecord\Laravel namespace can only be listened for via Laravel's event dispatcher and cannot be handled by the core LdapRecord dispatcher.
  9. Update LdapRecord\Models\Attributes\AccountControl methods

    v3

    The AccountControl attribute class has renamed its methods to be more explicit about flag manipulation. Key changes include:

    • add() → setFlag()
    • remove() → unsetFlag()
    • apply() → applyFlags()
    • has() → hasFlag()
    • doesntHave() → doesntHaveFlag()
    • setValues() → setFlags()
    • getValues() → getFlags()
    • Boolean setters now explicitly start with set (e.g., accountIsLocked() becomes setAccountIsLocked()).
  10. Use SASL Binding for secure LDAP authentication

    v3
    LdapRecord v3 introduces support for SASL (Simple Authentication and Security Layer) binding, allowing for more secure and flexible authentication options when connecting to LDAP servers.
  11. Implement Synchronized Database LDAP Authentication in Laravel

    v4
    Synchronized Database LDAP Authentication allows users who successfully authenticate via LDAP to be created and synchronized within the local application database. This approach enables the attachment of relational data (e.g., blog posts, attachments) to LDAP users and ensures the application remains operational if connectivity to the LDAP server is lost, as subsequent requests retrieve the user from the local database rather than the LDAP directory. When configured, the Laravel Auth::user() method returns an instance of the configured Eloquent database model.
    use IlluminateorRoot\Facades\Auth;
    
    $credentials = [
        'mail' => 'user@example.com',
        'password' => 'secret',
    ];
    
    if (Auth::attempt($credentials)) {
        $user = Auth::user();
    
        // Returns true: the user is an instance of the local Eloquent model
        $user instanceof \App\Models\User;
    }
  12. Move an LDAP entry to a different Organizational Unit

    v3
    Use the move() method to move a model into a different Organizational Unit (OU) or Container. Upon success, the model's Distinguished Name (DN) is automatically updated to reflect the new location.
    $user = User::find('cn=Steve Bauman,dc=local,dc=com');
    $ou = OrganizationalUnit::find('ou=Office Users,dc=local,dc=com');
    
    $user->move($ou);
    
    // Displays 'cn=Steve Bauman,ou=Office Users,dc=local,d=com'
    echo $user->getDn();