Rename providerKey to firewallName for more consistent naming

This commit is contained in:
Wouter de Jong 2020-04-10 23:45:43 +02:00
parent 50224aa285
commit b1e040f311
23 changed files with 95 additions and 100 deletions

View File

@ -42,13 +42,13 @@ class AnonymousFactory implements SecurityFactoryInterface, AuthenticatorFactory
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']);

View File

@ -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);
}

View File

@ -49,7 +49,7 @@ class CustomAuthenticatorFactory implements AuthenticatorFactoryInterface, Secur
;
}
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'];
}

View File

@ -103,19 +103,19 @@ class FormLoginFactory extends AbstractFactory implements AuthenticatorFactoryIn
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;

View File

@ -46,9 +46,9 @@ class HttpBasicFactory implements SecurityFactoryInterface, AuthenticatorFactory
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'])

View File

@ -97,15 +97,15 @@ class JsonLoginFactory extends AbstractFactory implements AuthenticatorFactoryIn
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;

View File

@ -89,19 +89,19 @@ class RememberMeFactory implements SecurityFactoryInterface, AuthenticatorFactor
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))

View File

@ -43,9 +43,9 @@ class RemoteUserFactory implements SecurityFactoryInterface, AuthenticatorFactor
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))

View File

@ -44,9 +44,9 @@ class X509Factory implements SecurityFactoryInterface, AuthenticatorFactoryInter
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))

View File

@ -286,7 +286,7 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
// 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 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
$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 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
$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 @@ class SecurityExtension extends Extension implements PrependExtensionInterface
list($provider, $listenerId, $defaultEntryPoint) = $factory->create($container, $id, $firewall[$key], $userProvider, $defaultEntryPoint);
$listeners[] = new Reference($listenerId);
$authenticationProviders[$id.'_'.$key] = $provider;
$authenticationProviders[] = $provider;
}
$hasListeners = true;
}

View File

@ -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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
*/
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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
$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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
{
$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 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
$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();

View File

@ -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());
}
}

View File

@ -92,12 +92,12 @@ abstract class AbstractPreAuthenticatedAuthenticator implements InteractiveAuthe
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
}

View File

@ -50,12 +50,12 @@ class AnonymousAuthenticator implements AuthenticatorInterface
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
}

View File

@ -63,7 +63,7 @@ interface AuthenticatorInterface
*
* @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 @@ interface AuthenticatorInterface
* 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).

View File

@ -100,12 +100,12 @@ class FormLoginAuthenticator extends AbstractLoginFormAuthenticator
/**
* @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);
}

View File

@ -82,12 +82,12 @@ class HttpBasicAuthenticator implements AuthenticatorInterface, AuthenticationEn
/**
* @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;
}

View File

@ -93,12 +93,12 @@ class JsonLoginAuthenticator implements InteractiveAuthenticatorInterface
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

View File

@ -76,12 +76,12 @@ class RememberMeAuthenticator implements InteractiveAuthenticatorInterface
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
}

View File

@ -7,24 +7,23 @@ use Symfony\Component\Security\Core\User\UserInterface;
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 @@ class PostAuthenticationToken extends AbstractToken
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 @@ class PostAuthenticationToken extends AbstractToken
*/
public function __serialize(): array
{
return [$this->providerKey, parent::__serialize()];
return [$this->firewallName, parent::__serialize()];
}
/**
@ -65,7 +59,7 @@ class PostAuthenticationToken extends AbstractToken
*/
public function __unserialize(array $data): void
{
[$this->providerKey, $parentData] = $data;
[$this->firewallName, $parentData] = $data;
parent::__unserialize($parentData);
}
}

View File

@ -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 @@ class LoginFailureEvent extends Event
return $this->authenticator;
}
public function getProviderKey(): string
public function getFirewallName(): string
{
return $this->providerKey;
return $this->firewallName;
}
public function getRequest(): Request

View File

@ -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 @@ class LoginSuccessEvent extends Event
return $this->request;
}
public function getProviderKey(): string
public function getFirewallName(): string
{
return $this->providerKey;
}

View File

@ -73,7 +73,7 @@ class AuthenticatorManagerTest extends TestCase
// 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 @@ class AuthenticatorManagerTest extends TestCase
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 @@ class AuthenticatorManagerTest extends TestCase
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 @@ class AuthenticatorManagerTest extends TestCase
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 @@ class AuthenticatorManagerTest extends TestCase
{
$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);