[Security] LdapUserProvider should not throw an exception if the UID key does not exist in an LDAP entry
This commit is contained in:
parent
81ad336a8a
commit
ee4d9a70c1
@ -151,10 +151,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 @@ class LdapUserProvider implements UserProviderInterface
|
||||
}
|
||||
|
||||
$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 @@ class LdapUserProvider implements UserProviderInterface
|
||||
protected function loadUser($username, Entry $entry)
|
||||
{
|
||||
$password = null;
|
||||
|
||||
if (null !== $this->passwordAttribute) {
|
||||
$password = $this->getAttributeValue($entry, $this->passwordAttribute);
|
||||
}
|
||||
|
Reference in New Issue
Block a user