-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Security] Deprecate onAuthenticationSuccess() #18135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…implement
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,9 +41,14 @@ abstract protected function getLoginUrl(); | |
* login page directly), this returns the URL the user should be redirected | ||
* to after logging in successfully (e.g. your homepage). | ||
* | ||
* @deprecated Implement onAuthenticationFailure() instead of needing this function. | ||
* | ||
* @return string | ||
*/ | ||
abstract protected function getDefaultSuccessRedirectUrl(); | ||
protected function getDefaultSuccessRedirectUrl() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this one was abstract, it was always implemented, so this code is never going to be executed, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will get executed if the user doesn't implement Also, deprecations are hard :). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understand. Currently, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @fabpot. I guess we should remove the method here. Then we can check below if the method exists, trigger a deprecation in that case and optionally call it (not sure right now if that is needed for backwards compatibility). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I've removed it :). The problem is purely for new users of this class: they technically won't be required at a PHP-level to implement |
||
{ | ||
throw new \Exception(sprintf('You must implement onAuthenticationSuccess() or getDefaultSuccessRedirectURL() in %s.', get_class($this))); | ||
} | ||
|
||
/** | ||
* Override to change what happens after a bad username/password is submitted. | ||
|
@@ -72,6 +77,8 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio | |
*/ | ||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) | ||
{ | ||
@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); | ||
|
||
// if the user hit a secure page and start() was called, this was | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hit => hits |
||
// the URL they were on, and probably where you want to redirect to | ||
$targetPath = $this->getTargetPath($request->getSession(), $providerKey); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Guard\Tests\Authenticator; | ||
|
||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Core\User\UserProviderInterface; | ||
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator; | ||
class AbstractFormLoginAuthenticatorTest extends \PHPUnit_Framework_TestCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing empty line |
||
{ | ||
/** | ||
* @group legacy | ||
*/ | ||
public function testLegacyWithLoginUrl() | ||
{ | ||
$request = new Request(); | ||
$request->setSession($this->getMock('Symfony\Component\HttpFoundation\Session\Session')); | ||
|
||
$authenticator = new LegacyFormLoginAuthenticator(); | ||
/** @var RedirectResponse $actualResponse */ | ||
$actualResponse = $authenticator->onAuthenticationSuccess( | ||
$request, | ||
$this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'), | ||
'provider_key' | ||
); | ||
|
||
$this->assertEquals( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can make it a one liner as it's a short assertion. |
||
'/default_url', | ||
$actualResponse->getTargetUrl() | ||
); | ||
} | ||
} | ||
|
||
class LegacyFormLoginAuthenticator extends AbstractFormLoginAuthenticator | ||
{ | ||
protected function getDefaultSuccessRedirectUrl() | ||
{ | ||
return '/default_url'; | ||
} | ||
|
||
protected function getLoginUrl() | ||
{ | ||
} | ||
|
||
public function getCredentials(Request $request) | ||
{ | ||
} | ||
|
||
public function getUser($credentials, UserProviderInterface $userProvider) | ||
{ | ||
} | ||
|
||
public function checkCredentials($credentials, UserInterface $user) | ||
{ | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be: