Skip to content

Commit 9a34d06

Browse files
committed
Rename providerKey to firewallName for more consistent naming
1 parent 471c470 commit 9a34d06

13 files changed

+64
-69
lines changed

Authentication/AuthenticatorManager.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthent
4747
private $eventDispatcher;
4848
private $eraseCredentials;
4949
private $logger;
50-
private $providerKey;
50+
private $firewallName;
5151

5252
/**
53-
* @param AuthenticatorInterface[] $authenticators The authenticators, with their unique providerKey as key
53+
* @param AuthenticatorInterface[] $authenticators
5454
*/
55-
public function __construct(iterable $authenticators, TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher, string $providerKey, ?LoggerInterface $logger = null, bool $eraseCredentials = true)
55+
public function __construct(iterable $authenticators, TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher, string $firewallName, ?LoggerInterface $logger = null, bool $eraseCredentials = true)
5656
{
5757
$this->authenticators = $authenticators;
5858
$this->tokenStorage = $tokenStorage;
5959
$this->eventDispatcher = $eventDispatcher;
60-
$this->providerKey = $providerKey;
60+
$this->firewallName = $firewallName;
6161
$this->logger = $logger;
6262
$this->eraseCredentials = $eraseCredentials;
6363
}
@@ -68,7 +68,7 @@ public function __construct(iterable $authenticators, TokenStorageInterface $tok
6868
public function authenticateUser(UserInterface $user, AuthenticatorInterface $authenticator, Request $request, array $badges = []): ?Response
6969
{
7070
// create an authenticated token for the User
71-
$token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport($user, $badges), $this->providerKey);
71+
$token = $authenticator->createAuthenticatedToken($passport = new SelfValidatingPassport($user, $badges), $this->firewallName);
7272

7373
// authenticate this in the system
7474
return $this->handleAuthenticationSuccess($token, $passport, $request, $authenticator);
@@ -77,43 +77,43 @@ public function authenticateUser(UserInterface $user, AuthenticatorInterface $au
7777
public function supports(Request $request): ?bool
7878
{
7979
if (null !== $this->logger) {
80-
$context = ['firewall_key' => $this->providerKey];
80+
$context = ['firewall_key' => $this->firewallName];
8181

8282
if ($this->authenticators instanceof \Countable || \is_array($this->authenticators)) {
8383
$context['authenticators'] = \count($this->authenticators);
8484
}
8585

86-
$this->logger->debug('Checking for guard authentication credentials.', $context);
86+
$this->logger->debug('Checking for authenticator support.', $context);
8787
}
8888

8989
$authenticators = [];
9090
$lazy = true;
91-
foreach ($this->authenticators as $key => $authenticator) {
91+
foreach ($this->authenticators as $authenticator) {
9292
if (null !== $this->logger) {
93-
$this->logger->debug('Checking support on authenticator.', ['firewall_key' => $this->providerKey, 'authenticator' => \get_class($authenticator)]);
93+
$this->logger->debug('Checking support on authenticator.', ['firewall_key' => $this->firewallName, 'authenticator' => \get_class($authenticator)]);
9494
}
9595

9696
if (false !== $supports = $authenticator->supports($request)) {
97-
$authenticators[$key] = $authenticator;
97+
$authenticators[] = $authenticator;
9898
$lazy = $lazy && null === $supports;
9999
} elseif (null !== $this->logger) {
100-
$this->logger->debug('Authenticator does not support the request.', ['firewall_key' => $this->providerKey, 'authenticator' => \get_class($authenticator)]);
100+
$this->logger->debug('Authenticator does not support the request.', ['firewall_key' => $this->firewallName, 'authenticator' => \get_class($authenticator)]);
101101
}
102102
}
103103

104104
if (!$authenticators) {
105105
return false;
106106
}
107107

108-
$request->attributes->set('_guard_authenticators', $authenticators);
108+
$request->attributes->set('_security_authenticators', $authenticators);
109109

110110
return $lazy ? null : true;
111111
}
112112

113113
public function authenticateRequest(Request $request): ?Response
114114
{
115-
$authenticators = $request->attributes->get('_guard_authenticators');
116-
$request->attributes->remove('_guard_authenticators');
115+
$authenticators = $request->attributes->get('_security_authenticators');
116+
$request->attributes->remove('_security_authenticators');
117117
if (!$authenticators) {
118118
return null;
119119
}
@@ -126,15 +126,16 @@ public function authenticateRequest(Request $request): ?Response
126126
*/
127127
private function executeAuthenticators(array $authenticators, Request $request): ?Response
128128
{
129-
foreach ($authenticators as $key => $authenticator) {
130-
// recheck if the authenticator still supports the listener. support() is called
129+
foreach ($authenticators as $authenticator) {
130+
// recheck if the authenticator still supports the listener. supports() is called
131131
// eagerly (before token storage is initialized), whereas authenticate() is called
132132
// lazily (after initialization). This is important for e.g. the AnonymousAuthenticator
133133
// as its support is relying on the (initialized) token in the TokenStorage.
134134
if (false === $authenticator->supports($request)) {
135135
if (null !== $this->logger) {
136136
$this->logger->debug('Skipping the "{authenticator}" authenticator as it did not support the request.', ['authenticator' => \get_class($authenticator)]);
137137
}
138+
138139
continue;
139140
}
140141

@@ -165,7 +166,7 @@ private function executeAuthenticator(AuthenticatorInterface $authenticator, Req
165166
$passport->checkIfCompletelyResolved();
166167

167168
// create the authenticated token
168-
$authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->providerKey);
169+
$authenticatedToken = $authenticator->createAuthenticatedToken($passport, $this->firewallName);
169170
if (true === $this->eraseCredentials) {
170171
$authenticatedToken->eraseCredentials();
171172
}
@@ -204,7 +205,7 @@ private function handleAuthenticationSuccess(TokenInterface $authenticatedToken,
204205
{
205206
$this->tokenStorage->setToken($authenticatedToken);
206207

207-
$response = $authenticator->onAuthenticationSuccess($request, $authenticatedToken, $this->providerKey);
208+
$response = $authenticator->onAuthenticationSuccess($request, $authenticatedToken, $this->firewallName);
208209
if ($authenticator instanceof InteractiveAuthenticatorInterface && $authenticator->isInteractive()) {
209210
$loginEvent = new InteractiveLoginEvent($request, $authenticatedToken);
210211
$this->eventDispatcher->dispatch($loginEvent, SecurityEvents::INTERACTIVE_LOGIN);
@@ -233,7 +234,7 @@ private function handleAuthenticationFailure(AuthenticationException $authentica
233234
$this->logger->debug('The "{authenticator}" authenticator set the failure response.', ['authenticator' => \get_class($authenticator)]);
234235
}
235236

236-
$this->eventDispatcher->dispatch($loginFailureEvent = new LoginFailureEvent($authenticationException, $authenticator, $request, $response, $this->providerKey));
237+
$this->eventDispatcher->dispatch($loginFailureEvent = new LoginFailureEvent($authenticationException, $authenticator, $request, $response, $this->firewallName));
237238

238239
// returning null is ok, it means they want the request to continue
239240
return $loginFailureEvent->getResponse();

Authenticator/AbstractAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ abstract class AbstractAuthenticator implements AuthenticatorInterface
3232
*
3333
* @return PostAuthenticationToken
3434
*/
35-
public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface
35+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
3636
{
3737
if (!$passport instanceof UserPassportInterface) {
3838
throw new LogicException(sprintf('Passport does not contain a user, overwrite "createAuthenticatedToken()" in "%s" to create a custom authenticated token.', \get_class($this)));
3939
}
4040

41-
return new PostAuthenticationToken($passport->getUser(), $providerKey, $passport->getUser()->getRoles());
41+
return new PostAuthenticationToken($passport->getUser(), $firewallName, $passport->getUser()->getRoles());
4242
}
4343
}

Authenticator/AbstractPreAuthenticatedAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ public function authenticate(Request $request): PassportInterface
9292
return new SelfValidatingPassport($user, [new PreAuthenticatedUserBadge()]);
9393
}
9494

95-
public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface
95+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
9696
{
97-
return new PreAuthenticatedToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles());
97+
return new PreAuthenticatedToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
9898
}
9999

100-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response
100+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
101101
{
102102
return null; // let the original request continue
103103
}

Authenticator/AnonymousAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public function authenticate(Request $request): PassportInterface
5050
return new AnonymousPassport();
5151
}
5252

53-
public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface
53+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
5454
{
5555
return new AnonymousToken($this->secret, 'anon.', []);
5656
}
5757

58-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response
58+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
5959
{
6060
return null; // let the original request continue
6161
}

Authenticator/AuthenticatorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function authenticate(Request $request): PassportInterface;
6363
*
6464
* @param PassportInterface $passport The passport returned from authenticate()
6565
*/
66-
public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface;
66+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface;
6767

6868
/**
6969
* Called when authentication executed and was successful!
@@ -74,7 +74,7 @@ public function createAuthenticatedToken(PassportInterface $passport, string $pr
7474
* If you return null, the current request will continue, and the user
7575
* will be authenticated. This makes sense, for example, with an API.
7676
*/
77-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response;
77+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response;
7878

7979
/**
8080
* Called when authentication executed, but failed (e.g. wrong username password).

Authenticator/FormLoginAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ public function authenticate(Request $request): PassportInterface
100100
/**
101101
* @param Passport $passport
102102
*/
103-
public function createAuthenticatedToken(PassportInterface $passport, $providerKey): TokenInterface
103+
public function createAuthenticatedToken(PassportInterface $passport, $firewallName): TokenInterface
104104
{
105-
return new UsernamePasswordToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles());
105+
return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
106106
}
107107

108-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response
108+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
109109
{
110110
return $this->successHandler->onAuthenticationSuccess($request, $token);
111111
}

Authenticator/HttpBasicAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public function authenticate(Request $request): PassportInterface
8282
/**
8383
* @param Passport $passport
8484
*/
85-
public function createAuthenticatedToken(PassportInterface $passport, $providerKey): TokenInterface
85+
public function createAuthenticatedToken(PassportInterface $passport, $firewallName): TokenInterface
8686
{
87-
return new UsernamePasswordToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles());
87+
return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
8888
}
8989

90-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response
90+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $firewallName): ?Response
9191
{
9292
return null;
9393
}

Authenticator/JsonLoginAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ public function authenticate(Request $request): PassportInterface
9393
return $passport;
9494
}
9595

96-
public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface
96+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
9797
{
98-
return new UsernamePasswordToken($passport->getUser(), null, $providerKey, $passport->getUser()->getRoles());
98+
return new UsernamePasswordToken($passport->getUser(), null, $firewallName, $passport->getUser()->getRoles());
9999
}
100100

101-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response
101+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
102102
{
103103
if (null === $this->successHandler) {
104104
return null; // let the original request continue

Authenticator/RememberMeAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public function authenticate(Request $request): PassportInterface
7676
return new SelfValidatingPassport($token->getUser());
7777
}
7878

79-
public function createAuthenticatedToken(PassportInterface $passport, string $providerKey): TokenInterface
79+
public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface
8080
{
81-
return new RememberMeToken($passport->getUser(), $providerKey, $this->secret);
81+
return new RememberMeToken($passport->getUser(), $firewallName, $this->secret);
8282
}
8383

84-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $providerKey): ?Response
84+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
8585
{
8686
return null; // let the original request continue
8787
}

Authenticator/Token/PostAuthenticationToken.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,23 @@
77

88
class PostAuthenticationToken extends AbstractToken
99
{
10-
private $providerKey;
10+
private $firewallName;
1111

1212
/**
13-
* @param string $providerKey The provider (firewall) key
14-
* @param string[] $roles An array of roles
13+
* @param string[] $roles An array of roles
1514
*
1615
* @throws \InvalidArgumentException
1716
*/
18-
public function __construct(UserInterface $user, string $providerKey, array $roles)
17+
public function __construct(UserInterface $user, string $firewallName, array $roles)
1918
{
2019
parent::__construct($roles);
2120

22-
if (empty($providerKey)) {
23-
throw new \InvalidArgumentException('$providerKey (i.e. firewall key) must not be empty.');
21+
if (empty($firewallName)) {
22+
throw new \InvalidArgumentException('$firewallName must not be empty.');
2423
}
2524

2625
$this->setUser($user);
27-
$this->providerKey = $providerKey;
26+
$this->firewallName = $firewallName;
2827

2928
// this token is meant to be used after authentication success, so it is always authenticated
3029
// you could set it as non authenticated later if you need to
@@ -42,30 +41,25 @@ public function getCredentials()
4241
return [];
4342
}
4443

45-
/**
46-
* Returns the provider (firewall) key.
47-
*
48-
* @return string
49-
*/
50-
public function getProviderKey()
44+
public function getFirewallName(): string
5145
{
52-
return $this->providerKey;
46+
return $this->firewallName;
5347
}
5448

5549
/**
5650
* {@inheritdoc}
5751
*/
5852
public function __serialize(): array
5953
{
60-
return [$this->providerKey, parent::__serialize()];
54+
return [$this->firewallName, parent::__serialize()];
6155
}
6256

6357
/**
6458
* {@inheritdoc}
6559
*/
6660
public function __unserialize(array $data): void
6761
{
68-
[$this->providerKey, $parentData] = $data;
62+
[$this->firewallName, $parentData] = $data;
6963
parent::__unserialize($parentData);
7064
}
7165
}

0 commit comments

Comments
 (0)