Skip to content

Commit 0898969

Browse files
committed
Removed all mentions of 'guard' in the new system
This to remove confusion between the new system and Guard. When using the new system, guard should not be installed. Guard did however influence the idea behind the new system. Thus keeping the mentions of "guard" makes it confusing to use the new system.
1 parent 13e4aad commit 0898969

24 files changed

+359
-200
lines changed

Authentication/GuardAuthenticatorHandler.php renamed to Authentication/AuthenticatorHandler.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
16-
use Symfony\Component\Security\Http\Authentication\Authenticator\AuthenticatorInterface;
16+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1818
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1919
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -25,7 +25,7 @@
2525
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2626

2727
/**
28-
* A utility class that does much of the *work* during the guard authentication process.
28+
* A utility class that does much of the *work* during the authentication process.
2929
*
3030
* By having the logic here instead of the listener, more of the process
3131
* can be called directly (e.g. for manual authentication) or overridden.
@@ -34,7 +34,7 @@
3434
*
3535
* @internal
3636
*/
37-
class GuardAuthenticatorHandler
37+
class AuthenticatorHandler
3838
{
3939
private $tokenStorage;
4040
private $dispatcher;
@@ -66,24 +66,24 @@ public function authenticateWithToken(TokenInterface $token, Request $request, s
6666
}
6767

6868
/**
69-
* Returns the "on success" response for the given GuardAuthenticator.
69+
* Returns the "on success" response for the given Authenticator.
7070
*
71-
* @param AuthenticatorInterface|GuardAuthenticatorInterface $guardAuthenticator
71+
* @param AuthenticatorInterface|GuardAuthenticatorInterface $authenticator
7272
*/
73-
public function handleAuthenticationSuccess(TokenInterface $token, Request $request, $guardAuthenticator, string $providerKey): ?Response
73+
public function handleAuthenticationSuccess(TokenInterface $token, Request $request, $authenticator, string $providerKey): ?Response
7474
{
75-
if (!$guardAuthenticator instanceof AuthenticatorInterface && !$guardAuthenticator instanceof GuardAuthenticatorInterface) {
76-
throw new \UnexpectedValueException('Invalid guard authenticator passed to '.__METHOD__.'. Expected AuthenticatorInterface of either Security Core or Security Guard.');
75+
if (!$authenticator instanceof AuthenticatorInterface && !$authenticator instanceof GuardAuthenticatorInterface) {
76+
throw new \UnexpectedValueException('Invalid authenticator passed to '.__METHOD__.'. Expected AuthenticatorInterface of either Security Core or Security Guard.');
7777
}
7878

79-
$response = $guardAuthenticator->onAuthenticationSuccess($request, $token, $providerKey);
79+
$response = $authenticator->onAuthenticationSuccess($request, $token, $providerKey);
8080

8181
// check that it's a Response or null
8282
if ($response instanceof Response || null === $response) {
8383
return $response;
8484
}
8585

86-
throw new \UnexpectedValueException(sprintf('The "%s::onAuthenticationSuccess()" method must return null or a Response object. You returned "%s".', \get_class($guardAuthenticator), get_debug_type($response)));
86+
throw new \UnexpectedValueException(sprintf('The "%s::onAuthenticationSuccess()" method must return null or a Response object. You returned "%s".', \get_class($authenticator), \is_object($response) ? \get_class($response) : \gettype($response)));
8787
}
8888

8989
/**
@@ -95,7 +95,7 @@ public function handleAuthenticationSuccess(TokenInterface $token, Request $requ
9595
public function authenticateUserAndHandleSuccess(UserInterface $user, Request $request, $authenticator, string $providerKey): ?Response
9696
{
9797
if (!$authenticator instanceof AuthenticatorInterface && !$authenticator instanceof GuardAuthenticatorInterface) {
98-
throw new \UnexpectedValueException('Invalid guard authenticator passed to '.__METHOD__.'. Expected AuthenticatorInterface of either Security Core or Security Guard.');
98+
throw new \UnexpectedValueException('Invalid authenticator passed to '.__METHOD__.'. Expected AuthenticatorInterface of either Security Core or Security Guard.');
9999
}
100100

101101
// create an authenticated token for the User
@@ -111,21 +111,21 @@ public function authenticateUserAndHandleSuccess(UserInterface $user, Request $r
111111
* Handles an authentication failure and returns the Response for the
112112
* GuardAuthenticator.
113113
*
114-
* @param AuthenticatorInterface|GuardAuthenticatorInterface $guardAuthenticator
114+
* @param AuthenticatorInterface|GuardAuthenticatorInterface $authenticator
115115
*/
116-
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, $guardAuthenticator, string $providerKey): ?Response
116+
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, $authenticator, string $providerKey): ?Response
117117
{
118-
if (!$guardAuthenticator instanceof AuthenticatorInterface && !$guardAuthenticator instanceof GuardAuthenticatorInterface) {
119-
throw new \UnexpectedValueException('Invalid guard authenticator passed to '.__METHOD__.'. Expected AuthenticatorInterface of either Security Core or Security Guard.');
118+
if (!$authenticator instanceof AuthenticatorInterface && !$authenticator instanceof GuardAuthenticatorInterface) {
119+
throw new \UnexpectedValueException('Invalid authenticator passed to '.__METHOD__.'. Expected AuthenticatorInterface of either Security Core or Security Guard.');
120120
}
121121

122-
$response = $guardAuthenticator->onAuthenticationFailure($request, $authenticationException);
122+
$response = $authenticator->onAuthenticationFailure($request, $authenticationException);
123123
if ($response instanceof Response || null === $response) {
124124
// returning null is ok, it means they want the request to continue
125125
return $response;
126126
}
127127

128-
throw new \UnexpectedValueException(sprintf('The "%s::onAuthenticationFailure()" method must return null or a Response object. You returned "%s".', \get_class($guardAuthenticator), get_debug_type($response)));
128+
throw new \UnexpectedValueException(sprintf('The "%s::onAuthenticationFailure()" method must return null or a Response object. You returned "%s".', \get_class($authenticator), get_debug_type($response)));
129129
}
130130

131131
/**

Authentication/GuardAuthenticationManager.php renamed to Authentication/AuthenticatorManager.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1616
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1717
use Symfony\Component\Security\Core\User\UserInterface;
18-
use Symfony\Component\Security\Http\Authentication\Authenticator\AuthenticatorInterface;
19-
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticationGuardToken;
18+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
19+
use Symfony\Component\Security\Http\Authenticator\Token\PreAuthenticationToken;
2020
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2121
use Symfony\Component\Security\Core\AuthenticationEvents;
2222
use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
@@ -33,20 +33,20 @@
3333
*
3434
* @experimental in 5.1
3535
*/
36-
class GuardAuthenticationManager implements AuthenticationManagerInterface
36+
class AuthenticatorManager implements AuthenticationManagerInterface
3737
{
38-
use GuardAuthenticationManagerTrait;
38+
use AuthenticatorManagerTrait;
3939

40-
private $guardAuthenticators;
40+
private $authenticators;
4141
private $eventDispatcher;
4242
private $eraseCredentials;
4343

4444
/**
45-
* @param iterable|AuthenticatorInterface[] $guardAuthenticators The authenticators, with keys that match what's passed to GuardAuthenticationListener
45+
* @param AuthenticatorInterface[] $authenticators The authenticators, with keys that match what's passed to AuthenticatorManagerListener
4646
*/
47-
public function __construct(iterable $guardAuthenticators, EventDispatcherInterface $eventDispatcher, bool $eraseCredentials = true)
47+
public function __construct(iterable $authenticators, EventDispatcherInterface $eventDispatcher, bool $eraseCredentials = true)
4848
{
49-
$this->guardAuthenticators = $guardAuthenticators;
49+
$this->authenticators = $authenticators;
5050
$this->eventDispatcher = $eventDispatcher;
5151
$this->eraseCredentials = $eraseCredentials;
5252
}
@@ -58,10 +58,10 @@ public function setEventDispatcher(EventDispatcherInterface $dispatcher)
5858

5959
public function authenticate(TokenInterface $token)
6060
{
61-
if (!$token instanceof PreAuthenticationGuardToken) {
61+
if (!$token instanceof PreAuthenticationToken) {
6262
/*
63-
* The listener *only* passes PreAuthenticationGuardToken instances.
64-
* This means that an authenticated token (e.g. PostAuthenticationGuardToken)
63+
* The listener *only* passes PreAuthenticationToken instances.
64+
* This means that an authenticated token (e.g. PostAuthenticationToken)
6565
* is being passed here, which happens if that token becomes
6666
* "not authenticated" (e.g. happens if the user changes between
6767
* requests). In this case, the user should be logged out.
@@ -77,13 +77,13 @@ public function authenticate(TokenInterface $token)
7777
throw new AuthenticationExpiredException();
7878
}
7979

80-
$guard = $this->findOriginatingAuthenticator($token);
81-
if (null === $guard) {
82-
$this->handleFailure(new ProviderNotFoundException(sprintf('Token with provider key "%s" did not originate from any of the guard authenticators.', $token->getGuardProviderKey())), $token);
80+
$authenticator = $this->findOriginatingAuthenticator($token);
81+
if (null === $authenticator) {
82+
$this->handleFailure(new ProviderNotFoundException(sprintf('Token with provider key "%s" did not originate from any of the authenticators.', $token->getAuthenticatorKey())), $token);
8383
}
8484

8585
try {
86-
$result = $this->authenticateViaGuard($guard, $token, $token->getProviderKey());
86+
$result = $this->authenticateViaAuthenticator($authenticator, $token, $token->getProviderKey());
8787
} catch (AuthenticationException $exception) {
8888
$this->handleFailure($exception, $token);
8989
}
@@ -101,14 +101,14 @@ public function authenticate(TokenInterface $token)
101101
return $result;
102102
}
103103

104-
protected function getGuardKey(string $key): string
104+
protected function getAuthenticatorKey(string $key): string
105105
{
106-
// Guard authenticators in the GuardAuthenticationManager are already indexed
106+
// Authenticators in the AuthenticatorManager are already indexed
107107
// by an unique key
108108
return $key;
109109
}
110110

111-
private function authenticateViaGuard(AuthenticatorInterface $authenticator, PreAuthenticationGuardToken $token, string $providerKey): TokenInterface
111+
private function authenticateViaAuthenticator(AuthenticatorInterface $authenticator, PreAuthenticationToken $token, string $providerKey): TokenInterface
112112
{
113113
// get the user from the Authenticator
114114
$user = $authenticator->getUser($token->getCredentials());
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Authentication;
13+
14+
use Symfony\Component\Security\Guard\AuthenticatorInterface as GuardAuthenticatorInterface;
15+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface as CoreAuthenticatorInterface;
16+
use Symfony\Component\Security\Http\Authenticator\Token\PreAuthenticationToken;
17+
18+
/**
19+
* @author Ryan Weaver <ryan@knpuniversity.com>
20+
*
21+
* @internal
22+
*/
23+
trait AuthenticatorManagerTrait
24+
{
25+
/**
26+
* @return CoreAuthenticatorInterface|GuardAuthenticatorInterface|null
27+
*/
28+
private function findOriginatingAuthenticator(PreAuthenticationToken $token)
29+
{
30+
// find the *one* Authenticator that this token originated from
31+
foreach ($this->authenticators as $key => $authenticator) {
32+
// get a key that's unique to *this* authenticator
33+
// this MUST be the same as AuthenticatorManagerListener
34+
$uniqueAuthenticatorKey = $this->getAuthenticatorKey($key);
35+
36+
if ($uniqueAuthenticatorKey === $token->getAuthenticatorKey()) {
37+
return $authenticator;
38+
}
39+
}
40+
41+
// no matching authenticator found
42+
return null;
43+
}
44+
45+
abstract protected function getAuthenticatorKey(string $key): string;
46+
}

Authentication/GuardAuthenticationManagerTrait.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

Authentication/Authenticator/AbstractAuthenticator.php renamed to Authenticator/AbstractAuthenticator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Security\Http\Authentication\Authenticator;
12+
namespace Symfony\Component\Security\Http\Authenticator;
1313

1414
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1515
use Symfony\Component\Security\Core\User\UserInterface;
16-
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
16+
use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;
1717

1818
/**
1919
* An optional base class that creates the necessary tokens for you.
@@ -25,13 +25,13 @@
2525
abstract class AbstractAuthenticator implements AuthenticatorInterface
2626
{
2727
/**
28-
* Shortcut to create a PostAuthenticationGuardToken for you, if you don't really
28+
* Shortcut to create a PostAuthenticationToken for you, if you don't really
2929
* care about which authenticated token you're using.
3030
*
31-
* @return PostAuthenticationGuardToken
31+
* @return PostAuthenticationToken
3232
*/
3333
public function createAuthenticatedToken(UserInterface $user, string $providerKey): TokenInterface
3434
{
35-
return new PostAuthenticationGuardToken($user, $providerKey, $user->getRoles());
35+
return new PostAuthenticationToken($user, $providerKey, $user->getRoles());
3636
}
3737
}

Authentication/Authenticator/AbstractFormLoginAuthenticator.php renamed to Authenticator/AbstractLoginFormAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Security\Http\Authentication\Authenticator;
12+
namespace Symfony\Component\Security\Http\Authenticator;
1313

1414
use Symfony\Component\HttpFoundation\RedirectResponse;
1515
use Symfony\Component\HttpFoundation\Request;
@@ -25,7 +25,7 @@
2525
*
2626
* @experimental in 5.1
2727
*/
28-
abstract class AbstractFormLoginAuthenticator extends AbstractAuthenticator implements AuthenticationEntryPointInterface
28+
abstract class AbstractLoginFormAuthenticator extends AbstractAuthenticator implements AuthenticationEntryPointInterface
2929
{
3030
/**
3131
* Return the URL to the login page.

Authentication/Authenticator/AnonymousAuthenticator.php renamed to Authenticator/AnonymousAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Security\Http\Authentication\Authenticator;
12+
namespace Symfony\Component\Security\Http\Authenticator;
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;

Authentication/Authenticator/AuthenticatorInterface.php renamed to Authenticator/AuthenticatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Security\Http\Authentication\Authenticator;
12+
namespace Symfony\Component\Security\Http\Authenticator;
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;

Authentication/Authenticator/CustomAuthenticatedInterface.php renamed to Authenticator/CustomAuthenticatedInterface.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
<?php
22

3-
namespace Symfony\Component\Security\Http\Authentication\Authenticator;
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Http\Authenticator;
413

514
use Symfony\Component\Security\Core\Exception\AuthenticationException;
615
use Symfony\Component\Security\Core\User\UserInterface;

0 commit comments

Comments
 (0)