diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php index cf77d99fdf0b..53a6b503a1e8 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AnonymousFactory.php @@ -42,13 +42,13 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider, return [$providerId, $listenerId, $defaultEntryPoint]; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId): string + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { if (null === $config['secret']) { $config['secret'] = new Parameter('container.build_hash'); } - $authenticatorId = 'security.authenticator.anonymous.'.$id; + $authenticatorId = 'security.authenticator.anonymous.'.$firewallName; $container ->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.anonymous')) ->replaceArgument(0, $config['secret']); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AuthenticatorFactoryInterface.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AuthenticatorFactoryInterface.php index acd1fce318e9..cb65f31fe5ef 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AuthenticatorFactoryInterface.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AuthenticatorFactoryInterface.php @@ -25,5 +25,5 @@ interface AuthenticatorFactoryInterface * * @return string|string[] The authenticator service ID(s) to be used by the firewall */ - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId); + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId); } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/CustomAuthenticatorFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/CustomAuthenticatorFactory.php index 43c236fcfaf6..95fa3c050fbb 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/CustomAuthenticatorFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/CustomAuthenticatorFactory.php @@ -49,7 +49,7 @@ public function addConfiguration(NodeDefinition $builder) ; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId): array + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): array { return $config['services']; } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php index 2edfb3ff3479..c5f247c307be 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php @@ -103,19 +103,19 @@ public function createEntryPoint(ContainerBuilder $container, string $id, array return $entryPointId; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId): string + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { if (isset($config['csrf_token_generator'])) { throw new InvalidConfigurationException('The "csrf_token_generator" option of "form_login" is only available when "security.enable_authenticator_manager" is set to "false", use "enable_csrf" instead.'); } - $authenticatorId = 'security.authenticator.form_login.'.$id; + $authenticatorId = 'security.authenticator.form_login.'.$firewallName; $options = array_intersect_key($config, $this->options); $container ->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.form_login')) ->replaceArgument(1, new Reference($userProviderId)) - ->replaceArgument(2, new Reference($this->createAuthenticationSuccessHandler($container, $id, $config))) - ->replaceArgument(3, new Reference($this->createAuthenticationFailureHandler($container, $id, $config))) + ->replaceArgument(2, new Reference($this->createAuthenticationSuccessHandler($container, $firewallName, $config))) + ->replaceArgument(3, new Reference($this->createAuthenticationFailureHandler($container, $firewallName, $config))) ->replaceArgument(4, $options); return $authenticatorId; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php index 9d121b17fec4..a698d2a1d1ae 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php @@ -46,9 +46,9 @@ public function create(ContainerBuilder $container, string $id, array $config, s return [$provider, $listenerId, $entryPointId]; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId): string + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { - $authenticatorId = 'security.authenticator.http_basic.'.$id; + $authenticatorId = 'security.authenticator.http_basic.'.$firewallName; $container ->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.http_basic')) ->replaceArgument(0, $config['realm']) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php index 4e09a3d2f8b1..7aa90405799a 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/JsonLoginFactory.php @@ -97,15 +97,15 @@ protected function createListener(ContainerBuilder $container, string $id, array return $listenerId; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId) + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId) { - $authenticatorId = 'security.authenticator.json_login.'.$id; + $authenticatorId = 'security.authenticator.json_login.'.$firewallName; $options = array_intersect_key($config, $this->options); $container ->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.json_login')) ->replaceArgument(1, new Reference($userProviderId)) - ->replaceArgument(2, isset($config['success_handler']) ? new Reference($this->createAuthenticationSuccessHandler($container, $id, $config)) : null) - ->replaceArgument(3, isset($config['failure_handler']) ? new Reference($this->createAuthenticationFailureHandler($container, $id, $config)) : null) + ->replaceArgument(2, isset($config['success_handler']) ? new Reference($this->createAuthenticationSuccessHandler($container, $firewallName, $config)) : null) + ->replaceArgument(3, isset($config['failure_handler']) ? new Reference($this->createAuthenticationFailureHandler($container, $firewallName, $config)) : null) ->replaceArgument(4, $options); return $authenticatorId; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php index 5f530a17e210..4b29db1a03d3 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php @@ -89,19 +89,19 @@ public function create(ContainerBuilder $container, string $id, array $config, ? return [$authProviderId, $listenerId, $defaultEntryPoint]; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId): string + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { - $templateId = $this->generateRememberMeServicesTemplateId($config, $id); - $rememberMeServicesId = $templateId.'.'.$id; + $templateId = $this->generateRememberMeServicesTemplateId($config, $firewallName); + $rememberMeServicesId = $templateId.'.'.$firewallName; // create remember me services (which manage the remember me cookies) - $this->createRememberMeServices($container, $id, $templateId, [new Reference($userProviderId)], $config); + $this->createRememberMeServices($container, $firewallName, $templateId, [new Reference($userProviderId)], $config); // create remember me listener (which executes the remember me services for other authenticators and logout) - $this->createRememberMeListener($container, $id, $rememberMeServicesId); + $this->createRememberMeListener($container, $firewallName, $rememberMeServicesId); // create remember me authenticator (which re-authenticates the user based on the remember me cookie) - $authenticatorId = 'security.authenticator.remember_me.'.$id; + $authenticatorId = 'security.authenticator.remember_me.'.$firewallName; $container ->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.remember_me')) ->replaceArgument(0, new Reference($rememberMeServicesId)) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php index 0f0c44f8abc2..e25c3c7d07df 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RemoteUserFactory.php @@ -43,9 +43,9 @@ public function create(ContainerBuilder $container, string $id, array $config, s return [$providerId, $listenerId, $defaultEntryPoint]; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId) + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId) { - $authenticatorId = 'security.authenticator.remote_user.'.$id; + $authenticatorId = 'security.authenticator.remote_user.'.$firewallName; $container ->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.remote_user')) ->replaceArgument(0, new Reference($userProviderId)) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php index 604cee7e4490..f966302a1da6 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php @@ -44,9 +44,9 @@ public function create(ContainerBuilder $container, string $id, array $config, s return [$providerId, $listenerId, $defaultEntryPoint]; } - public function createAuthenticator(ContainerBuilder $container, string $id, array $config, string $userProviderId) + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId) { - $authenticatorId = 'security.authenticator.x509.'.$id; + $authenticatorId = 'security.authenticator.x509.'.$firewallName; $container ->setDefinition($authenticatorId, new ChildDefinition('security.authenticator.x509')) ->replaceArgument(0, new Reference($userProviderId)) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 35bcf015575d..ac089d1eb2ea 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -286,7 +286,7 @@ private function createFirewalls(array $config, ContainerBuilder $container) // add authentication providers to authentication manager $authenticationProviders = array_map(function ($id) { return new Reference($id); - }, array_unique($authenticationProviders)); + }, array_values(array_unique($authenticationProviders))); $container ->getDefinition('security.authentication.manager') @@ -439,9 +439,9 @@ private function createFirewall(ContainerBuilder $container, string $id, array $ $firewallAuthenticationProviders = []; list($authListeners, $defaultEntryPoint) = $this->createAuthenticationListeners($container, $id, $firewall, $firewallAuthenticationProviders, $defaultProvider, $providerIds, $configuredEntryPoint, $contextListenerId); - $authenticationProviders = array_merge($authenticationProviders, $firewallAuthenticationProviders); - - if ($this->authenticatorManagerEnabled) { + if (!$this->authenticatorManagerEnabled) { + $authenticationProviders = array_merge($authenticationProviders, $firewallAuthenticationProviders); + } else { // authenticator manager $authenticators = array_map(function ($id) { return new Reference($id); @@ -535,10 +535,10 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri $authenticators = $factory->createAuthenticator($container, $id, $firewall[$key], $userProvider); if (\is_array($authenticators)) { foreach ($authenticators as $i => $authenticator) { - $authenticationProviders[$id.'_'.$key.$i] = $authenticator; + $authenticationProviders[] = $authenticator; } } else { - $authenticationProviders[$id.'_'.$key] = $authenticators; + $authenticationProviders[] = $authenticators; } if ($factory instanceof EntryPointFactoryInterface) { @@ -548,7 +548,7 @@ private function createAuthenticationListeners(ContainerBuilder $container, stri list($provider, $listenerId, $defaultEntryPoint) = $factory->create($container, $id, $firewall[$key], $userProvider, $defaultEntryPoint); $listeners[] = new Reference($listenerId); - $authenticationProviders[$id.'_'.$key] = $provider; + $authenticationProviders[] = $provider; } $hasListeners = true; } diff --git a/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php b/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php index 36a991610593..1d6e1ff2ac5d 100644 --- a/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php +++ b/src/Symfony/Component/Security/Http/Authentication/AuthenticatorManager.php @@ -47,17 +47,17 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent private $eventDispatcher; private $eraseCredentials; private $logger; - private $providerKey; + private $firewallName; /** - * @param AuthenticatorInterface[] $authenticators The authenticators, with their unique providerKey as key + * @param AuthenticatorInterface[] $authenticators */ - public function __construct(iterable $authenticators, TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher, string $providerKey, ?LoggerInterface $logger = null, bool $eraseCredentials = true) + public function __construct(iterable $authenticators, TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher, string $firewallName, ?LoggerInterface $logger = null, bool $eraseCredentials = true) { $this->authenticators = $authenticators; $this->tokenStorage = $tokenStorage; $this->eventDispatcher = $eventDispatcher; - $this->providerKey = $providerKey; + $this->firewallName = $firewallName; $this->logger = $logger; $this->eraseCredentials = $eraseCredentials; } @@ -68,7 +68,7 @@ public function __construct(iterable $authenticators, TokenStorageInterface $tok public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request, array $badges = []): ?Response { // create an authenticated token for the User - $token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport($user, $badges), $this->providerKey); + $token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport($user, $badges), $this->firewallName); // authenticate this in the system return $this->handleAuthenticationSuccess($token, $passport, $request, $authenticator); @@ -77,27 +77,27 @@ public function authenticateUser(UserInterface $user, AuthenticatorInterface $au public function supports(Request $request): ?bool { if (null !== $this->logger) { - $context = ['firewall_key' => $this->providerKey]; + $context = ['firewall_key' => $this->firewallName]; if ($this->authenticators instanceof \Countable || \is_array($this->authenticators)) { $context['authenticators'] = \count($this->authenticators); } - $this->logger->debug('Checking for guard authentication credentials.', $context); + $this->logger->debug('Checking for authenticator support.', $context); } $authenticators = []; $lazy = true; - foreach ($this->authenticators as $key => $authenticator) { + foreach ($this->authenticators as $authenticator) { if (null !== $this->logger) { - $this->logger->debug('Checking support on authenticator.', ['firewall_key' => $this->providerKey, 'authenticator' => \get_class($authenticator)]); + $this->logger->debug('Checking support on authenticator.', ['firewall_key' => $this->firewallName, 'authenticator' => \get_class($authenticator)]); } if (false !== $supports = $authenticator->supports($request)) { - $authenticators[$key] = $authenticator; + $authenticators[] = $authenticator; $lazy = $lazy && null === $supports; } elseif (null !== $this->logger) { - $this->logger->debug('Authenticator does not support the request.', ['firewall_key' => $this->providerKey, 'authenticator' => \get_class($authenticator)]); + $this->logger->debug('Authenticator does not support the request.', ['firewall_key' => $this->firewallName, 'authenticator' => \get_class($authenticator)]); } } @@ -105,15 +105,15 @@ public function supports(Request $request): ?bool return false; } - $request->attributes->set('_guard_authenticators', $authenticators); + $request->attributes->set('_security_authenticators', $authenticators); return $lazy ? null : true; } public function authenticateRequest(Request $request): ?Response { - $authenticators = $request->attributes->get('_guard_authenticators'); - $request->attributes->remove('_guard_authenticators'); + $authenticators = $request->attributes->get('_security_authenticators'); + $request->attributes->remove('_security_authenticators'); if (!$authenticators) { return null; } @@ -126,8 +126,8 @@ public function authenticateRequest(Request $request): ?Response */ private function executeAuthenticators(array $authenticators, Request $request): ?Response { - foreach ($authenticators as $key => $authenticator) { - // recheck if the authenticator still supports the listener. support() is called + foreach ($authenticators as $authenticator) { + // recheck if the authenticator still supports the listener. supports() is called // eagerly (before token storage is initialized), whereas authenticate() is called // lazily (after initialization). This is important for e.g. the AnonymousAuthenticator // as its support is relying on the (initialized) token in the TokenStorage. @@ -135,6 +135,7 @@ private function executeAuthenticators(array $authenticators, Request $request): if (null !== $this->logger) { $this->logger->debug('Skipping the "{authenticator}" authenticator as it did not support the request.', ['authenticator' => \get_class($authenticator)]); } + continue; } @@ -165,7 +166,7 @@ private function executeAuthenticator(AuthenticatorInterface $authenticator, Req $passport->checkIfCompletelyResolved(); // create the authenticated token - $authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->providerKey); + $authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->firewallName); if (true === $this->eraseCredentials) { $authenticatedToken->eraseCredentials(); } @@ -204,7 +205,7 @@ private function handleAuthenticationSuccess(TokenInterface $authenticatedToken, { $this->tokenStorage->setToken($authenticatedToken); - $response = $authenticator->onAuthenticationSuccess($request, $authenticatedToken, $this->providerKey); + $response = $authenticator->onAuthenticationSuccess($request, $authenticatedToken, $this->firewallName); if ($authenticator instanceof InteractiveAuthenticatorInterface && $authenticator->isInteractive()) { $loginEvent = new InteractiveLoginEvent($request, $authenticatedToken); $this->eventDispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN); @@ -233,7 +234,7 @@ private function handleAuthenticationFailure(AuthenticationException $authentica $this->logger->debug('The "{authenticator}" authenticator set the failure response.', ['authenticator' => \get_class($authenticator)]); } - $this->eventDispatcher->dispatch($loginFailureEvent = new LoginFailureEvent($authenticationException, $authenticator, $request, $response, $this->providerKey)); + $this->eventDispatcher->dispatch($loginFailureEvent = new LoginFailureEvent($authenticationException, $authenticator, $request, $response, $this->firewallName)); // returning null is ok, it means they want the request to continue return $loginFailureEvent->getResponse(); diff --git a/src/Symfony/Component/Security/Http/Authenticator/AbstractAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/AbstractAuthenticator.php index 51a49a3b1729..6a5ec2f1502e 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/AbstractAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/AbstractAuthenticator.php @@ -32,12 +32,12 @@ abstract class AbstractAuthenticator implements AuthenticatorInterface * * @return PostAuthenticationToken */ - public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface { if (!$passport instanceof UserPassportInterface) { throw new LogicException(sprintf('Passport does not contain a user, overwrite "createAuthenticatedToken()" in "%s" to create a custom authenticated token.', \get_class($this))); } - return new PostAuthenticationToken($passport->getUser(), $providerKey, $passport->getUser()->getRoles()); + return new PostAuthenticationToken($passport->getUser(), $firewallName, $passport->getUser()->getRoles()); } } diff --git a/src/Symfony/Component/Security/Http/Authenticator/AbstractPreAuthenticatedAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/AbstractPreAuthenticatedAuthenticator.php index 435de68e9887..85a578d8c679 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/AbstractPreAuthenticatedAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/AbstractPreAuthenticatedAuthenticator.php @@ -92,12 +92,12 @@ public function authenticate(Request $request): PassportInterface return new SelfValidatingPassport($user, [new PreAuthenticatedUserBadge()]); } - public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface { - return new PreAuthenticatedToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles()); + return new PreAuthenticatedToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles()); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { return null; // let the original request continue } diff --git a/src/Symfony/Component/Security/Http/Authenticator/AnonymousAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/AnonymousAuthenticator.php index 27a315b0f565..c0420b5d4cfe 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/AnonymousAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/AnonymousAuthenticator.php @@ -50,12 +50,12 @@ public function authenticate(Request $request): PassportInterface return new AnonymousPassport(); } - public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface { return new AnonymousToken($this->secret, 'anon.', []); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { return null; // let the original request continue } diff --git a/src/Symfony/Component/Security/Http/Authenticator/AuthenticatorInterface.php b/src/Symfony/Component/Security/Http/Authenticator/AuthenticatorInterface.php index d80356e71340..e1f2b21f70a0 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/AuthenticatorInterface.php +++ b/src/Symfony/Component/Security/Http/Authenticator/AuthenticatorInterface.php @@ -63,7 +63,7 @@ public function authenticate(Request $request): PassportInterface; * * @param PassportInterface $passport The passport returned from authenticate() */ - public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface; + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface; /** * Called when authentication executed and was successful! @@ -74,7 +74,7 @@ public function createAuthenticatedToken(PassportInterface $passport, string $pr * If you return null, the current request will continue, and the user * will be authenticated. This makes sense, for example, with an API. */ - public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response; + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response; /** * Called when authentication executed, but failed (e.g. wrong username password). diff --git a/src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php index 0bbbb6eb8304..31cab7afcd35 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/FormLoginAuthenticator.php @@ -100,12 +100,12 @@ public function authenticate(Request $request): PassportInterface /** * @param Passport $passport */ - public function createAuthenticatedToken(PassportInterface $passport, $providerKey): TokenInterface + public function createAuthenticatedToken(PassportInterface $passport, $firewallName): TokenInterface { - return new UsernamePasswordToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles()); + return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles()); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { return $this->successHandler->onAuthenticationSuccess($request, $token); } diff --git a/src/Symfony/Component/Security/Http/Authenticator/HttpBasicAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/HttpBasicAuthenticator.php index 46eb6aa7bcbf..e4c7af251e8c 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/HttpBasicAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/HttpBasicAuthenticator.php @@ -82,12 +82,12 @@ public function authenticate(Request $request): PassportInterface /** * @param Passport $passport */ - public function createAuthenticatedToken(PassportInterface $passport, $providerKey): TokenInterface + public function createAuthenticatedToken(PassportInterface $passport, $firewallName): TokenInterface { - return new UsernamePasswordToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles()); + return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles()); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, $firewallName): ?Response { return null; } diff --git a/src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php index 924ed7fcca34..d165fbceb191 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/JsonLoginAuthenticator.php @@ -93,12 +93,12 @@ public function authenticate(Request $request): PassportInterface return $passport; } - public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface { - return new UsernamePasswordToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles()); + return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles()); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { if (null === $this->successHandler) { return null; // let the original request continue diff --git a/src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php b/src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php index 12a70d42b403..f5aa016ad15d 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php +++ b/src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php @@ -76,12 +76,12 @@ public function authenticate(Request $request): PassportInterface return new SelfValidatingPassport($token->getUser()); } - public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface { - return new RememberMeToken($passport->getUser(), $providerKey, $this->secret); + return new RememberMeToken($passport->getUser(), $firewallName, $this->secret); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response { return null; // let the original request continue } diff --git a/src/Symfony/Component/Security/Http/Authenticator/Token/PostAuthenticationToken.php b/src/Symfony/Component/Security/Http/Authenticator/Token/PostAuthenticationToken.php index 3525fa4765b9..774ba60a8603 100644 --- a/src/Symfony/Component/Security/Http/Authenticator/Token/PostAuthenticationToken.php +++ b/src/Symfony/Component/Security/Http/Authenticator/Token/PostAuthenticationToken.php @@ -7,24 +7,23 @@ class PostAuthenticationToken extends AbstractToken { - private $providerKey; + private $firewallName; /** - * @param string $providerKey The provider (firewall) key - * @param string[] $roles An array of roles + * @param string[] $roles An array of roles * * @throws \InvalidArgumentException */ - public function __construct(UserInterface $user, string $providerKey, array $roles) + public function __construct(UserInterface $user, string $firewallName, array $roles) { parent::__construct($roles); - if (empty($providerKey)) { - throw new \InvalidArgumentException('$providerKey (i.e. firewall key) must not be empty.'); + if (empty($firewallName)) { + throw new \InvalidArgumentException('$firewallName must not be empty.'); } $this->setUser($user); - $this->providerKey = $providerKey; + $this->firewallName = $firewallName; // this token is meant to be used after authentication success, so it is always authenticated // you could set it as non authenticated later if you need to @@ -42,14 +41,9 @@ public function getCredentials() return []; } - /** - * Returns the provider (firewall) key. - * - * @return string - */ - public function getProviderKey() + public function getFirewallName(): string { - return $this->providerKey; + return $this->firewallName; } /** @@ -57,7 +51,7 @@ public function getProviderKey() */ public function __serialize(): array { - return [$this->providerKey, parent::__serialize()]; + return [$this->firewallName, parent::__serialize()]; } /** @@ -65,7 +59,7 @@ public function __serialize(): array */ public function __unserialize(array $data): void { - [$this->providerKey, $parentData] = $data; + [$this->firewallName, $parentData] = $data; parent::__unserialize($parentData); } } diff --git a/src/Symfony/Component/Security/Http/Event/LoginFailureEvent.php b/src/Symfony/Component/Security/Http/Event/LoginFailureEvent.php index 03a1c7a78c6a..96da4e35ff73 100644 --- a/src/Symfony/Component/Security/Http/Event/LoginFailureEvent.php +++ b/src/Symfony/Component/Security/Http/Event/LoginFailureEvent.php @@ -22,15 +22,15 @@ class LoginFailureEvent extends Event private $authenticator; private $request; private $response; - private $providerKey; + private $firewallName; - public function __construct(AuthenticationException $exception, AuthenticatorInterface $authenticator, Request $request, ?Response $response, string $providerKey) + public function __construct(AuthenticationException $exception, AuthenticatorInterface $authenticator, Request $request, ?Response $response, string $firewallName) { $this->exception = $exception; $this->authenticator = $authenticator; $this->request = $request; $this->response = $response; - $this->providerKey = $providerKey; + $this->firewallName = $firewallName; } public function getException(): AuthenticationException @@ -43,9 +43,9 @@ public function getAuthenticator(): AuthenticatorInterface return $this->authenticator; } - public function getProviderKey(): string + public function getFirewallName(): string { - return $this->providerKey; + return $this->firewallName; } public function getRequest(): Request diff --git a/src/Symfony/Component/Security/Http/Event/LoginSuccessEvent.php b/src/Symfony/Component/Security/Http/Event/LoginSuccessEvent.php index 80f740480b1c..c7eee3a66e74 100644 --- a/src/Symfony/Component/Security/Http/Event/LoginSuccessEvent.php +++ b/src/Symfony/Component/Security/Http/Event/LoginSuccessEvent.php @@ -31,14 +31,14 @@ class LoginSuccessEvent extends Event private $response; private $providerKey; - public function __construct(AuthenticatorInterface $authenticator, PassportInterface $passport, TokenInterface $authenticatedToken, Request $request, ?Response $response, string $providerKey) + public function __construct(AuthenticatorInterface $authenticator, PassportInterface $passport, TokenInterface $authenticatedToken, Request $request, ?Response $response, string $firewallName) { $this->authenticator = $authenticator; $this->passport = $passport; $this->authenticatedToken = $authenticatedToken; $this->request = $request; $this->response = $response; - $this->providerKey = $providerKey; + $this->providerKey = $firewallName; } public function getAuthenticator(): AuthenticatorInterface @@ -70,7 +70,7 @@ public function getRequest(): Request return $this->request; } - public function getProviderKey(): string + public function getFirewallName(): string { return $this->providerKey; } diff --git a/src/Symfony/Component/Security/Http/Tests/Authentication/AuthenticatorManagerTest.php b/src/Symfony/Component/Security/Http/Tests/Authentication/AuthenticatorManagerTest.php index 2cf7994db7ea..2b21b380d376 100644 --- a/src/Symfony/Component/Security/Http/Tests/Authentication/AuthenticatorManagerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Authentication/AuthenticatorManagerTest.php @@ -73,7 +73,7 @@ public function testSupportCheckedUponRequestAuthentication() // means support changed between calling supports() and authenticateRequest() // (which is the case with lazy firewalls and e.g. the AnonymousAuthenticator) $authenticator = $this->createAuthenticator(false); - $this->request->attributes->set('_guard_authenticators', [$authenticator]); + $this->request->attributes->set('_security_authenticators', [$authenticator]); $authenticator->expects($this->never())->method('authenticate'); @@ -87,7 +87,7 @@ public function testSupportCheckedUponRequestAuthentication() public function testAuthenticateRequest($matchingAuthenticatorIndex) { $authenticators = [$this->createAuthenticator(0 === $matchingAuthenticatorIndex), $this->createAuthenticator(1 === $matchingAuthenticatorIndex)]; - $this->request->attributes->set('_guard_authenticators', $authenticators); + $this->request->attributes->set('_security_authenticators', $authenticators); $matchingAuthenticator = $authenticators[$matchingAuthenticatorIndex]; $authenticators[($matchingAuthenticatorIndex + 1) % 2]->expects($this->never())->method('authenticate'); @@ -118,7 +118,7 @@ public function provideMatchingAuthenticatorIndex() public function testNoCredentialsValidated() { $authenticator = $this->createAuthenticator(); - $this->request->attributes->set('_guard_authenticators', [$authenticator]); + $this->request->attributes->set('_security_authenticators', [$authenticator]); $authenticator->expects($this->any())->method('authenticate')->willReturn(new Passport($this->user, new PasswordCredentials('pass'))); @@ -136,7 +136,7 @@ public function testNoCredentialsValidated() public function testEraseCredentials($eraseCredentials) { $authenticator = $this->createAuthenticator(); - $this->request->attributes->set('_guard_authenticators', [$authenticator]); + $this->request->attributes->set('_security_authenticators', [$authenticator]); $authenticator->expects($this->any())->method('authenticate')->willReturn(new SelfValidatingPassport($this->user)); @@ -170,7 +170,7 @@ public function testInteractiveAuthenticator() { $authenticator = $this->createMock(InteractiveAuthenticatorInterface::class); $authenticator->expects($this->any())->method('isInteractive')->willReturn(true); - $this->request->attributes->set('_guard_authenticators', [$authenticator]); + $this->request->attributes->set('_security_authenticators', [$authenticator]); $authenticator->expects($this->any())->method('authenticate')->willReturn(new SelfValidatingPassport($this->user)); $authenticator->expects($this->any())->method('createAuthenticatedToken')->willReturn($this->token);