8000 [Security] Remove hard dependency on $providerKey for default auth su… · sigues/symfony@5e6c06f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e6c06f

Browse files
committed
[Security] Remove hard dependency on $providerKey for default auth success handler
1 parent d4b40fb commit 5e6c06f

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