ldaptools/ldaptools-bundle
Symfony bundle integrating LdapTools, a PHP LDAP library for querying and managing Active Directory and OpenLDAP. It adds service configuration and DI integration, making LDAP authentication, lookups, and directory operations easier in Symfony apps.
ldaptools/ldaptools library directly or a Laravel-specific LDAP package.config/bundles.php if Flex does not do it automatically:
composer require ldaptools/ldaptools-bundle
DependencyInjection/Configuration.php and the bundle service definitions. Those files tell you the exact config keys, service IDs, and autowiring aliases for your installed version.config/packages/ldap_tools.yaml with at least one domain, server list, base DN, and bind credentials sourced from environment variables:
ldap_tools:
domains:
corp:
domain_name: corp.example.com
servers:
- dc1.corp.example.com
- dc2.corp.example.com
base_dn: dc=corp,dc=example,dc=com
admin_username: '%env(LDAP_BIND_USER)%'
admin_password: '%env(LDAP_BIND_PASSWORD)%'
sAMAccountName or uid and dump the result. Inject the bundle’s LDAP manager service, or fetch it from the container while confirming the exact alias:
use LdapTools\LdapManager;
public function __construct(private LdapManager $ldap) {}
public function lookup(string $username): void
{
$user = $this->ldap->getRepository('user')->findOneByUsername($username);
dump($user);
}
Resources/config/services.xml or services.yaml and alias it explicitly in your app.LdapUserDirectory instead of calling LdapManager from controllers. This keeps bind credentials, domain selection, error handling, and attribute mapping in one place.$query = $this->ldap->buildLdapQuery()
->from('user')
->where(['department' => 'Engineering'])
->select(['username', 'email', 'displayName']);
LdapObject instances or repository methods, and keep a dedicated mapper between your domain model and LDAP attributes.corp and partners. Avoid letting a single service silently switch domains based on request input; inject or select the domain explicitly.findAll-style calls on broad bases such as dc=example,dc=com.ldaptools/ldaptools behind a Laravel service provider or choose a maintained Laravel LDAP package; the bundle’s value is Symfony DI, configuration, and Security integration.composer.json constraints before installing. A 48-star bundle with zero dependents may not support current Symfony versions; pin versions or be prepared to fork.symfony/ldap or another library later.objectGUID and objectSid are binary; memberOf may be absent if you do not query it; sAMAccountName, userPrincipalName, and distinguishedName behave differently from OpenLDAP attributes.ldap_tools often will not take effect until bin/console cache:clear.ldapsearch first. Compare the exact filter, base DN, and bind DN outside Symfony. Then inspect the bundle config and enable logging for the LdapTools connection.LdapManager and repositories for unit tests, and use an OpenLDAP or AD container for integration tests of filters, paging, and group mapping.How can I help you explore Laravel packages today?