anthonyedmonds / laravel-ldap-emulator
Automatically boot an LDAP emulator while working in a local environment.
Installs: 4 790
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.3
- directorytree/ldaprecord-laravel: ^3
- spatie/laravel-permission: ^6
Requires (Dev)
- illuminate/support: ^11
README
Automatically boot an LDAP emulator while working in a local environment.
Built for Laravel.
Based on the LDAP emulation provided by LDAP Record.
Supports roles provided by Spatie's Laravel Permission.
Installation
Add the library via Composer: composer require anthonyedmonds/laravel-ldap-emulator --dev
Add the LdapEmulatorServiceProvider
to bootstrap/providers.php
:
use AnthonyEdmonds\LaravelLdapEmulator\Providers\LdapEmulatorServiceProvider; return [ ... LdapEmulatorServiceProvider::class, ... ];
If you are manually loading service providers, LdapEmulatorServiceProvider
must be loaded after LdapRecord\Laravel\LdapServiceProvider
.
Once installed, export the config: php artisan vendor:publish --provider="AnthonyEdmonds\LaravelLdapEmulator\Providers\LdapEmulatorServiceProvider"
Configuration
All configuration can be performed in the published config/ldap-emulator.php
file.
Further instructions on setting up users are provided in the comments.
- Keep the total number of users to a minimum for efficiency
- You may create a mixture of users which are automatically imported or left in active directory
- You may only assign roles to automatically imported users
Usage
When the APP_ENV
key of your system is set to local
an LDAP emulator instance is started.
Beyond configuring the pool of users to add, the system will operate as if it had an LDAP server connected.
Imported users will not be updated once they have been created, however they can be synced when they sign in if LdapRecord is set up to do so.
Note that there some limitations to the functionality of the emulator, which are described here.
Authentication
When a call to Auth::attempt()
is made, the Attempting
event is fired and the LdapUser attempting to log in will be allowed to sign-in.
If you use a library that first calls Auth::validate()
, such as Laravel Fortify, you will need to call the setActingUser()
method first:
Fortify::authenticateUsing(function ($request) { if (config('ldap-emulator.enabled') === true) { LdapEmulatorServiceProvider::setActingUser($request->username); } $validated = Auth::validate([ 'samaccountname' => $request->username, 'password' => $request->password, ]); return $validated ? Auth::getLastAttempted() : null; });
Roadmap
Raise a ticket with your ideas and suggestions, or raise a pull request with your contributions.