10000 [Security] Deprecate onAuthenticationSuccess() by weaverryan · Pull Request #18135 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Security] 8000 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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ abstract class AbstractFormLoginAuthenticator extends AbstractGuardAuthenticator
*/
abstract protected function getLoginUrl();

/**
* The user will be redirected to the secure page they originally tried
* to access. But if no such page exists (i.e. the user went to the
* login page directly), this returns the URL the user should be redirected
* to after logging in successfully (e.g. your homepage).
*
* @return string
*/
abstract protected function getDefaultSuccessRedirectUrl();

/**
* Override to change what happens after a bad username/password is submitted.
*
Expand Down Expand Up @@ -72,7 +62,13 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
*/
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
// if the user hit a secure page and start() was called, this was
@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 (!method_exists($this, 'getDefaultSuccessRedirectUrl')) {
throw new \Exception(sprintf('You must implement onAuthenticationSuccess() or getDefaultSuccessRedirectURL() in %s.', get_class($this)));
}

// if the user hits a secure page and start() was called, this was
// the URL they were on, and probably where you want to redirect to
$targetPath = $this->getTargetPath($request->getSession(), $providerKey);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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
Copy link
Member

Choose a reason for hiding this comment

The 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('/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)
{
}
}
0