8000 [#18027] Deprecate onAuthenticationSuccess() - it's simple enough to … · symfony/symfony@009c6a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 009c6a6

Browse files
committed
[#18027] Deprecate onAuthenticationSuccess() - it's simple enough to implement
1 parent b868feb commit 009c6a6

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ abstract protected function getLoginUrl();
4141
* login page directly), this returns the URL the user should be redirected
4242
* to after logging in successfully (e.g. yo 8000 ur homepage).
4343
*
44+
* @deprecated Implement onAuthenticationFailure() instead of needing this function.
45+
*
4446
* @return string
4547
*/
46-
abstract protected function getDefaultSuccessRedirectUrl();
48+
protected function getDefaultSuccessRedirectUrl()
49+
{
50+
throw new \Exception(sprintf('You must implement onAuthenticationSuccess() or getDefaultSuccessRedirectURL() in %s.', get_class($this)));
51+
}
4752

4853
/**
4954
* Override to change what happens after a bad username/password is submitted.
@@ -72,6 +77,8 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
7277
*/
7378
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
7479
{
80+
@trigger_error(sprintf('The AbstractFormLoginAuthenticator::onAuthenticationSuccess() implementation was deprecated in Symfony 3.1 and will be removed in Symfony 4.0. You should implement this method yourself in %s and remove getDefaultSuccessRedirectUrl().', get_class($this)), E_USER_DEPRECATED);
81+
7582
// if the user hit a secure page and start() was called, this was
7683
// the URL they were on, and probably where you want to redirect to
7784
$targetPath = $this->getTargetPath($request->getSession(), $providerKey);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\Guard\Tests\Authenticator;
13+
14+
use Symfony\Component\HttpFoundation\RedirectResponse;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\Security\Core\User\UserInterface;
17+
use Symfony\Component\Security\Core\User\UserProviderInterface;
18+
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
19+
class AbstractFormLoginAuthenticatorTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* @group legacy
23+
*/
24+
public function testLegacyWithLoginUrl()
25+
{
26+
$request = new Request();
27+
$request->setSession($this->getMock('Symfony\Component\HttpFoundation\Session\Session'));
28+
29+
$authenticator = new LegacyFormLoginAuthenticator();
30+
/** @var RedirectResponse $actualResponse */
31+
$actualResponse = $authenticator->onAuthenticationSuccess(
32+
$request,
33+
$this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'),
34+
'provider_key'
35+
);
36+
37+
$this->assertEquals(
38+
'/default_url',
39+
$actualResponse->getTargetUrl()
40+
);
41+
}
42+
}
43+
44+
class LegacyFormLoginAuthenticator extends AbstractFormLoginAuthenticator
45+
{
46+
protected function getDefaultSuccessRedirectUrl()
47+
{
48+
return '/default_url';
49+
}
50+
51+
protected function getLoginUrl()
52+
{
53+
}
54+
55+
public function getCredentials(Request $request)
56+
{
57+
}
58+
59+
public function getUser($credentials, UserProviderInterface $userProvider)
60+
{
61+
}
62+
63+
public function checkCredentials($credentials, UserInterface $user)
64+
{
65+
}
66+
}
67+

0 commit comments

Comments
 (0)
0