Skip to content

Commit

Permalink
[SecurityBundle] Fix Security::login() on specific firewall
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr authored and nicolas-grekas committed Feb 21, 2023
1 parent 86e3697 commit 601bcc1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Resources/config/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
service_locator([
'security.token_storage' => service('security.token_storage'),
'security.authorization_checker' => service('security.authorization_checker'),
'security.user_authenticator' => service('security.user_authenticator')->ignoreOnInvalid(),
'security.authenticator.managers_locator' => service('security.authenticator.managers_locator')->ignoreOnInvalid(),
'request_stack' => service('request_stack'),
'security.firewall.map' => service('security.firewall.map'),
'security.user_checker' => service('security.user_checker'),
Expand Down
2 changes: 1 addition & 1 deletion Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function login(UserInterface $user, string $authenticatorName = null, str
$authenticator = $this->getAuthenticator($authenticatorName, $firewallName);

$this->container->get('security.user_checker')->checkPreAuth($user);
$this->container->get('security.user_authenticator')->authenticateUser($user, $authenticator, $request);
$this->container->get('security.authenticator.managers_locator')->get($firewallName)->authenticateUser($user, $authenticator, $request);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions Tests/Functional/app/SecurityHelper/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ security:
custom_authenticators:
- 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle\ApiAuthenticator'
provider: main
second:
pattern: ^/second
form_login:
check_path: /second/login/check
custom_authenticators:
- 'Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AuthenticatorBundle\ApiAuthenticator'
provider: main

access_control:
- { path: '^/main/login/check$', roles: IS_AUTHENTICATED_FULLY }
- { path: '^/main/logged-in$', roles: IS_AUTHENTICATED_FULLY }
- { path: '^/second/login/check$', roles: IS_AUTHENTICATED_FULLY }
- { path: '^/second/logged-in$', roles: IS_AUTHENTICATED_FULLY }
8 changes: 8 additions & 0 deletions Tests/Functional/app/SecurityHelper/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ logged-in:
force-logout:
path: /main/force-logout
controller: Symfony\Bundle\SecurityBundle\Tests\Functional\LogoutController::logout

second-force-login:
path: /second/force-login
controller: Symfony\Bundle\SecurityBundle\Tests\Functional\ForceLoginController::welcome

second-logged-in:
path: /second/logged-in
controller: Symfony\Bundle\SecurityBundle\Tests\Functional\LoggedInController
2 changes: 1 addition & 1 deletion Tests/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testLogin()
->willReturnMap([
['request_stack', $requestStack],
['security.firewall.map', $firewallMap],
['security.user_authenticator', $userAuthenticator],
['security.authenticator.managers_locator', new ServiceLocator(['main' => fn () => $userAuthenticator])],
['security.user_checker', $userChecker],
])
;
Expand Down

0 comments on commit 601bcc1

Please sign in to comment.