Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Symfony/Bundle/SecurityBundle/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ private function getAuthenticator(?string $authenticatorName, string $firewallNa
$firewallAuthenticatorLocator = $this->authenticators[$firewallName];

if (!$authenticatorName) {
$authenticatorIds = array_keys($firewallAuthenticatorLocator->getProvidedServices());

$authenticatorIds = array_filter(array_keys($firewallAuthenticatorLocator->getProvidedServices()), fn (string $authenticatorId) => $authenticatorId !== \sprintf('security.authenticator.remember_me.%s', $firewallName));
if (!$authenticatorIds) {
throw new LogicException(sprintf('No authenticator was found for the firewall "%s".', $firewallName));
}
Expand Down
48 changes: 47 additions & 1 deletion src/Symfony/Bundle/SecurityBundle/Tests/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ public function testLogin()
$firewallAuthenticatorLocator
->expects($this->once())
->method('getProvidedServices')
->willReturn(['security.authenticator.custom.dev' => $authenticator])
->willReturn([
'security.authenticator.custom.dev' => $authenticator,
'security.authenticator.remember_me.main' => $authenticator
])
;
$firewallAuthenticatorLocator
->expects($this->once())
Expand Down Expand Up @@ -274,6 +277,49 @@ public function testLoginWithoutRequestContext()
$security->login($user);
}

public function testLoginFailsWhenTooManyAuthenticatorsFound()
{
$request = new Request();
$authenticator = $this->createMock(AuthenticatorInterface::class);
$requestStack = $this->createMock(RequestStack::class);
$firewallMap = $this->createMock(FirewallMap::class);
$firewall = new FirewallConfig('main', 'main');
$userAuthenticator = $this->createMock(UserAuthenticatorInterface::class);
$user = $this->createMock(UserInterface::class);
$userChecker = $this->createMock(UserCheckerInterface::class);

$container = $this->createMock(ContainerInterface::class);
$container
->expects($this->atLeastOnce())
->method('get')
->willReturnMap([
['request_stack', $requestStack],
['security.firewall.map', $firewallMap],
['security.authenticator.managers_locator', $this->createContainer('main', $userAuthenticator)],
['security.user_checker_locator', $this->createContainer('main', $userChecker)],
])
;

$requestStack->expects($this->once())->method('getCurrentRequest')->willReturn($request);
$firewallMap->expects($this->once())->method('getFirewallConfig')->willReturn($firewall);

$firewallAuthenticatorLocator = $this->createMock(ServiceProviderInterface::class);
$firewallAuthenticatorLocator
->expects($this->once())
->method('getProvidedServices')
->willReturn([
'security.authenticator.custom.main' => $authenticator,
'security.authenticator.other.main' => $authenticator
])
;

$security = new Security($container, ['main' => $firewallAuthenticatorLocator]);

$this->expectException(\LogicException::class);
$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');
$security->login($user);
}

public function testLogout()
{
$request = new Request();
Expand Down