diff --git a/src/Symfony/Component/Security/Core/CHANGELOG.md b/src/Symfony/Component/Security/Core/CHANGELOG.md index 7cf09c70d4413..5cf976903dc9c 100644 --- a/src/Symfony/Component/Security/Core/CHANGELOG.md +++ b/src/Symfony/Component/Security/Core/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * Add `$token` argument to `UserCheckerInterface::checkPostAuth()` * Deprecate argument `$secret` of `RememberMeToken` * Deprecate returning an empty string in `UserInterface::getUserIdentifier()` + * Make `ChainUserProvider::loadUserByIdentifier()` to pass all arguments to its nodes, not only `$identifier` 7.0 --- diff --git a/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php b/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php index 3f6d223dea178..5cbeea98385c1 100644 --- a/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UserNotFoundException; +use Symfony\Component\Security\Core\User\AttributesBasedUserProviderInterface; use Symfony\Component\Security\Core\User\ChainUserProvider; use Symfony\Component\Security\Core\User\InMemoryUser; use Symfony\Component\Security\Core\User\InMemoryUserProvider; @@ -70,6 +71,28 @@ public function testLoadUserByIdentifierThrowsUserNotFoundException() $provider->loadUserByIdentifier('foo'); } + public function testLoadUserByIdentifierPassesAllArgumentsToInternalProviders(): void + { + $provider1 = $this->createMock(InMemoryUserProvider::class); + $provider1 + ->expects($this->once()) + ->method('loadUserByIdentifier') + ->with('foo') + ->willThrowException(new UserNotFoundException('not found')) + ; + + $provider2 = $this->createMock(AttributesBasedUserProviderInterface::class); + $provider2 + ->expects($this->once()) + ->method('loadUserByIdentifier') + ->with('foo', ['bar' => 'baz']) + ->willReturn($account = $this->createMock(UserInterface::class)) + ; + + $provider = new ChainUserProvider([$provider1, $provider2]); + $this->assertSame($account, $provider->loadUserByIdentifier('foo', ['bar' => 'baz'])); + } + public function testRefreshUser() { $provider1 = $this->createMock(InMemoryUserProvider::class); diff --git a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php index 21e2e618e777b..5f39ab707a7cd 100644 --- a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php @@ -50,7 +50,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface { foreach ($this->providers as $provider) { try { - return $provider->loadUserByIdentifier($identifier); + return $provider->loadUserByIdentifier(...func_get_args()); } catch (UserNotFoundException) { // try next one }