Skip to content

Commit 3cfb54e

Browse files
authored
Use base search for known DN lookup (#31)
* Use base search for known DN lookup Performing a 'base' search using the DN as base is the standard way. Using (distinguishedName=) as a filter is not universal – for example, OpenLDAP uses entryDN instead. And while OpenLDAP 2.6.x seems to *recognize* distinguishedName, it gives a completely different result (applying the match to all DN-containing attributes rather than to the entry's own DN) – so the search gives 25 entries, none of which were the correct one. * Use base search in AttributeAddUsersGroups as well
1 parent 9d77cb8 commit 3cfb54e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/Auth/Process/AttributeAddUsersGroups.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ protected function search(array $memberOf, array $options): array
354354
// Init the groups variable
355355
$entries = [];
356356
$ldapUtils = new LdapUtils();
357+
$options['scope'] = 'base';
357358

358359
// Check each DN of the passed memberOf
359360
foreach ($memberOf as $dn) {
@@ -369,8 +370,8 @@ protected function search(array $memberOf, array $options): array
369370
// Query LDAP for the attribute values for the DN
370371
$entry = $ldapUtils->search(
371372
$this->ldapObject,
372-
$this->searchBase,
373-
sprintf("(&(%s=%s)(distinguishedName=%s))", $map['type'], $this->type_map['group'], $dn),
373+
[$dn],
374+
sprintf("(%s=%s)", $map['type'], $this->type_map['group']),
374375
$options,
375376
true,
376377
);

lib/Auth/Source/Ldap.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ protected function login(string $username, string $password): array
134134
}
135135

136136
$ldapUtils->bind($ldapObject, $dn, $password);
137-
$filter = sprintf('(distinguishedName=%s)', $dn);
137+
138+
$options['scope'] = 'base';
139+
$filter = '(objectClass=*)';
138140

139141
/** @psalm-var \Symfony\Component\Ldap\Entry $entry */
140-
$entry = $ldapUtils->search($ldapObject, $searchBase, $filter, $options, false);
142+
$entry = $ldapUtils->search($ldapObject, [$dn], $filter, $options, false);
141143

142144
$attributes = $this->ldapConfig->getOptionalValue('attributes', []);
143145
if ($attributes === null) {

0 commit comments

Comments
 (0)