Skip to content

Commit 78eecba

Browse files
committed
Fix BC layer
1 parent a7a6f8a commit 78eecba

12 files changed

+122
-170
lines changed

UPGRADE-3.4.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,16 @@ Security
295295
* Deprecated the HTTP digest authentication: `NonceExpiredException`,
296296
`DigestAuthenticationListener` and `DigestAuthenticationEntryPoint` will be
297297
removed in 4.0. Use another authentication system like `http_basic` instead.
298+
299+
* The `GuardAuthenticatorInterface` has been deprecated and will be removed in 4.0.
300+
Use `AuthenticatorInterface` instead.
298301

299302
SecurityBundle
300303
--------------
301304

302305
* Using voters that do not implement the `VoterInterface`is now deprecated in
303306
the `AccessDecisionManager` and this functionality will be removed in 4.0.
304307

305-
* Using guard authenticator that implement the `GuardAuthenticatorInterface` is now
306-
deprecated, this will be removed in 4.0. `AuthenticatorInterface` must be used now.
307-
308308
* `FirewallContext::getListeners()` now returns `\Traversable|array`
309309

310310
* `InitAclCommand::__construct()` now takes an instance of

UPGRADE-4.0.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,6 @@ Security
659659
* The `RoleInterface` has been removed. Extend the `Symfony\Component\Security\Core\Role\Role`
660660
class instead.
661661

662-
* The `GuardAuthenticatorInterface` has been removed. Implement
663-
`Symfony\Component\Security\Guard\AuthenticatorInterface` class instead.
664-
665662
* The `LogoutUrlGenerator::registerListener()` method expects a 6th `string $context = null` argument.
666663

667664
* The `AccessDecisionManager::setVoters()` method has been removed. Pass the
@@ -676,6 +673,9 @@ Security
676673
`DigestAuthenticationListener` and `DigestAuthenticationEntryPoint` classes
677674
have been removed. Use another authentication system like `http_basic` instead.
678675

676+
* The `GuardAuthenticatorInterface` interface has been removed.
677+
Use `AuthenticatorInterface` instead.
678+
679679
SecurityBundle
680680
--------------
681681

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CHANGELOG
1515
requests.
1616
* deprecated HTTP digest authentication
1717
* Added a new password encoder for the Argon2i hashing algorithm
18+
* deprecated `GuardAuthenticatorInterface` in favor of `AuthenticatorInterface`
1819

1920
3.3.0
2021
-----

