8000 feature #24446 [Security] Remove GuardAuthenticatorInterface (chalasr) · symfony/symfony@75fe1fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 75fe1fc

Browse files
committed
feature #24446 [Security] Remove GuardAuthenticatorInterface (chalasr)
This PR was merged into the 4.0-dev branch. Discussion ---------- [Security] Remove GuardAuthenticatorInterface | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | symfony/symfony-docs#8485 Removes BC layers for #16835. Commits ------- 3408152 [Security][Guard] Remove GuardAuthenticatorInterface
2 parents 0958fc4 + 3408152 commit 75fe1fc

9 files changed

+124
-388
lines changed

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ CHANGELOG
1111
* removed support for voters that don't implement the `VoterInterface`
1212
* added a sixth `string $context` argument to `LogoutUrlGenerator::registerListener()`
1313
* removed HTTP digest authentication
14+
* removed `GuardAuthenticatorInterface` in favor of `AuthenticatorInterface`
15+
* removed `AbstractGuardAuthenticator::supports()`
1416

1517
3.4.0
1618
-----

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Security\Guard;
1313

14-
use Symfony\Component\HttpFoundation\Request;
1514
use Symfony\Component\Security\Core\User\UserInterface;
1615
use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
1716

@@ -22,18 +21,6 @@
2221
*/
2322
abstract class AbstractGuardAuthenticator implements AuthenticatorInterface
2423
{
25-
/**
26-
* {@inheritdoc}
27-
*
28-
* @deprecated since version 3.4, to be removed in 4.0
29-
*/
30-
public function supports(Request $request)
31-
{
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);
33-
34-
return true;
35-
}
36-
3724
/**
3825
* Shortcut to create a PostAuthenticationGuardToken for you, if you don't really
3926
* care about which authenticated token you're using.

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

Lines changed: 108 additions & 1 deletion
10000
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
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;
1522

1623
/**
1724
* The interface for all "guard" authenticators.
@@ -23,7 +30,7 @@
2330
* @author Ryan Weaver <ryan@knpuniversity.com>
2431
* @author Amaury Leroux de Lens <amaury@lerouxdelens.com>
2532
*/
26-
interface AuthenticatorInterface extends GuardAuthenticatorInterface
33+
interface AuthenticatorInterface extends AuthenticationEntryPointInterface
2734
{
2835
/**
2936
* Does the authenticator support the given Request?
@@ -60,4 +67,104 @@ public function supports(Request $request);
6067
* @throws \UnexpectedValueException If null is returned
6168
*/
6269
public function getCredentials(Request $request);
70+
71+
/**
72+
* Return a UserInterface object based on the credentials.
73+
*
74+
* The *credentials* are the return value from getCredentials()
75+
*
76+
* You may throw an AuthenticationException if you wish. If you return
77+
* null, then a UsernameNotFoundException is thrown for you.
78+
*
79+
* @param mixed $credentials
80+
* @param UserProviderInterface $userProvider
81+
*
82+
* @throws AuthenticationException
83+
*
84+
* @return UserInterface|null
85+
*/
86+
public function getUser($credentials, UserProviderInterface $userProvider);
87+
88+
/**
89+
* Returns true if the credentials are valid.
90+
*
91+
* If any value other than true is returned, authentication will
92+
* fail. You may also throw an AuthenticationException if you wish
93+
* to cause authentication to fail.
94+
*
95+
* The *credentials* are the return value from getCredentials()
96+
*
97+
* @param mixed $credentials
98+
* @param UserInterface $user
99+
*
100+
* @return bool
101+
*
102+
* @throws AuthenticationException
103+
*/
104+
public function checkCredentials($credentials, UserInterface $user);
105+
106+
/**
107+
* Create an authenticated token for the given user.
108+
*
109+
* If you don't care about which token class is used or don't really
110+
* understand what a "token" is, you can skip this method by extending
111+
* the AbstractGuardAuthenticator class from your authenticator.
112+
*
113+
* @see AbstractGuardAuthenticator
114+
*
115+
* @param UserInterface $user
116+
* @param string $providerKey The provider (i.e. firewall) key
117+
*
118+
* @return GuardTokenInterface
119+
*/
120+
public function createAuthenticatedToken(UserInterface $user, $providerKey);
121+
122+
/**
123+
* Called when authentication executed, but failed (e.g. wrong username password).
124+
*
125+
* This should return the Response sent back to the user, like a
126+
* RedirectResponse to the login page or a 403 response.
127+
*
128+
* If you return null, the request will continue, but the user will
129+
* not be authenticated. This is probably not what you want to do.
130+
*
131+
* @param Request $request
132+
* @param AuthenticationException $exception
133+
*
134+
* @return Response|null
135+
*/
136+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception);
137+
138+
/**
139+
* Called when authentication executed and was successful!
140+
*
141+
* This should return the Response sent back to the user, like a
142+
* RedirectResponse to the last page they visited.
143+
*
144+
* If you return null, the current request will continue, and the user
145+
* will be authenticated. This makes sense, for example, with an API.
146+
*
147+
* @param Request $request
148+
* @param TokenInterface $token
149+
* @param string $providerKey The provider (i.e. firewall) key
150+
*
151+
* @return Response|null
152+
*/
153+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey);
154+
155+
/**
156+
* Does this method support remember me cookies?
157+
*
158+
* Remember me cookie will be set if *all* of the following are met:
159+
* A) This method returns true
160+
* B) The remember_me key under your firewall is configured
161+
* C) The "remember me" functionality is activated. This is usually
162+
* done by having a _remember_me checkbox in your form, but
163+
* can be configured by the "always_remember_me" and "remember_me_parameter"
164+
* parameters under the "remember_me" firewall key
165+
* D) The onAuthenticationSuccess method returns a Response object
166+
*
167+
* @return bool
168+
*/
169+
public function supportsRememberMe();
63170
}

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +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;
18+
use Symfony\Component\Security\Guard\AuthenticatorInterface;
1919
use Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken;
2020
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
21-
use Symfony\Component\Security\Guard\AuthenticatorInterface;
2221
use Psr\Log\LoggerInterface;
2322
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2423
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -94,7 +93,7 @@ public function handle(GetResponseEvent $event)
9493
}
9594
}
9695

