Skip to content

Commit 5431c40

Browse files
Merge branch '6.4' into 7.2
* 6.4: [Validator] Review Latvian translations Fixed lazy-loading ghost objects generation with property hooks with default values. remove no longer used service definition [Config] Fix generated comment for multiline "info" Fix: exclude remember_me from security login authenticators
2 parents 257fb12 + 671ab53 commit 5431c40

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

Security.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ private function getAuthenticator(?string $authenticatorName, string $firewallNa
158158
$firewallAuthenticatorLocator = $this->authenticators[$firewallName];
159159

160160
if (!$authenticatorName) {
161-
$authenticatorIds = array_keys($firewallAuthenticatorLocator->getProvidedServices());
162-
161+
$authenticatorIds = array_filter(array_keys($firewallAuthenticatorLocator->getProvidedServices()), fn (string $authenticatorId) => $authenticatorId !== \sprintf('security.authenticator.remember_me.%s', $firewallName));
163162
if (!$authenticatorIds) {
164163
throw new LogicException(\sprintf('No authenticator was found for the firewall "%s".', $firewallName));
165164
}

Tests/SecurityTest.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ public function testLogin()
152152
$firewallAuthenticatorLocator
153153
->expects($this->once())
154154
->method('getProvidedServices')
155-
->willReturn(['security.authenticator.custom.dev' => $authenticator])
155+
->willReturn([
156+
'security.authenticator.custom.dev' => $authenticator,
157+
'security.authenticator.remember_me.main' => $authenticator
158+
])
156159
;
157160
$firewallAuthenticatorLocator
158161
->expects($this->once())
@@ -252,6 +255,49 @@ public function testLoginWithoutRequestContext()
252255
$security->login($user);
253256
}
254257

258+
public function testLoginFailsWhenTooManyAuthenticatorsFound()
259+
{
260+
$request = new Request();
261+
$authenticator = $this->createMock(AuthenticatorInterface::class);
262+
$requestStack = $this->createMock(RequestStack::class);
263+
$firewallMap = $this->createMock(FirewallMap::class);
264+
$firewall = new FirewallConfig('main', 'main');
265+
$userAuthenticator = $this->createMock(UserAuthenticatorInterface::class);
266+
$user = $this->createMock(UserInterface::class);
267+
$userChecker = $this->createMock(UserCheckerInterface::class);
268+
269+
$container = $this->createMock(ContainerInterface::class);
270+
$container
271+
->expects($this->atLeastOnce())
272+
->method('get')
273+
->willReturnMap([
274+
['request_stack', $requestStack],
275+
['security.firewall.map', $firewallMap],
276+
['security.authenticator.managers_locator', $this->createContainer('main', $userAuthenticator)],
277+
['security.user_checker_locator', $this->createContainer('main', $userChecker)],
278+
])
279+
;
280+
281+
$requestStack->expects($this->once())->method('getCurrentRequest')->willReturn($request);
282+
$firewallMap->expects($this->once())->method('getFirewallConfig')->willReturn($firewall);
283+
284+
$firewallAuthenticatorLocator = $this->createMock(ServiceProviderInterface::class);
285+
$firewallAuthenticatorLocator
286+
->expects($this->once())
287+
->method('getProvidedServices')
288+
->willReturn([
289+
'security.authenticator.custom.main' => $authenticator,
290+
'security.authenticator.other.main' => $authenticator
291+
])
292+
;
293+
294+
$security = new Security($container, ['main' => $firewallAuthenticatorLocator]);
295+
296+
$this->expectException(\LogicException::class);
297+
$this->expectExceptionMessage('Too many authenticators were found for the current firewall "main". You must provide an instance of "Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface" to login programmatically. The available authenticators for the firewall "main" are "security.authenticator.custom.main" ,"security.authenticator.other.main');
298+
$security->login($user);
299+
}
300+
255301
public function testLogout()
256302
{
257303
$request = new Request();

0 commit comments

Comments
 (0)