symfony/ldap
Symfony LDAP Component: a PHP LDAP client built on top of the PHP ldap extension. Stable since Symfony 3.1, offering tools to connect, bind, search, and manage directory entries. Docs, issues, and PRs are handled in the main Symfony repo.
LdapClient, Entry, and Query classes can be treated as Laravel services, enabling modular LDAP logic (e.g., LdapUserProvider for authentication).bind()) accommodate Symfony components without tight coupling. For example:
$this->app->bind('ldap', function ($app) {
return new \Symfony\Component\Ldap\LdapClient('ext_ldap');
});
memberOf, userPrincipalName) makes it ideal for enterprise use cases like SSO or multi-tenancy.Query class enables fluent LDAP queries (e.g., Query::where('cn', 'John Doe')), reducing boilerplate and improving maintainability in Laravel controllers/repositories.php-ldap extension (common in shared hosting but may need enabling). Laravel’s config/ldap.php can centralize extension checks:
if (!extension_loaded('ldap')) {
throw new \RuntimeException('LDAP extension is required.');
}
SecurityBundle (e.g., LdapUserProvider) can be resolved by leveraging Laravel’s authentication stack (e.g., AuthManager).EventDispatcher can integrate with Laravel’s events (e.g., auth.attempted, ldap.user.fetched) via bridges like symfony/event-dispatcher-contracts.composer require symfony/ldap:^6.4 --with-all-dependencies
connection facade or a custom pool wrapper.Rule::ldapDn()) can complement this.Log facade:
try {
$client->bind($dn, $password);
} catch (\Symfony\Component\Ldap\Exception\ConnectionException $e) {
Log::error('LDAP bind failed: ' . $e->getMessage());
}
cache facade) be needed?Auth system (e.g., custom LdapUserProvider)?config/ldap/tenants.php) be managed?LdapClient as a singleton or context-bound service.config/ldap.php for server credentials, TLS settings, and query defaults.UserProvider interface for LDAP-backed users.HttpClient, OptionsResolver, or EventDispatcher, this package leverages those dependencies.spomky-labs/ldap (for advanced AD features) or league/oauth2-ldap (for OAuth-LDAP hybrids).ldap_connect(), ldap_search() calls).LdapClient::search(), binds → LdapClient::bind()).LdapService class wrapping the package:
class LdapService {
public function __construct(private LdapClient $client) {}
public function findUser(string $dn): ?Entry {
return $this->client->find('ou=users', Entry::fromDn($dn));
}
}
Artisan commands or Tinker.LdapService::findUser()).config/ldap.php to centralize credentials:
'connections' => [
'default' => [
'url' => env('LDAP_URL', 'ldap://localhost'),
'options' => [
'account_usdn' => true,
'account_canonical_form' => DN::RFC2253,
],
],
],
AuthManager to use LdapUserProvider:
class LdapUserProvider implements UserProvider {
public function retrieveByCredentials(array $credentials) {
$client = new LdapClient('ext_ldap');
$user = $client->find('ou=users', $credentials['username']);
return $user ? new LdapUser($user) : null;
}
}
memberOf for AD groups).php-ldap extension is enabled:
sudo apt-get install php8.1-ldap # Ubuntu
sudo pecl install ldap # Custom installs
LdapClient bindings for searches, binds, and entry management.ldap_* functions with Symfony’s API.Auth system via UserProvider.cache facade).ldap.user.synced).contexts or resolvers for tenant-aware LDAP clients.composer why symfony/ldap
composer show symfony/ldap
composer update symfony/ldap --with-dependencies
LdapUserRepository) to isolate changes.How can I help you explore Laravel packages today?