8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 135c6f7 commit d3942cbCopy full SHA for d3942cb
src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php
@@ -68,31 +68,62 @@ public function testRefreshUser()
68
$provider1 = $this->getProvider();
69
$provider1
70
->expects($this->once())
71
- ->method('refreshUser')
72
- ->willThrowException(new UnsupportedUserException('unsupported'))
+ ->method('supportsClass')
+ ->willReturn(false)
73
;
74
75
$provider2 = $this->getProvider();
76
+ $provider2
77
+ ->expects($this->once())
78
79
+ ->willReturn(true)
80
+ ;
81
+
82
$provider2
83
84
+ ->method('refreshUser')
85
+ ->willThrowException(new UnsupportedUserException('unsupported'))
86
87
88
+ $provider3 = $this->getProvider();
89
+ $provider3
90
91
92
93
94
95
96
97
->method('refreshUser')
98
->willReturn($account = $this->getAccount())
99
100
- $provider = new ChainUserProvider([$provider1, $provider2]);
101
+ $provider = new ChainUserProvider([$provider1, $provider2, $provider3]);
102
$this->assertSame($account, $provider->refreshUser($this->getAccount()));
103
}
104
105
public function testRefreshUserAgain()
106
{
107
108
+ $provider1
109
110
111
112
113
114
115
116
117
->willThrowException(new UsernameNotFoundException('not found'))
118
119
9 628C 5
120
121
122
123
124
125
126
127
128
129
@@ -107,13 +138,25 @@ public function testRefreshUserThrowsUnsupportedUserException()
138
139
$this->expectException('Symfony\Component\Security\Core\Exception\UnsupportedUserException');
140
141
142
143
144
145
146
147
148
149
150
->willThrowException(new UnsupportedUserException('unsupported'))
151
152
153
154
155
156
157
158
159
160
161
162
@@ -171,13 +214,25 @@ public function testSupportsClassWhenNotSupported()
171
214
public function testAcceptsTraversable()
172
215
173
216
217
218
219
220
221
222
174
223
175
224
176
225
177
226
178
227
179
228
180
229
230
231
232
233
234
235
181
236
182
237
183
238
src/Symfony/Component/Security/Core/User/ChainUserProvider.php
@@ -73,6 +73,10 @@ public function refreshUser(UserInterface $user)
foreach ($this->providers as $provider) {
try {
+ if (!$provider->supportsClass(\get_class($user))) {
+ continue;
+ }
return $provider->refreshUser($user);
} catch (UnsupportedUserException $e) {
// try next one
src/Symfony/Component/Security/Http/Firewall/ContextListener.php
@@ -168,12 +168,17 @@ protected function refreshUser(TokenInterface $token)
168
169
$userNotFoundByProvider = false;
170
$userDeauthenticated = false;
+ $userClass = \get_class($user);
foreach ($this->userProviders as $provider) {
if (!$provider instanceof UserProviderInterface) {
throw new \InvalidArgumentException(sprintf('User provider "%s" must implement "%s".', \get_class($provider), UserProviderInterface::class));
+ 6284 if (!$provider->supportsClass($userClass)) {
$refreshedUser = $provider->refreshUser($user);
184
$newToken = clone $token;
@@ -233,7 +238,7 @@ protected function refreshUser(TokenInterface $token)
return null;
239
240
- throw new \RuntimeException(sprintf('There is no user provider for user "%s".', \get_class($user)));
241
+ throw new \RuntimeException(sprintf('There is no user provider for user "%s".', $userClass));
242
243
244
private function safelyUnserialize($serializedToken)
src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php
@@ -256,7 +256,7 @@ public function testIfTokenIsDeauthenticatedTriggersDeprecations()
256
257
$tokenStorage = new TokenStorage();
258
$refreshedUser = new User('foobar', 'baz');
259
- $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(), new SupportingUserProvider($refreshedUser)]);
+ $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(true), new NotSupportingUserProvider(false), new SupportingUserProvider($refreshedUser)]);
260
261
$this->assertSame($refreshedUser, $tokenStorage->getToken()->getUser());
262
@@ -265,7 +265,7 @@ public function testIfTokenIsDeauthenticated()
265
266
267
268
- $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(), new SupportingUserProvider($refreshedUser)], null, true);
+ $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(true), new NotSupportingUserProvider(false), new SupportingUserProvider($refreshedUser)], null, true);
269
270
$this->assertNull($tokenStorage->getToken());
271
@@ -287,7 +287,7 @@ public function testRememberMeGetsCanceledIfTokenIsDeauthenticated()
287
$rememberMeServices = $this->createMock(RememberMeServicesInterface::class);
288
$rememberMeServices->expects($this->once())->method('loginFail');
289
290
- $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(), new SupportingUserProvider($refreshedUser)], null, true, $rememberMeServices);
+ $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(true), new NotSupportingUserProvider(false), new SupportingUserProvider($refreshedUser)], null, true, $rememberMeServices);
291
292
293
@@ -296,7 +296,7 @@ public function testTryAllUserProvidersUntilASupportingUserProviderIsFound()
296
297
298
299
- $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(), new SupportingUserProvider($refreshedUser)], $refreshedUser);
+ $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(true), new NotSupportingUserProvider(false), new SupportingUserProvider($refreshedUser)], $refreshedUser);
300
301
302
@@ -313,22 +313,22 @@ public function testNextSupportingUserProviderIsTriedIfPreviousSupportingUserPro
313
public function testTokenIsSetToNullIfNoUserWasLoadedByTheRegisteredUserProviders()
314
315
316
- $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(), new SupportingUserProvider()]);
+ $this->handleEventWithPreviousSession($tokenStorage, [new NotSupportingUserProvider(true), new NotSupportingUserProvider(false), new SupportingUserProvider()]);
317
318
319
320
321
public function testRuntimeExceptionIsThrownIfNoSupportingUserProviderWasRegistered()
322
323
$this->expectException('RuntimeException');
324
- $this->handleEventWithPreviousSession(new TokenStorage(), [new NotSupportingUserProvider(), new NotSupportingUserProvider()]);
+ $this->handleEventWithPreviousSession(new TokenStorage(), [new NotSupportingUserProvider(false), new NotSupportingUserProvider(true)]);
325
326
327
public function testAcceptsProvidersAsTraversable()
328
329
330
331
- $this->handleEventWithPreviousSession($tokenStorage, new \ArrayObject([new NotSupportingUserProvider(), new SupportingUserProvider($refreshedUser)]), $refreshedUser);
+ $this->handleEventWithPreviousSession($tokenStorage, new \ArrayObject([new NotSupportingUserProvider(true), new NotSupportingUserProvider(false), new SupportingUserProvider($refreshedUser)]), $refreshedUser);
332
333
334
@@ -383,14 +383,26 @@ private function handleEventWithPreviousSession(TokenStorageInterface $tokenStor
383
384
class NotSupportingUserProvider implements UserProviderInterface
385
386
+ /** @var bool */
387
+ private $throwsUnsupportedException;
388
389
+ public function __construct($throwsUnsupportedException)
390
+ {
391
+ $this->throwsUnsupportedException = $throwsUnsupportedException;
392
393
394
public function loadUserByUsername($username)
395
396
throw new UsernameNotFoundException();
397
398
399
public function refreshUser(UserInterface $user)
400
- throw new UnsupportedUserException();
401
+ if ($this->throwsUnsupportedException) {
402
+ throw new UnsupportedUserException();
403
404
405
+ return $user;
406
407
408
public function supportsClass($class)