8000 [Security] Remove hard dependency on $providerKey for default auth success handler by asm89 · Pull Request #4865 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
*
Expand All @@ -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;
}
Expand Down
0