Permalink
Browse files

bug #21579 [Security] LdapUserProvider should not throw an exception …

…if the UID key does not exist in an LDAP entry (csarrazi)

This PR was submitted for the 3.1 branch but it was merged into the 3.2 branch instead (closes #21579).

Discussion
----------

[Security] LdapUserProvider should not throw an exception if the UID key does not exist in an LDAP entry

| Q             | A
| ------------- | ---
| Branch?       | 3.1+
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21577
| License       | MIT
| Doc PR        |

This ticket should fix #21577, which was introduced by commit 6641b79

LdapUserProvider should not throw an exception if the uid key does not exist in the entry.

Commits
-------

ee4d9a7 [Security] LdapUserProvider should not throw an exception if the UID key does not exist in an LDAP entry
  • Loading branch information...
2 parents 81ad336 + ee4d9a7 commit f376080b4b903b3086159cffbc72431c975235dc @fabpot fabpot committed Feb 11, 2017
@@ -151,10 +151,7 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
);
}
- /**
- * @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
- */
- public function testLoadUserByUsernameFailsIfEntryHasNoUidKeyAttribute()
+ public function testLoadUserByUsernameShouldNotFailIfEntryHasNoUidKeyAttribute()
{
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
@@ -48,7 +48,7 @@ class LdapUserProvider implements UserProviderInterface
public function __construct(LdapInterface $ldap, $baseDn, $searchDn = null, $searchPassword = null, array $defaultRoles = array(), $uidKey = 'sAMAccountName', $filter = '({uid_key}={username})', $passwordAttribute = null)
{
if (null === $uidKey) {
- $uidKey = 'uid';
+ $uidKey = 'sAMAccountName';
}
$this->ldap = $ldap;
@@ -87,7 +87,13 @@ public function loadUserByUsername($username)
}
$entry = $entries[0];
- $username = $this->getAttributeValue($entry, $this->uidKey);
+
+ try {
+ if (null !== $this->uidKey) {
+ $username = $this->getAttributeValue($entry, $this->uidKey);
+ }
+ } catch (InvalidArgumentException $e) {
+ }
return $this->loadUser($username, $entry);
}
@@ -123,6 +129,7 @@ public function supportsClass($class)
protected function loadUser($username, Entry $entry)
{
$password = null;
+
if (null !== $this->passwordAttribute) {
$password = $this->getAttributeValue($entry, $this->passwordAttribute);
}

0 comments on commit f376080

Please sign in to comment.