Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0db1655

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

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ 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. your homepage).
4343
*
44+
* @deprecated Implement onAuthenticationFailure() instead of needing this function.
4445
* @return string
4546
*/
46-
abstract protected function getDefaultSuccessRedirectUrl();
47+
protected function getDefaultSuccessRedirectUrl()
48+
{
49+
throw new \Exception(sprintf('You must implement onAuthenticationSuccess() or getDefaultSuccessRedirectURL() in %s.', get_class($this)));
50+
}
4751

4852
/**
4953
* Override to change what happens after a bad username/password is submitted.
@@ -72,6 +76,8 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
7276
*/
7377
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
7478
{
79+
@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);
80+
7581
// if the user hit a secure page and start() was called, this was
7682
// the URL they were on, and probably where you want to redirect to
7783
$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 <[email protected]>
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\Exception\AuthenticationException;
17+
use Symfony\Component\Security\Core\User\UserInterface;
18+
use Symfony\Component\Security\Core\User\UserProviderInterface;
19+
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;
20+
class AbstractFormLoginAuthenticatorTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @group legacy
24+
*/
25+
public function testLegacyWithLoginUrl()
26+
{
27+
$request = new Request();
28+
$request->setSession($this->getMock('Symfony\Component\HttpFoundation\Session\Session'));
29+
30+
$authenticator = new LegacyFormLoginAuthenticator();
31+
/** @var RedirectResponse $actualResponse */
32+
$actualResponse = $authenticator->onAuthenticationSuccess(
33+
$request,
34+
$this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'),
35+
'provider_key'
36+
);
37+
38+
$this->assertEquals(
39+
'/default_url',
40+
$actualResponse->getTargetUrl()
41+
);
42+
}
43+
}
44+
45+
class LegacyFormLoginAuthenticator extends AbstractFormLoginAuthenticator
46+
{
47+
protected function getDefaultSuccessRedirectUrl()
48+
{
49+
return '/default_url';
50+
}
51+
52+
protected function getLoginUrl()
53+
{
54+
}
55+
56+
public function getCredentials(Request $request)
57+
{
58+
}
59+
60+
public function getUser($credentials, UserProviderInterface $userProvider)
61+
{
62+
}
63+
64+
public function checkCredentials($credentials, UserInterface $user)
65+
{
66+
}
67+
}

0 commit comments

Comments
 (0)