AgentSkillsCN

symfony-7-4-ldap

Symfony 7.4 LDAP组件参考文档。在处理LDAP、目录服务、LDAP认证、LDAP查询、Active Directory,或使用Symfony Ldap适配器时,均可运用这一技能。

SKILL.md
--- frontmatter
name: "symfony-7-4-ldap"
description: "Symfony 7.4 LDAP component reference. Use this skill when working with LDAP, directory services, LDAP authentication, LDAP queries, Active Directory, or the Symfony Ldap adapter."

Symfony 7.4 LDAP Component

Overview

The Symfony LDAP component provides a PHP client on top of PHP's ldap extension for connecting to, authenticating against, and querying LDAP/Active Directory servers. It is used in Mezzo's authentication service for LDAP-based user authentication.

Quick Reference

Installation

bash
composer require symfony/ldap

Create Connection

php
use Symfony\Component\Ldap\Ldap;

$ldap = Ldap::create('ext_ldap', [
    'host' => 'my-server',
    'encryption' => 'ssl',
]);
// Or with connection string:
$ldap = Ldap::create('ext_ldap', [
    'connection_string' => 'ldaps://my-server:636',
]);

Bind (Authenticate)

php
$ldap->bind($dn, $password);

Query

php
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
$results = $query->execute();

Manage Entries

php
$entryManager = $ldap->getEntryManager();
$entryManager->add($entry);
$entryManager->update($entry);
$entryManager->remove($entry);

Key Classes

ClassPurpose
Symfony\Component\Ldap\LdapMain LDAP client
Symfony\Component\Ldap\EntryRepresents an LDAP entry
Symfony\Component\Ldap\LdapInterfaceContract for LDAP implementations
Symfony\Component\Ldap\Adapter\ExtLdap\AdapterPHP ldap extension adapter
Symfony\Component\Ldap\Adapter\QueryInterfaceQuery interface with scope constants

Connection Options

OptionDescription
hostIP or hostname of the LDAP server
portPort to access the LDAP server
versionLDAP protocol version
encryptionssl, tls, or none (default)
connection_stringFull LDAP URI (alternative to host+port)
optReferralsAuto-follow referrals

Full Documentation