From b1e75f7a7fb7571dcd09df73421864286601c402 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 12 Mar 2016 12:14:01 -0500 Subject: [PATCH 1/3] [#18027] Deprecate onAuthenticationSuccess() - it's simple enough to implement --- .../AbstractFormLoginAuthenticator.php | 9 ++- .../AbstractFormLoginAuthenticatorTest.php | 67 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php diff --git a/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php b/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php index cefafc1e542fb..df5bf86eab6fd 100644 --- a/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php +++ b/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php @@ -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() + { + 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 // the URL they were on, and probably where you want to redirect to $targetPath = $this->getTargetPath($request->getSession(), $providerKey); diff --git a/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php b/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php new file mode 100644 index 0000000000000..8c5df6bfa8d14 --- /dev/null +++ b/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php @@ -0,0 +1,67 @@ + + * + * 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 +{ + /** + * @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) + { + } +} + From 7cd1a13bfcc9a1fd784a9c17b59229afcd926d80 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 24 Mar 2016 19:14:50 -0400 Subject: [PATCH 2/3] Making minor fixes thanks to comments --- .../Guard/Authenticator/AbstractFormLoginAuthenticator.php | 4 ++-- .../Authenticator/AbstractFormLoginAuthenticatorTest.php | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php b/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php index df5bf86eab6fd..b024decd437fb 100644 --- a/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php +++ b/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php @@ -41,7 +41,7 @@ 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. + * @deprecated Implement onAuthenticationSuccess() instead of needing this function. * * @return string */ @@ -79,7 +79,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, { @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 + // 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); diff --git a/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php b/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php index 8c5df6bfa8d14..7eb3013ef2375 100644 --- a/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php +++ b/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php @@ -34,10 +34,7 @@ public function testLegacyWithLoginUrl() 'provider_key' ); - $this->assertEquals( - '/default_url', - $actualResponse->getTargetUrl() - ); + $this->assertEquals('/default_url', $actualResponse->getTargetUrl()); } } @@ -64,4 +61,3 @@ public function checkCredentials($credentials, UserInterface $user) { } } - From c912c894c156ee866df89ce914511b6f3593e947 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 30 Mar 2016 16:50:05 -0400 Subject: [PATCH 3/3] Removing concrete getDefaultSuccessRedirectUrl() method --- .../AbstractFormLoginAuthenticator.php | 19 ++++--------------- .../AbstractFormLoginAuthenticatorTest.php | 1 + 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php b/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php index b024decd437fb..d10e486705a82 100644 --- a/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php +++ b/src/Symfony/Component/Security/Guard/Authenticator/AbstractFormLoginAuthenticator.php @@ -35,21 +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). - * - * @deprecated Implement onAuthenticationSuccess() instead of needing this function. - * - * @return string - */ - protected function getDefaultSuccessRedirectUrl() - { - 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. * @@ -79,6 +64,10 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, { @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); diff --git a/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php b/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php index 7eb3013ef2375..e86b5ad26488e 100644 --- a/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php +++ b/src/Symfony/Component/Security/Guard/Tests/Authenticator/AbstractFormLoginAuthenticatorTest.php @@ -16,6 +16,7 @@ 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 { /** pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy