Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3a5447

Browse filesBrowse files
committed
[SecurityBundle] Lazy load authentication providers
1 parent 1d6a3fe commit f3a5447
Copy full SHA for f3a5447

File tree

4 files changed

+13
-13
lines changed
Filter options

4 files changed

+13
-13
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
1616
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1717
use Symfony\Component\DependencyInjection\Alias;
18+
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1819
use Symfony\Component\DependencyInjection\ChildDefinition;
1920
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2021
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -263,7 +264,7 @@ private function createFirewalls($config, ContainerBuilder $container)
263264
}, array_values(array_unique($authenticationProviders)));
264265
$container
265266
->getDefinition('security.authentication.manager')
266-
->replaceArgument(0, $authenticationProviders)
267+
->replaceArgument(0, new IteratorArgument($authenticationProviders))
267268
;
268269
}
269270

‎src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
<!-- Authentication related services -->
2929
<service id="security.authentication.manager" class="Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager" public="false">
30-
<argument type="collection" />
30+
<argument /> <!-- providers -->
3131
<argument>%security.authentication.manager.erase_credentials%</argument>
3232
<call method="setEventDispatcher">
3333
<argument type="service" id="event_dispatcher" />

‎src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,17 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
3737
/**
3838
* Constructor.
3939
*
40-
* @param AuthenticationProviderInterface[] $providers An array of AuthenticationProviderInterface instances
41-
* @param bool $eraseCredentials Whether to erase credentials after authentication or not
40+
* @param iterable|AuthenticationProviderInterface[] $providers An iterable with AuthenticationProviderInterface instances as values
41+
* @param bool $eraseCredentials Whether to erase credentials after authentication or not
4242
*
4343
* @throws \InvalidArgumentException
4444
*/
45-
public function __construct(array $providers, $eraseCredentials = true)
45+
public function __construct($providers, $eraseCredentials = true)
4646
{
4747
if (!$providers) {
4848
throw new \InvalidArgumentException('You must at least add one authentication provider.');
4949
}
5050

51-
foreach ($providers as $provider) {
52-
if (!$provider instanceof AuthenticationProviderInterface) {
53-
throw new \InvalidArgumentException(sprintf('Provider "%s" must implement the AuthenticationProviderInterface.', get_class($provider)));
54-
}
55-
}
56-
5751
$this->providers = $providers;
5852
$this->eraseCredentials = (bool) $eraseCredentials;
5953
}
@@ -72,6 +66,10 @@ public function authenticate(TokenInterface $token)
7266
$result = null;
7367

7468
foreach ($this->providers as $provider) {
69+
if (!$provider instanceof AuthenticationProviderInterface) {
70+
throw new \InvalidArgumentException(sprintf('Provider "%s" must implement the AuthenticationProviderInterface.', get_class($provider)));
71+
}
72+
7573
if (!$provider->supports($token)) {
7674
continue;
7775
}

‎src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Core/Tests/Authentication/AuthenticationProviderManagerTest.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Security\Core\Exception\ProviderNotFoundException;
1616
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1717
use Symfony\Component\Security\Core\Exception\AccountStatusException;
18+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1819
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1920

2021
class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
@@ -32,9 +33,9 @@ public function testAuthenticateWithoutProviders()
3233
*/
3334
public function testAuthenticateWithProvidersWithIncorrectInterface()
3435
{
35-
new AuthenticationProviderManager(array(
36+
(new AuthenticationProviderManager(array(
3637
new \stdClass(),
37-
));
38+
)))->authenticate($this->getMockBuilder(TokenInterface::class)->getMock());
3839
}
3940

4041
public function testAuthenticateWhenNoProviderSupportsToken()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.