From 5e6c06fc708b10a20946dc4637af8235e042f214 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 11 Jul 2012 20:32:56 +0200 Subject: [PATCH] [Security] Remove hard dependency on $providerKey for default auth success handler --- .../Security/Factory/AbstractFactory.php | 4 +-- .../Resources/config/security_listeners.xml | 1 - .../DefaultAuthenticationSuccessHandler.php | 30 +++++++++++++++---- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php index 87fbb30d1f02..a83de659f27a 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php @@ -175,8 +175,8 @@ protected function createAuthenticationSuccessHandler($container, $id, $config) $successHandlerId = 'security.authentication.success_handler.'.$id; $successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.success_handler')); - $successHandler->replaceArgument(1, $id); - $successHandler->replaceArgument(2, array_intersect_key($config, $this->defaultSuccessHandlerOptions)); + $successHandler->replaceArgument(1, array_intersect_key($config, $this->defaultSuccessHandlerOptions)); + $successHandler->addMethodCall('setProviderKey', array($id)); return $successHandlerId; } diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml index cb3f45f77a90..44644c9b3cf1 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml @@ -110,7 +110,6 @@ - diff --git a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php index deb7d4574a82..66d6bdacb231 100644 --- a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php +++ b/src/Symfony/Component/Security/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 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token) 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 @@ protected function determineTargetUrl(Request $request) 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; }