minor #32939 [Security] remove the deprecated LdapUserProvider class (xabbuh)
This PR was merged into the 5.0-dev branch.
Discussion
----------
[Security] remove the deprecated LdapUserProvider class
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Commits
-------
7d6fc14452
remove the deprecated LdapUserProvider class
This commit is contained in:
commit
6497ec362e
@ -4,6 +4,7 @@ CHANGELOG
|
|||||||
5.0.0
|
5.0.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
* The `LdapUserProvider` class has been removed, use `Symfony\Component\Ldap\Security\LdapUserProvider` instead.
|
||||||
* The `FirewallMapInterface::getListeners()` method must return an array of 3 elements.
|
* The `FirewallMapInterface::getListeners()` method must return an array of 3 elements.
|
||||||
* Removed the `ContextListener::setLogoutOnUserChange()` method.
|
* Removed the `ContextListener::setLogoutOnUserChange()` method.
|
||||||
* Removed the `ListenerInterface`, turn your listeners into callables instead.
|
* Removed the `ListenerInterface`, turn your listeners into callables instead.
|
||||||
|
@ -1,354 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\Security\Core\Tests\User;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Symfony\Component\Ldap\Adapter\CollectionInterface;
|
|
||||||
use Symfony\Component\Ldap\Adapter\QueryInterface;
|
|
||||||
use Symfony\Component\Ldap\Entry;
|
|
||||||
use Symfony\Component\Ldap\Exception\ConnectionException;
|
|
||||||
use Symfony\Component\Ldap\LdapInterface;
|
|
||||||
use Symfony\Component\Security\Core\User\LdapUserProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
* @requires extension ldap
|
|
||||||
*/
|
|
||||||
class LdapUserProviderTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testLoadUserByUsernameFailsIfCantConnectToLdap()
|
|
||||||
{
|
|
||||||
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('bind')
|
|
||||||
->willThrowException(new ConnectionException())
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
|
|
||||||
$provider->loadUserByUsername('foo');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameFailsIfNoLdapEntries()
|
|
||||||
{
|
|
||||||
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(0)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
|
|
||||||
$provider->loadUserByUsername('foo');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
|
|
||||||
{
|
|
||||||
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(2)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
|
|
||||||
$provider->loadUserByUsername('foo');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
|
|
||||||
{
|
|
||||||
$this->expectException('Symfony\Component\Security\Core\Exception\InvalidArgumentException');
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('offsetGet')
|
|
||||||
->with(0)
|
|
||||||
->willReturn(new Entry('foo', [
|
|
||||||
'sAMAccountName' => ['foo'],
|
|
||||||
'userpassword' => ['bar', 'baz'],
|
|
||||||
]
|
|
||||||
))
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(1)
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, [], 'sAMAccountName', '({uid_key}={username})', 'userpassword');
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
'Symfony\Component\Security\Core\User\User',
|
|
||||||
$provider->loadUserByUsername('foo')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameShouldNotFailIfEntryHasNoUidKeyAttribute()
|
|
||||||
{
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('offsetGet')
|
|
||||||
->with(0)
|
|
||||||
->willReturn(new Entry('foo', []))
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(1)
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, [], 'sAMAccountName', '({uid_key}={username})');
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
'Symfony\Component\Security\Core\User\User',
|
|
||||||
$provider->loadUserByUsername('foo')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameFailsIfEntryHasNoPasswordAttribute()
|
|
||||||
{
|
|
||||||
$this->expectException('Symfony\Component\Security\Core\Exception\InvalidArgumentException');
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('offsetGet')
|
|
||||||
->with(0)
|
|
||||||
->willReturn(new Entry('foo', [
|
|
||||||
'sAMAccountName' => ['foo'],
|
|
||||||
]
|
|
||||||
))
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(1)
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, [], 'sAMAccountName', '({uid_key}={username})', 'userpassword');
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
'Symfony\Component\Security\Core\User\User',
|
|
||||||
$provider->loadUserByUsername('foo')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttribute()
|
|
||||||
{
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('offsetGet')
|
|
||||||
->with(0)
|
|
||||||
->willReturn(new Entry('foo', [
|
|
||||||
'sAMAccountName' => ['foo'],
|
|
||||||
]
|
|
||||||
))
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(1)
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
'Symfony\Component\Security\Core\User\User',
|
|
||||||
$provider->loadUserByUsername('foo')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttributeAndWrongCase()
|
|
||||||
{
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('offsetGet')
|
|
||||||
->with(0)
|
|
||||||
->willReturn(new Entry('foo', [
|
|
||||||
'sAMAccountName' => ['foo'],
|
|
||||||
]
|
|
||||||
))
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(1)
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('Foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com');
|
|
||||||
$this->assertSame('foo', $provider->loadUserByUsername('Foo')->getUsername());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoadUserByUsernameIsSuccessfulWithPasswordAttribute()
|
|
||||||
{
|
|
||||||
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
|
|
||||||
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
|
|
||||||
$query
|
|
||||||
->expects($this->once())
|
|
||||||
->method('execute')
|
|
||||||
->willReturn($result)
|
|
||||||
;
|
|
||||||
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('offsetGet')
|
|
||||||
->with(0)
|
|
||||||
->willReturn(new Entry('foo', [
|
|
||||||
'sAMAccountName' => ['foo'],
|
|
||||||
'userpassword' => ['bar'],
|
|
||||||
'email' => ['elsa@symfony.com'],
|
|
||||||
]
|
|
||||||
))
|
|
||||||
;
|
|
||||||
$result
|
|
||||||
->expects($this->once())
|
|
||||||
->method('count')
|
|
||||||
->willReturn(1)
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('escape')
|
|
||||||
->willReturn('foo')
|
|
||||||
;
|
|
||||||
$ldap
|
|
||||||
->expects($this->once())
|
|
||||||
->method('query')
|
|
||||||
->willReturn($query)
|
|
||||||
;
|
|
||||||
|
|
||||||
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, [], 'sAMAccountName', '({uid_key}={username})', 'userpassword', ['email']);
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
'Symfony\Component\Security\Core\User\User',
|
|
||||||
$provider->loadUserByUsername('foo')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\Security\Core\User;
|
|
||||||
|
|
||||||
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', LdapUserProvider::class, BaseLdapUserProvider::class), E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
use Symfony\Component\Ldap\Entry;
|
|
||||||
use Symfony\Component\Ldap\Security\LdapUserProvider as BaseLdapUserProvider;
|
|
||||||
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LdapUserProvider is a simple user provider on top of ldap.
|
|
||||||
*
|
|
||||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
|
||||||
* @author Charles Sarrazin <charles@sarraz.in>
|
|
||||||
*
|
|
||||||
* @deprecated since Symfony 4.4, use "Symfony\Component\Ldap\Security\LdapUserProvider" instead
|
|
||||||
*/
|
|
||||||
class LdapUserProvider extends BaseLdapUserProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function refreshUser(UserInterface $user)
|
|
||||||
{
|
|
||||||
if (!$user instanceof User) {
|
|
||||||
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new User($user->getUsername(), null, $user->getRoles());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function supportsClass(string $class)
|
|
||||||
{
|
|
||||||
return 'Symfony\Component\Security\Core\User\User' === $class;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a user from an LDAP entry.
|
|
||||||
*
|
|
||||||
* @return User
|
|
||||||
*/
|
|
||||||
protected function loadUser(string $username, Entry $entry)
|
|
||||||
{
|
|
||||||
$ldapUser = parent::loadUser($username, $entry);
|
|
||||||
|
|
||||||
return new User($ldapUser->getUsername(), $ldapUser->getPassword(), $ldapUser->getRoles(), true, true, true, true, $ldapUser->getExtraFields());
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user