-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Ldap] Updated Ldap component documentation for 3.1 #6982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,10 @@ You can install the component in 2 different ways: | |
Usage | ||
----- | ||
|
||
The :class:`Symfony\\Component\\Ldap\\LdapClient` class provides methods | ||
The :class:`Symfony\\Component\\Ldap\\Ldap` class provides methods | ||
to authenticate and query against an LDAP server. | ||
|
||
The :class:`Symfony\\Component\\Ldap\\LdapClient` class can be configured | ||
The :class:`Symfony\\Component\\Ldap\\Ldap` class can be configured | ||
using the following options: | ||
|
||
``host`` | ||
|
@@ -35,38 +35,96 @@ using the following options: | |
``version`` | ||
The version of the LDAP protocol to use | ||
|
||
``useSsl`` | ||
Whether or not to secure the connection using SSL | ||
``encryption`` | ||
Your encryption mechanism (``ssl``, ``tls`` or ``none``) | ||
|
||
``useStartTls`` | ||
Whether or not to secure the connection using StartTLS | ||
``connection_string`` | ||
You may use this option instead of ``host`` and ``port`` to connect to the | ||
LDAP server | ||
|
||
``optReferrals`` | ||
Specifies whether to automatically follow referrals | ||
returned by the LDAP server | ||
|
||
For example, to connect to a start-TLS secured LDAP server:: | ||
|
||
use Symfony\Component\Ldap\LdapClient; | ||
use Symfony\Component\Ldap\Ldap; | ||
|
||
$ldap = new LdapClient('my-server', 389, 3, false, true); | ||
$ldap = Ldap::create('ext_ldap', array( | ||
'host' => 'my-server', | ||
'encryption' => 'ssl', | ||
)); | ||
|
||
The :method:`Symfony\\Component\\Ldap\\LdapClient::bind` method | ||
Or you could directly specify a connection string:: | ||
|
||
use Symfony\Component\Ldap\Ldap; | ||
|
||
$ldap = Ldap::create('ext_ldap', array('connection_string' => 'ldaps://my-server:636')); | ||
|
||
The :method:`Symfony\\Component\\Ldap\\Ldap::bind` method | ||
authenticates a previously configured connection using both the | ||
distinguished name (DN) and the password of a user:: | ||
|
||
use Symfony\Component\Ldap\LdapClient; | ||
use Symfony\Component\Ldap\Ldap; | ||
// ... | ||
|
||
$ldap->bind($dn, $password); | ||
|
||
Once bound (or if you enabled anonymous authentication on your | ||
LDAP server), you may query the LDAP server using the | ||
:method:`Symfony\\Component\\Ldap\\LdapClient::find` method:: | ||
:method:`Symfony\\Component\\Ldap\\Ldap::query` method:: | ||
|
||
use Symfony\Component\Ldap\Ldap; | ||
// ... | ||
|
||
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); | ||
$results = $query->execute(); | ||
|
||
foreach ($results as $entry) { | ||
// Do something with the results | ||
} | ||
|
||
By default, LDAP entries are lazy-loaded. If you wish to fetch | ||
all entries in a single call and do something with the results' | ||
array, you may use the | ||
:method:`Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\Collection::toArray` method:: | ||
|
||
use Symfony\Component\Ldap\Ldap; | ||
// ... | ||
|
||
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); | ||
$results = $query->execute()->toArray(); | ||
|
||
// Do something with the results array | ||
|
||
Creating or Updating Entries | ||
---------------------------- | ||
|
||
The Ldap component provides means to create new LDAP entries, update or even | ||
delete existing ones:: | ||
|
||
use Symfony\Component\Ldap\LdapClient; | ||
use Symfony\Component\Ldap\Ldap; | ||
use Symfony\Component\Ldap\Entry; | ||
// ... | ||
|
||
$ldap->find('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); | ||
$entry = new Entry('cn=Fabien Potencier,dc=symfony,dc=com', array( | ||
'sn' => array('fabpot'), | ||
'objectClass' => array('inetOrgPerson'), | ||
)); | ||
|
||
$em = $ldap->getEntryManager(); | ||
|
||
// Creating a new entry | ||
$em->add($entry); | ||
|
||
// Finding and updating an existing entry | ||
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); | ||
$result = $query->execute(); | ||
$entry = $result[0]; | ||
$entry->addAttribute('email', array('[email protected]')); | ||
$em->update($entry); | ||
|
||
// Removing an existing entry | ||
$em->remove(new Entry('cn=Test User,dc=symfony,dc=com')); | ||
|
||
.. _Packagist: https://packagist.org/packages/symfony/ldap |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but this option name looks weird. Is there a better alternative to
connection_string
? For example, likedsn
in the database world.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the term "DSN" is specific to the database world. "connection_string" is standard for all software, and not only databases. :)