8000 [Security] LdapUserProvider should not throw an exception if the UID … · symfony/symfony@ee4d9a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee4d9a7

Browse files
csarrazifabpot
authored andcommitted
[Security] LdapUserProvider should not throw an exception if the UID key does not exist in an LDAP entry
1 parent 81ad336 commit ee4d9a7

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