summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2012-07-12 13:32:07 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2012-07-12 13:32:07 +0200
commit77e63cb1bad01c2632557391373b04a8da82e099 (patch)
treea695b81f02813f5271933f23938b873b243586dd
parent955fa80e91aaeb8e66805560ec9a0c39b9eb5eb0 (diff)
parentb8d0ed72c14a8068aa604cd42974bc6e64547579 (diff)
downloadsymfony-security-77e63cb1bad01c2632557391373b04a8da82e099.zip
symfony-security-77e63cb1bad01c2632557391373b04a8da82e099.tar.gz
symfony-security-77e63cb1bad01c2632557391373b04a8da82e099.tar.bz2
merged branch asm89/fix-default-auth-successhandler-extension (PR #4865)
Commits ------- 5e6c06f [Security] Remove hard dependency on $providerKey for default auth success handler Discussion ---------- [Security] Remove hard dependency on $providerKey for default auth success handler Bug fix: yes? Feature addition: yes? Backwards compatibility break: no Symfony2 tests pass: [![Build Status](https://secure.travis-ci.org/asm89/symfony.png?branch=fix-default-auth-successhandler-extension)](http://travis-ci.org/asm89/symfony) License of the code: MIT In 8ffaafa86741a03ecb2f91e3d67802f4c6baf36b a hard dependency was introduced between the default authentication success handling code and the active firewall. This makes sense. However, for people implementing their own success handler this makes it impossible to extend the default class as the `$providerKey` is set in the extension of the security bundle. This PR makes the dependency a soft one so people can extend the class and use the default definition as a parent for their own service. However it is the responsibility of the developers to set the appropriate `$providerKey` if they want to use the target url saved in the session. Imo this is the right way as the developer should also set the appropriate options for the parent class in the overriding constructor. --------------------------------------------------------------------------- by stof at 2012-07-11T19:01:12Z @asm89 this PR need to be rebased according to github --------------------------------------------------------------------------- by asm89 at 2012-07-11T19:13:09Z @stof Done :) --------------------------------------------------------------------------- by asm89 at 2012-07-12T10:07:53Z @fabpot Done.
-rw-r--r--Http/Authentication/DefaultAuthenticationSuccessHandler.php30
1 files changed, 24 insertions, 6 deletions
diff --git a/Http/Authentication/DefaultAuthenticationSuccessHandler.php b/Http/Authentication/DefaultAuthenticationSuccessHandler.php
index deb7d45..66d6bda 100644
--- a/Http/Authentication/DefaultAuthenticationSuccessHandler.php
+++ b/Http/Authentication/DefaultAuthenticationSuccessHandler.php
@@ -35,13 +35,11 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
* Constructor.
*
* @param HttpUtils $httpUtils
- * @param string $providerKey
* @param array $options Options for processing a successful authentication attempt.
*/
- public function __construct(HttpUtils $httpUtils, $providerKey, array $options)
+ public function __construct(HttpUtils $httpUtils, array $options)
{
$this->httpUtils = $httpUtils;
- $this->providerKey = $providerKey;
$this->options = array_merge(array(
'always_use_default_target_path' => false,
@@ -60,6 +58,27 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
return $this->httpUtils->createRedirectResponse($request, $this->determineTargetUrl($request));
}
+
+ /**
+ * Get the provider key.
+ *
+ * @return string
+ */
+ public function getProviderKey()
+ {
+ return $this->providerKey;
+ }
+
+ /**
+ * Set the provider key.
+ *
+ * @param string $providerKey
+ */
+ public function setProviderKey($providerKey)
+ {
+ $this->providerKey = $providerKey;
+ }
+
/**
* Builds the target URL according to the defined options.
*
@@ -77,9 +96,8 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
return $targetUrl;
}
- $session = $request->getSession();
- if ($targetUrl = $session->get('_security.'.$this->providerKey.'.target_path')) {
- $session->remove('_security.'.$this->providerKey.'.target_path');
+ if (null !== $this->providerKey && $targetUrl = $request->getSession()->get('_security.'.$this->providerKey.'.target_path')) {
+ $request->getSession()->remove('_security.'.$this->providerKey.'.target_path');
return $targetUrl;
}