bug #21791 [SecurityBundle] only pass relevant user provider (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[SecurityBundle] only pass relevant user provider

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #4498, #12465, #20401, #21737
| License       | MIT
| Doc PR        |

There is no need for the context listener to be aware of all the configured user providers. It must only use the provider for the current firewall (the one identified by the context key passed to the constructor) to refresh the user from the session.

Commits
-------

d97e07fd6a [SecurityBundle] only pass relevant user provider
This commit is contained in:
Fabien Potencier 2017-02-27 18:22:58 -08:00
commit eb750be851

View File

@ -214,16 +214,6 @@ class SecurityExtension extends Extension
$firewalls = $config['firewalls'];
$providerIds = $this->createUserProviders($config, $container);
// make the ContextListener aware of the configured user providers
$definition = $container->getDefinition('security.context_listener');
$arguments = $definition->getArguments();
$userProviders = array();
foreach ($providerIds as $userProviderId) {
$userProviders[] = new Reference($userProviderId);
}
$arguments[1] = $userProviders;
$definition->setArguments($arguments);
// load firewall map
$mapDef = $container->getDefinition('security.firewall.map');
$map = $authenticationProviders = array();
@ -288,7 +278,7 @@ class SecurityExtension extends Extension
$contextKey = $firewall['context'];
}
$listeners[] = new Reference($this->createContextListener($container, $contextKey));
$listeners[] = new Reference($this->createContextListener($container, $contextKey, $defaultProvider));
}
// Logout listener
@ -371,7 +361,7 @@ class SecurityExtension extends Extension
return array($matcher, $listeners, $exceptionListener);
}
private function createContextListener($container, $contextKey)
private function createContextListener($container, $contextKey, $providerId)
{
if (isset($this->contextListeners[$contextKey])) {
return $this->contextListeners[$contextKey];
@ -379,6 +369,7 @@ class SecurityExtension extends Extension
$listenerId = 'security.context_listener.'.count($this->contextListeners);
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.context_listener'));
$listener->replaceArgument(1, array(new Reference($providerId)));
$listener->replaceArgument(2, $contextKey);
return $this->contextListeners[$contextKey] = $listenerId;