src/Symfony/Component/Security/Guard/AbstractGuardAuthenticator.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@
2323
abstract class AbstractGuardAuthenticator implements AuthenticatorInterface
2424
{
2525
/**
26-
* Default implementation of the AuthenticatorInterface::supports method
27-
* As we still have the deprecated GuardAuthenticatorInterface, this method must be implemented here
28-
* Once GuardAuthenticatorInterface will be removed, this method should be removed too.
26+
* {@inheritdoc}
2927
*
30-
* @param Request $request
31-
*
32-
* @return bool
28+
* @deprecated since version 3.4, to be removed in 4.0
3329
*/
3430
public function supports(Request $request)
3531
{
36-
@trigger_error('The Symfony\Component\Security\Guard\AbstractGuardAuthenticator::supports default implementation is used. This is provided for backward compatibility on GuardAuthenticationInterface that is deprecated since version 3.1 and will be removed in 4.0. Provide your own implementation of the supports method instead.', E_USER_DEPRECATED);
32+
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.4 and will be removed in 4.0. Implement the "%s::supports()" method in class "%s" instead.', __METHOD__, AuthenticatorInterface::class, get_class($this)), E_USER_DEPRECATED);
3733

3834
return true;
3935
}

src/Symfony/Component/Security/Guard/AuthenticatorInterface.php

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
namespace Symfony\Component\Security\Guard;
1313

1414
use Symfony\Component\HttpFoundation\Request;
15-
use Symfony\Component\HttpFoundation\Response;
16-
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
17-
use Symfony\Component\Security\Core\Exception\AuthenticationException;
18-
use Symfony\Component\Security\Core\User\UserInterface;
19-
use Symfony\Component\Security\Core\User\UserProviderInterface;
20-
use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
21-
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2215

2316
/**
2417
* The interface for all "guard" authenticators.
@@ -30,14 +23,12 @@
3023
* @author Ryan Weaver <[email protected]>
3124
* @author Amaury Leroux de Lens <[email protected]>
3225
*/
33-
interface AuthenticatorInterface extends AuthenticationEntryPointInterface
26+
interface AuthenticatorInterface extends GuardAuthenticatorInterface
3427
{
3528
/**
36-
* Does the authenticator support the given Request ?
29+
* Does the authenticator support the given Request?
3730
*
38-
* If this returns true, authentication will continue (e.g. getCredentials() will be called).
39-
* If false, this authenticator is done. The next (if any) authenticators will be called and
40-
* may authenticate the user, or leave the user as anonymous.
31+
* If this returns false, the authenticator will be skipped.
4132
*
4233
* @param Request $request
4334
*
@@ -47,8 +38,7 @@ public function supports(Request $request);
4738

4839
/**
4940
* Get the authentication credentials from the request and return them
50-
* as any type (e.g. an associate array). If you return null, authentication
51-
* will be skipped.
41+
* as any type (e.g. an associate array).
5242
*
5343
* Whatever value you return here will be passed to getUser() and checkCredentials()
5444
*
@@ -65,106 +55,9 @@ public function supports(Request $request);
6555
*
6656
* @param Request $request
6757
*
68-
* @return mixed|null
69-
*/
70-
public function getCredentials(Request $request);
71-
72-
/**
73-
* Return a UserInterface object based on the credentials.
74-
*
75-
* The *credentials* are the return value from getCredentials()
76-
*
77-
* You may throw an AuthenticationException if you wish. If you return
78-
* null, then a UsernameNotFoundException is thrown for you.
58+
* @return mixed Any non-null value
7959
*
80-
* @param mixed $credentials
81-
* @param UserProviderInterface $userProvider
82-
*
83-
* @throws AuthenticationException
84-
*
85-
* @return UserInterface|null
60+
* @throws \UnexpectedValueException If null is returned
8661
*/
87-
public function getUser($credentials, UserProviderInterface $userProvider);
88-
89-
/**
90-
* Returns true if the credentials are valid.
91-
*
92-
* If any value other than true is returned, authentication will
93-
* fail. You may also throw an AuthenticationException if you wish
94-
* to cause authentication to fail.
95-
*
96-
* The *credentials* are the return value from getCredentials()
97-
*
98-
* @param mixed $credentials
99-
* @param UserInterface $user
100-
*
101-
* @return bool
102-
*
103-
* @throws AuthenticationException
104-
*/
105-
public function checkCredentials($credentials, UserInterface $user);
106-
107-
/**
108-
* Creates an authenticated token for the given user.
109-
*
110-
* If you don't care about which token class is used or don't really
111-
* understand what a "token" is, you can skip this method by extending
112-
* the AbstractGuardAuthenticator class from your authenticator.
113-
*
114-
* @see AbstractGuardAuthenticator
115-
*
116-
* @param UserInterface $user
117-
* @param string $providerKey The provider (i.e. firewall) key
118-
*
119-
* @return GuardTokenInterface
120-
*/
121-
public function createAuthenticatedToken(UserInterface $user, $providerKey);
122-
123-
/**
124-
* Called when authentication executed, but failed (e.g. wrong username password).
125-
*
126-
* This should return the Response sent back to the user, like a
127-
* RedirectResponse to the login page or a 403 response.
128-
*
129-
* If you return null, the request will continue, but the user will
130-
* not be authenticated. This is probably not what you want to do.
131-
*
132-
* @param Request $request
133-
* @param AuthenticationException $exception
134-
*
135-
* @return Response|null
136-
*/
137-
public function onAuthenticationFailure(Request $request, AuthenticationException $exception);
138-
139-
/**
140-
* Called when authentication executed and was successful!
141-
*
142-
* This should return the Response sent back to the user, like a
143-
* RedirectResponse to the last page they visited.
144-
*
145-
* If you return null, the current request will continue, and the user
146-
* will be authenticated. This makes sense, for example, with an API.
147-
*
148-
* @param Request $request
149-
* @param TokenInterface $token
150-
* @param string $providerKey The provider (i.e. firewall) key
151-
*
152-
* @return Response|null
153-
*/
154-
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey);
155-
156-
/**
157-
* Does this method support remember me cookies?
158-
*
159-
* Remember me cookie will be set if *all* of the following are met:
160-
* A) This method returns true
161-
* B) The remember_me key under your firewall is configured
162-
* C) The "remember me" functionality is activated. This is usually
163-
* done by having a _remember_me checkbox in your form, but
164-
* can be configured by the "always_remember_me" and "remember_me_parameter"
165-
* parameters under the "remember_me" firewall key
166-
*
167-
* @return bool
168-
*/
169-
public function supportsRememberMe();
62+
public function getCredentials(Request $request);
17063
}

