[Security] Remove hard dependency on $providerKey for default auth success handler

This commit is contained in:
Alexander 2012-07-11 20:32:56 +02:00
parent d4b40fb24b
commit 5e6c06fc70
3 changed files with 26 additions and 9 deletions

View File

@ -175,8 +175,8 @@ abstract class AbstractFactory implements SecurityFactoryInterface
$successHandlerId = 'security.authentication.success_handler.'.$id; $successHandlerId = 'security.authentication.success_handler.'.$id;
$successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.success_handler')); $successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.success_handler'));
$successHandler->replaceArgument(1, $id); $successHandler->replaceArgument(1, array_intersect_key($config, $this->defaultSuccessHandlerOptions));
$successHandler->replaceArgument(2, array_intersect_key($config, $this->defaultSuccessHandlerOptions)); $successHandler->addMethodCall('setProviderKey', array($id));
return $successHandlerId; return $successHandlerId;
} }

View File

@ -110,7 +110,6 @@
<service id="security.authentication.success_handler" class="%security.authentication.success_handler.class%" abstract="true" public="false"> <service id="security.authentication.success_handler" class="%security.authentication.success_handler.class%" abstract="true" public="false">
<argument type="service" id="security.http_utils" /> <argument type="service" id="security.http_utils" />
<argument />
<argument type="collection" /> <!-- Options --> <argument type="collection" /> <!-- Options -->
</service> </service>

View File

@ -35,13 +35,11 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
* Constructor. * Constructor.
* *
* @param HttpUtils $httpUtils * @param HttpUtils $httpUtils
* @param string $providerKey
* @param array $options Options for processing a successful authentication attempt. * @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->httpUtils = $httpUtils;
$this->providerKey = $providerKey;
$this->options = array_merge(array( $this->options = array_merge(array(
'always_use_default_target_path' => false, 'always_use_default_target_path' => false,
@ -60,6 +58,27 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
return $this->httpUtils->createRedirectResponse($request, $this->determineTargetUrl($request)); 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. * Builds the target URL according to the defined options.
* *
@ -77,9 +96,8 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
return $targetUrl; return $targetUrl;
} }
$session = $request->getSession(); if (null !== $this->providerKey && $targetUrl = $request->getSession()->get('_security.'.$this->providerKey.'.target_path')) {
if ($targetUrl = $session->get('_security.'.$this->providerKey.'.target_path')) { $request->getSession()->remove('_security.'.$this->providerKey.'.target_path');
$session->remove('_security.'.$this->providerKey.'.target_path');
return $targetUrl; return $targetUrl;
} }