|
| 1 | +.. index:: |
| 2 | + single: Ldap |
| 3 | + single: Components; Ldap |
| 4 | + |
| 5 | +The Ldap Component |
| 6 | +================== |
| 7 | + |
| 8 | + The Ldap component provides a means to connect to an LDAP server (OpenLDAP or Active Directory). |
| 9 | + |
| 10 | +Installation |
| 11 | +------------ |
| 12 | + |
| 13 | +You can install the component in 2 different ways: |
| 14 | + |
| 15 | +* :doc:`Install it via Composer </components/using_components>` (``symfony/ldap`` on `Packagist`_); |
| 16 | +* Use the official Git repository (https://github.com/symfony/ldap). |
| 17 | + |
| 18 | +.. include:: /components/require_autoload.rst.inc |
| 19 | + |
| 20 | +Usage |
| 21 | +----- |
| 22 | + |
| 23 | +The :class:`Symfony\\Component\\Ldap\\LdapClient` class provides methods |
| 24 | +to authenticate and query against an LDAP server. |
| 25 | + |
| 26 | +The :class:`Symfony\\Component\\Ldap\\LdapClient` class can be configured |
| 27 | +using the following options: |
| 28 | + |
| 29 | +``host`` |
| 30 | + IP or hostname of the LDAP server |
| 31 | + |
| 32 | +``port`` |
| 33 | + Port used to access the LDAP server |
| 34 | + |
| 35 | +``version`` |
| 36 | + The version of the LDAP protocol to use |
| 37 | + |
| 38 | +``useSsl`` |
| 39 | + Whether or not to secure the connection using SSL |
| 40 | + |
| 41 | +``useStartTls`` |
| 42 | + Whether or not to secure the connection using StartTLS |
| 43 | + |
| 44 | +``optReferrals`` |
| 45 | + Specifies whether to automatically follow referrals |
| 46 | + returned by the LDAP server |
| 47 | + |
| 48 | +For example, to connect to a start-TLS secured LDAP server:: |
| 49 | + |
| 50 | + use Symfony\Component\Ldap\LdapClient; |
| 51 | + |
| 52 | + $ldap = new LdapClient('my-server', 389, 3, false, true); |
| 53 | + |
| 54 | +The :method:`Symfony\\Component\\Ldap\\LdapClient::bind` method |
| 55 | +authenticates a previously configured connection using both the |
| 56 | +distinguished name (DN) and the password of a user:: |
| 57 | + |
| 58 | + use Symfony\Component\Ldap\LdapClient; |
| 59 | + // ... |
| 60 | + |
| 61 | + $ldap->bind($dn, $password); |
| 62 | + |
| 63 | +Once bound (or if you enabled anonymous authentication on your |
| 64 | +LDAP server), you may query the LDAP server using the |
| 65 | +:method:`Symfony\\Component\\Ldap\\LdapClient::find` method:: |
| 66 | + |
| 67 | + use Symfony\Component\Ldap\LdapClient; |
| 68 | + // ... |
| 69 | + |
| 70 | + $ldap->find('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); |
| 71 | + |
| 72 | +.. _Packagist: https://packagist.org/packages/symfony/ldap |
0 commit comments