src/Symfony/Component/Security/Guard/Firewall/GuardAuthenticationListener.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1717
use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
18+
use Symfony\Component\Security\Guard\GuardAuthenticatorInterface;
1819
use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken;
1920
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
20-
use Symfony\Component\Security\Guard\GuardAuthenticatorInterface;
2121
use Symfony\Component\Security\Guard\AuthenticatorInterface;
2222
use Psr\Log\LoggerInterface;
2323
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
@@ -94,46 +94,37 @@ public function handle(GetResponseEvent $event)
9494
}
9595
}
9696

97-
private function executeGuardAuthenticator($uniqueGuardKey, AuthenticatorInterface $guardAuthenticator, GetResponseEvent $event)
97+
private function executeGuardAuthenticator($uniqueGuardKey, GuardAuthenticatorInterface $guardAuthenticator, GetResponseEvent $event)
9898
{
9999
$request = $event->getRequest();
100100
try {
101101
if (null !== $this->logger) {
102102
$this->logger->debug('Calling getCredentials() on guard configurator.', array('firewall_key' => $this->providerKey, 'authenticator' => get_class($guardAuthenticator)));
103103
}
104104

105-
// abort the execution of the authenticator if it doesn't support the request.
106-
if ($guardAuthenticator instanceof GuardAuthenticatorInterface) {
107-
// it's a GuardAuthenticatorInterface
108-
// we support the previous behaviour to avoid BC break.
109-
$credentialsCanBeNull = true;
110-
@trigger_error('The Symfony\Component\Security\Guard\GuardAuthenticatorInterface interface is deprecated since version 3.1 and will be removed in 4.0. Use Symfony\Component\Security\Guard\Authenticator\GuardAuthenticatorInterface instead.', E_USER_DEPRECATED);
111-
} else {
112-
if (true !== $guardAuthenticator->supports($request)) {
105+
// abort the execution of the authenticator if it doesn't support the request
106+
if ($guardAuthenticator instanceof AuthenticatorInterface) {
107+
if (!$guardAuthenticator->supports($request)) {
113108
return;
114109
}
115110
// as there was a support for given request,
116111
// authenticator is expected to give not-null credentials.
117112
$credentialsCanBeNull = false;
113+
} else {
114+
// deprecated since version 3.4, to be removed in 4.0
115+
$credentialsCanBeNull = true;
118116
}
119117

120118
// allow the authenticator to fetch authentication info from the request
121119
$credentials = $guardAuthenticator->getCredentials($request);
122120

123121
if (null === $credentials) {
124-
// if GuardAuthenticatorInterface is used
125-
// allow null to skip authentication.
122+
// deprecated since version 3.4, to be removed in 4.0
126123
if ($credentialsCanBeNull) {
127124
return;
128125
}
129126

130-
// otherwise something went wrong and the authentication must fail
131-
throw new \UnexpectedValueException(sprintf(
132-
'You must return some credentials from %s:getCredentials().
133-
To skip authentication, return false from %s::supports().',
134-
get_class($guardAuthenticator),
135-
get_class($guardAuthenticator)
136-
));
127+
throw new \UnexpectedValueException(sprintf('The return value of "%s::getCredentials()" must not be null. Return false from "%s::supports()" instead.', get_class($guardAuthenticator), get_class($guardAuthenticator)));
137128
}
138129

139130
// create a token with the unique key, so that the provider knows which authenticator to use
@@ -205,7 +196,7 @@ public function setRememberMeServices(RememberMeServicesInterface $rememberMeSer
205196
* @param TokenInterface $token
206197
* @param Response $response
207198
*/
208-
private function triggerRememberMe(AuthenticatorInterface $guardAuthenticator, Request $request, TokenInterface $token, Response $response = null)
199+
private function triggerRememberMe(GuardAuthenticatorInterface $guardAuthenticator, Request $request, TokenInterface $token, Response $response = null)
209200
{
210201
if (null === $this->rememberMeServices) {
211202
if (null !== $this->logger) {

src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
* can be called directly (e.g. for manual authentication) or overridden.
3030
*
3131
* @author Ryan Weaver <[email protected]>
32+
*
33+
* @final since version 3.4
3234
*/
3335
class GuardAuthenticatorHandler
3436
{
@@ -68,7 +70,7 @@ public function authenticateWithToken(TokenInterface $token, Request $request)
6870
*
6971
* @return null|Response
7072
*/
71-
public function handleAuthenticationSuccess(TokenInterface $token, Request $request, AuthenticatorInterface $guardAuthenticator, $providerKey)
73+
public function handleAuthenticationSuccess(TokenInterface $token, Request $request, GuardAuthenticatorInterface $guardAuthenticator, $providerKey)
7274
{
7375
$response = $guardAuthenticator->onAuthenticationSuccess($request, $token, $providerKey);
7476

@@ -95,7 +97,7 @@ public function handleAuthenticationSuccess(TokenInterface $token, Request $requ
9597
*
9698
* @return Response|null
9799
*/
98-
public function authenticateUserAndHandleSuccess(UserInterface $user, Request $request, AuthenticatorInterface $authenticator, $providerKey)
100+
public function authenticateUserAndHandleSuccess(UserInterface $user, Request $request, GuardAuthenticatorInterface $authenticator, $providerKey)
99101
{
100102
// create an authenticated token for the User
101103
$token = $authenticator->createAuthenticatedToken($user, $providerKey);
@@ -117,7 +119,7 @@ public function authenticateUserAndHandleSuccess(UserInterface $user, Request $r
117119
*
118120
* @return null|Response
119121
*/
120-
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, AuthenticatorInterface $guardAuthenticator, $providerKey)
122+
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, GuardAuthenticatorInterface $guardAuthenticator, $providerKey)
121123
{
122124
$token = $this->tokenStorage->getToken();
123125
if ($token instanceof PostAuthenticationGuardToken && $providerKey === $token->getProviderKey()) {

src/Symfony/Component/Security/Guard/GuardAuthenticatorInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Security\Core\User\UserInterface;
1919
use Symfony\Component\Security\Core\User\UserProviderInterface;
2020
use Symfony\Component\Security\Guard\Token\GuardTokenInterface;
21+
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2122

2223
/**
2324
* The interface for all "guard" authenticators.
@@ -28,9 +29,9 @@
2829
*
2930
* @author Ryan Weaver <[email protected]>
3031
*
31-
* @deprecated Symfony\Component\Security\Guard\AuthenticatorInterface must be used instead
32+
* @deprecated since version 3.4, to be removed in 4.0. Use AuthenticatorInterface instead
3233
*/
33-
interface GuardAuthenticatorInterface extends AuthenticatorInterface
34+
interface GuardAuthenticatorInterface extends AuthenticationEntryPointInterface
3435
{
3536
/**
3637
* Get the authentication credentials from the request and return them

src/Symfony/Component/Security/Guard/Provider/GuardAuthenticationProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct($guardAuthenticators, UserProviderInterface $userPro
5656
/**
5757
* Finds the correct authenticator for the token and calls it.
5858
*
59-
* @param TokenInterface|GuardTokenInterface $token
59+
* @param GuardTokenInterface $token
6060
*
6161
* @return TokenInterface
6262
*/
@@ -101,7 +101,7 @@ public function authenticate(TokenInterface $token)
101101
// instances that will be checked if you have multiple firewalls.
102102
}
103103

104-
private function authenticateViaGuard(AuthenticatorInterface $guardAuthenticator, PreAuthenticationGuardToken $token)
104+
private function authenticateViaGuard($guardAuthenticator, PreAuthenticationGuardToken $token)
105105
{
106106
// get the user from the GuardAuthenticator
107107
$user = $guardAuthenticator->getUser($token->getCredentials(), $this->userProvider);
@@ -142,6 +142,6 @@ private function authenticateViaGuard(AuthenticatorInterface $guardAuthenticator
142142

143143
public function supports(TokenInterface $token)
144144
{
145-
return $token instanceof TokenInterface;
145+
return $token instanceof GuardTokenInterface;
146146
}
147147
}

0 commit comments

Comments
 (0)