summaryrefslogtreecommitdiffstats
path: root/Guard
diff options
context:
space:
mode:
Diffstat (limited to 'Guard')
-rw-r--r--Guard/Authenticator/AbstractFormLoginAuthenticator.php21
-rw-r--r--Guard/Firewall/GuardAuthenticationListener.php2
-rw-r--r--Guard/Provider/GuardAuthenticationProvider.php1
-rw-r--r--Guard/Tests/Authenticator/FormLoginAuthenticatorTest.php9
-rw-r--r--Guard/composer.json8
5 files changed, 24 insertions, 17 deletions
diff --git a/Guard/Authenticator/AbstractFormLoginAuthenticator.php b/Guard/Authenticator/AbstractFormLoginAuthenticator.php
index 6d6d14e..f99900b 100644
--- a/Guard/Authenticator/AbstractFormLoginAuthenticator.php
+++ b/Guard/Authenticator/AbstractFormLoginAuthenticator.php
@@ -18,6 +18,7 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Security;
+use Symfony\Component\Security\Http\Util\TargetPathTrait;
/**
* A base class to make form login authentication easier!
@@ -26,6 +27,8 @@ use Symfony\Component\Security\Core\Security;
*/
abstract class AbstractFormLoginAuthenticator extends AbstractGuardAuthenticator
{
+ use TargetPathTrait;
+
/**
* Return the URL to the login page.
*
@@ -34,16 +37,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.
*
* @param Request $request
@@ -73,12 +66,18 @@ abstract class AbstractFormLoginAuthenticator extends AbstractGuardAuthenticator
*/
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 (!method_exists($this, 'getDefaultSuccessRedirectUrl')) {
+ throw new \Exception(sprintf('You must implement onAuthenticationSuccess() or getDefaultSuccessRedirectUrl() in %s.', get_class($this)));
+ }
+
$targetPath = null;
// 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
if ($request->getSession() instanceof SessionInterface) {
- $targetPath = $request->getSession()->get('_security.'.$providerKey.'.target_path');
+ $targetPath = $this->getTargetPath($request->getSession(), $providerKey);
}
if (!$targetPath) {
diff --git a/Guard/Firewall/GuardAuthenticationListener.php b/Guard/Firewall/GuardAuthenticationListener.php
index ed0a36e..59d5d29 100644
--- a/Guard/Firewall/GuardAuthenticationListener.php
+++ b/Guard/Firewall/GuardAuthenticationListener.php
@@ -78,7 +78,7 @@ class GuardAuthenticationListener implements ListenerInterface
if ($event->hasResponse()) {
if (null !== $this->logger) {
- $this->logger->debug(sprintf('The "%s" authenticator set the response. Any later authenticator will not be called', get_class($guardAuthenticator)));
+ $this->logger->debug('The "{authenticator}" authenticator set the response. Any later authenticator will not be called', array('authenticator' => get_class($guardAuthenticator)));
}
break;
diff --git a/Guard/Provider/GuardAuthenticationProvider.php b/Guard/Provider/GuardAuthenticationProvider.php
index 4347e02..2793674 100644
--- a/Guard/Provider/GuardAuthenticationProvider.php
+++ b/Guard/Provider/GuardAuthenticationProvider.php
@@ -12,7 +12,6 @@
namespace Symfony\Component\Security\Guard\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
-use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Guard\GuardAuthenticatorInterface;
diff --git a/Guard/Tests/Authenticator/FormLoginAuthenticatorTest.php b/Guard/Tests/Authenticator/FormLoginAuthenticatorTest.php
index 3dbbf84..e35564b 100644
--- a/Guard/Tests/Authenticator/FormLoginAuthenticatorTest.php
+++ b/Guard/Tests/Authenticator/FormLoginAuthenticatorTest.php
@@ -50,6 +50,9 @@ class FormLoginAuthenticatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(self::LOGIN_URL, $failureResponse->getTargetUrl());
}
+ /**
+ * @group legacy
+ */
public function testAuthenticationSuccessWithoutSession()
{
$token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')
@@ -62,6 +65,9 @@ class FormLoginAuthenticatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(self::DEFAULT_SUCCESS_URL, $redirectResponse->getTargetUrl());
}
+ /**
+ * @group legacy
+ */
public function testAuthenticationSuccessWithSessionButEmpty()
{
$token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')
@@ -78,6 +84,9 @@ class FormLoginAuthenticatorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(self::DEFAULT_SUCCESS_URL, $redirectResponse->getTargetUrl());
}
+ /**
+ * @group legacy
+ */
public function testAuthenticationSuccessWithSessionAndTarget()
{
$token = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface')
diff --git a/Guard/composer.json b/Guard/composer.json
index 3208920..7adb774 100644
--- a/Guard/composer.json
+++ b/Guard/composer.json
@@ -16,9 +16,9 @@
}
],
"require": {
- "php": ">=5.3.9",
- "symfony/security-core": "~2.8|~3.0.0",
- "symfony/security-http": "~2.7|~3.0.0"
+ "php": ">=5.5.9",
+ "symfony/security-core": "~2.8|~3.0",
+ "symfony/security-http": "~3.1"
},
"require-dev": {
"psr/log": "~1.0"
@@ -32,7 +32,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
- "dev-master": "2.8-dev"
+ "dev-master": "3.1-dev"
}
}
}