Skip to content

Commit 2205b62

Browse files
committed
bug #61595 [Security] Pass attributes to nested ChainUserProviders (valtzu)
This PR was merged into the 6.4 branch. Discussion ---------- [Security] Pass attributes to nested `ChainUserProvider`s | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT Fix a missed corner case of #61548 found by `@nicolas`-grekas in #61594 (comment) _(Not needed on 8.0)_ Commits ------- cb75dd2 [Security] Pass attributes to nested `ChainUserProviders`
2 parents 1207f74 + cb75dd2 commit 2205b62

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public function testLoadUserByIdentifier()
4949

5050
public function testLoadUserByIdentifierWithAttributes()
5151
{
52+
$provider0 = $this->createMock(ChainUserProvider::class);
53+
$provider0
54+
->expects($this->once())
55+
->method('loadUserByIdentifier')
56+
->with($this->equalTo('foo'), $this->equalTo(['attr' => 5]))
57+
->willThrowException(new UserNotFoundException('not found'))
58+
;
59+
5260
$provider1 = $this->createMock(UserProviderInterface::class);
5361
$provider1
5462
->expects($this->once())
@@ -65,7 +73,7 @@ public function testLoadUserByIdentifierWithAttributes()
6573
->willReturn($account = $this->createMock(UserInterface::class))
6674
;
6775

68-
$provider = new ChainUserProvider([$provider1, $provider2]);
76+
$provider = new ChainUserProvider([$provider0, $provider1, $provider2]);
6977
$this->assertSame($account, $provider->loadUserByIdentifier('foo', ['attr' => 5]));
7078
}
7179

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function loadUserByIdentifier(string $identifier/* , array $attributes =
6464
$attributes = \func_num_args() > 1 ? func_get_arg(1) : [];
6565
foreach ($this->providers as $provider) {
6666
try {
67-
if ($provider instanceof AttributesBasedUserProviderInterface) {
67+
if ($provider instanceof AttributesBasedUserProviderInterface || $provider instanceof self) {
6868
return $provider->loadUserByIdentifier($identifier, $attributes);
6969
}
7070

0 commit comments

Comments
 (0)