Skip to content

Commit 1d5c229

Browse files
bug symfony#26009 [SecurityBundle] Allow remember-me factory creation when multiple user providers are configured. (iisisrael)
This PR was merged into the 3.4 branch. Discussion ---------- [SecurityBundle] Allow remember-me factory creation when multiple user providers are configured. | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | none When more than one user provider is configured, and `remember_me` is enabled on a firewall, this avoids the deprecation notice in 3.4 and thrown `InvalidConfigurationException` in 4.0 ("Not configuring explicitly the provider for the "remember_me" listener on "foo" firewall is ambiguous as there is more than one registered provider."). The `RememberMeFactory` ignores the `$userProvider` argument and uses the secret configured for the firewall. (If no secret is configured, it throws its own exception.) The added test passes in 3.4 with a deprecation notice without the change, so would expect it to fail in 4.0 without the change. Other tests in the `SecurityBundle` already included two errors and one failure, not related to this change. Commits ------- 6ab8dd9 Allow remember-me factory creation when multiple user providers are configured.
2 parents 003e616 + 6ab8dd9 commit 1d5c229

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ private function createAuthenticationListeners($container, $id, $firewall, &$aut
515515
throw new InvalidConfigurationException(sprintf('Invalid firewall "%s": user provider "%s" not found.', $id, $firewall[$key]['provider']));
516516
}
517517
$userProvider = $providerIds[$normalizedName];
518+
} elseif ('remember_me' === $key) {
519+
// RememberMeFactory will use the firewall secret when created
520+
$userProvider = null;
518521
} else {
519522
$userProvider = $defaultProvider ?: $this->getFirstProvider($id, $key, $providerIds);
520523
}

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ public function testPerListenerProvider()
259259
$this->addToAssertionCount(1);
260260
}
261261

262+
public function testPerListenerProviderWithRememberMe()
263+
{
264+
$container = $this->getRawContainer();
265+
$container->loadFromExtension('security', array(
266+
'providers' => array(
267+
'first' => array('id' => 'foo'),
268+
'second' => array('id' => 'bar'),
269+
),
270+
271+
'firewalls' => array(
272+
'default' => array(
273+
'form_login' => array('provider' => 'second'),
274+
'logout_on_user_change' => true,
275+
'remember_me' => array('secret' => 'baz'),
276+
),
277+
),
278+
));
279+
280+
$container->compile();
281+
$this->addToAssertionCount(1);
282+
}
283+
262284
protected function getRawContainer()
263285
{
264286
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)