97-
private function executeGuardAuthenticator($uniqueGuardKey, GuardAuthenticatorInterface $guardAuthenticator, GetResponseEvent $event)
96+
private function executeGuardAuthenticator($uniqueGuardKey, AuthenticatorInterface $guardAuthenticator, GetResponseEvent $event)
9897
{
9998
$request = $event->getRequest();
10099
try {
@@ -103,27 +102,14 @@ private function executeGuardAuthenticator($uniqueGuardKey, GuardAuthenticatorIn
103102
}
104103

105104
// abort the execution of the authenticator if it doesn't support the request
106-
if ($guardAuthenticator instanceof AuthenticatorInterface) {
107-
if (!$guardAuthenticator->supports($request)) {
108-
return;
109-
}
110-
// as there was a support for given request,
111-
// authenticator is expected to give not-null credentials.
112-
$credentialsCanBeNull = false;
113-
} else {
114-
// deprecated since version 3.4, to be removed in 4.0
115-
$credentialsCanBeNull = true;
105+
if (!$guardAuthenticator->supports($request)) {
106+
return;
116107
}
117108

118109
// allow the authenticator to fetch authentication info from the request
119110
$credentials = $guardAuthenticator->getCredentials($request);
120111

121112
if (null === $credentials) {
122-
// deprecated since version 3.4, to be removed in 4.0
123-
if ($credentialsCanBeNull) {
124-
return;
125-
}
126-
127113
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)));
128114
}
129115

@@ -196,7 +182,7 @@ public function setRememberMeServices(RememberMeServicesInterface $rememberMeSer
196182
* @param TokenInterface $token
197183
* @param Response $response
198184
*/
199-
private function triggerRememberMe(GuardAuthenticatorInterface $guardAuthenticator, Request $request, TokenInterface $token, Response $response = null)
185+
private function triggerRememberMe(AuthenticatorInterface $guardAuthenticator, Request $request, TokenInterface $token, Response $response = null)
200186
{
201187
if (null === $this->rememberMeServices) {
202188
if (null !== $this->logger) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function authenticateWithToken(TokenInterface $token, Request $request)
7070
*
7171
* @return null|Response
7272
*/
73-
public function handleAuthenticationSuccess(TokenInterface $token, Request $request, GuardAuthenticatorInterface $guardAuthenticator, $providerKey)
73+
public function handleAuthenticationSuccess(TokenInterface $token, Request $request, AuthenticatorInterface $guardAuthenticator, $providerKey)
7474
{
7575
$response = $guardAuthenticator->onAuthenticationSuccess($request, $token, $providerKey);
7676

@@ -97,7 +97,7 @@ public function handleAuthenticationSuccess(TokenInterface $token, Request $requ
9797
*
9898
* @return Response|null
9999
*/
100-
public function authenticateUserAndHandleSuccess(UserInterface $user, Request $request, GuardAuthenticatorInterface $authenticator, $providerKey)
100+
public function authenticateUserAndHandleSuccess(UserInterface $user, Request $request, AuthenticatorInterface $authenticator, $providerKey)
101101
{
102102
// create an authenticated token for the User
103103
$token = $authenticator->createAuthenticatedToken($user, $providerKey);
@@ -119,7 +119,7 @@ public function authenticateUserAndHandleSuccess(UserInterface $user, Request $r
119119
*
120120
* @return null|Response
121121
*/
122-
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, GuardAuthenticatorInterface $guardAuthenticator, $providerKey)
122+
public function handleAuthenticationFailure(AuthenticationException $authenticationException, Request $request, AuthenticatorInterface $guardAuthenticator, $providerKey)
123123
{
124124
$token = $this->tokenStorage->getToken();
125125
if ($token instanceof PostAuthenticationGuardToken && $providerKey === $token->getProviderKey()) {

0 commit comments

Comments
 (0)
0