8000 bug #21579 [Security] LdapUserProvider should not throw an exception … · symfony/symfony@f376080 · GitHub
[go: up one dir, main page]

Skip to content

Commit f376080

Browse files
committed
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
2 parents 81ad336 + ee4d9a7 commit f376080

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Symfony/Component/Security/Core/Tests/User/LdapUserProviderTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
151151
);
152152
}
153153

154-
/**
155-
* @expectedException \Symfony\Component\Security\Core\Exception\InvalidArgumentException
156-
*/
157-
public function testLoadUserByUsernameFailsIfEntryHasNoUidKeyAttribute()
154+
public function testLoadUserByUsernameShouldNotFailIfEntryHasNoUidKeyAttribute()
158155
{
159156
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
160157
$query = $this->getMockBuilder(QueryInterface::class)->getMock();

src/Symfony/Component/Security/Core/User/LdapUserProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class LdapUserProvider implements UserProviderInterface
4848
public function __construct(LdapInterface $ldap, $baseDn, $searchDn = null, $searchPassword = null, array $defaultRoles = array(), $uidKey = 'sAMAccountName', $filter = '({uid_key}={username})', $passwordAttribute = null)
4949
{
5050
if (null === $uidKey) {
51-
$uidKey = 'uid';
51+
$uidKey = 'sAMAccountName';
5252
}
5353

5454
$this->ldap = $ldap;
@@ -87,7 +87,13 @@ public function loadUserByUsername($username)
8787
}
8888

8989
$entry = $entries[0];
90-
$username = $this->getAttributeValue($entry, $this->uidKey);
90+
91+
try {
92+
if (null !== $this->uidKey) {
93+
$username = $this->getAttributeValue($entry, $this->uidKey);
94+
}
95+
} catch (InvalidArgumentException $e) {
96+
}
9197

9298
return $this->loadUser($username, $entry);
9399
}
@@ -123,6 +129,7 @@ public function supportsClass($class)
123129
protected function loadUser($username, Entry $entry)
124130
{
125131
$password = null;
132+
126133
if (null !== $this->passwordAttribute) {
127134
$password = $this->getAttributeValue($entry, $this->passwordAttribute);
128135
}

0 commit comments

Comments
 (0)
0