8000 merged branch asm89/fix-default-auth-successhandler-extension (PR #4865) · sigues/symfony@06f5f07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06f5f07

Browse files
committed
merged branch asm89/fix-default-auth-successhandler-extension (PR symfony#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 8ffaafa 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.
2 parents 3b400ae + 5e6c06f commit 06f5f07

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ protected function createAuthenticationSuccessHandler($container, $id, $config)
175175
$successHandlerId = 'security.authentication.success_handler.'.$id;
176176

177177
$successHandler = $container->setDefinition($successHandlerId, new DefinitionDecorator('security.authentication.success_handler'));
178-
$successHandler->replaceArgument(1, $id);
179-
$successHandler->replaceArgument(2, array_intersect_key($config, $this->defaultSuccessHandlerOptions));
178+
$successHandler->replaceArgument(1, array_intersect_key($config, $this->defaultSuccessHandlerOptions));
179+
$successHandler->addMethodCall('setProviderKey', array($id));
180180

181181
return $successHandlerId;
182182
}

src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110

111111
<service id="security.authentication.success_handler" class="%security.authentication.success_handler.class%" abstract="true" public="false">
112112
<argument type="service" id="security.http_utils" />
113-
<argument />
114113
<argument type="collection" /> <!-- Options -->
115114
</service>
116115

src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
3535
* Constructor.
3636
*
3737
* @param HttpUtils $httpUtils
38-
* @param string $providerKey
3938
* @param array $options Options for processing a successful authentication attempt.
4039
*/
41-
public function __construct(HttpUtils $httpUtils, $providerKey, array $options)
40+
public function __construct(HttpUtils $httpUtils, array $options)
4241
{
4342
$this->httpUtils = $httpUtils;
44-
$this->providerKey = $providerKey;
4543

4644
$this->options = array_merge(array(
4745
'always_use_default_target_path' => false,
@@ -60,6 +58,27 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token)
6058
return $this->httpUtils->createRedirectResponse($request, $this->determineTargetUrl($request));
6159
}
6260

61+
62+
/**
63+
* Get the provider key.
64+
*
65+
* @return string
66+
*/
67+
public function getProviderKey()
68+
{
69+
return $this->providerKey;
70+
}
71+
72+
/**
73+
* Set the provider key.
74+
*
75+
* @param string $providerKey
76+
*/
77+
public function setProviderKey($providerKey)
78+
{
79+
$this->providerKey = $providerKey;
80+
}
81+
6382
/**
6483
* Builds the target URL according to the defined options.
6584
*
@@ -77,9 +96,8 @@ protected function determineTargetUrl(Request $request)
7796
return $targetUrl;
7897
}
7998

80-
$session = $request->getSession();
81-
if ($targetUrl = $session->get('_security.'.$this->providerKey.'.target_path')) {
82-
$session->remove('_security.'.$this->providerKey.'.target_path');
99+
if (null !== $this->providerKey && $targetUrl = $request->getSession()->get('_security.'.$this->providerKey.'.target_path')) {
100+
$request->getSession()->remove('_security.'.$this->providerKey.'.target_path');
83101

84102
return $targetUrl;
85103
}

0 commit comments

Comments
 (0)
0