Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitf3a5447

Browse files
committed
[SecurityBundle] Lazy load authentication providers
1 parent1d6a3fe commitf3a5447

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
useSymfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
1616
useSymfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1717
useSymfony\Component\DependencyInjection\Alias;
18+
useSymfony\Component\DependencyInjection\Argument\IteratorArgument;
1819
useSymfony\Component\DependencyInjection\ChildDefinition;
1920
useSymfony\Component\HttpKernel\DependencyInjection\Extension;
2021
useSymfony\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,newIteratorArgument($authenticationProviders))
267268
;
268269
}
269270

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

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

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

Lines 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 Anarray of AuthenticationProviderInterface instances
41-
* @param bool $eraseCredentials Whether to erase credentials after authentication or not
40+
* @paramiterable|AuthenticationProviderInterface[] $providers Aniterable with AuthenticationProviderInterface instances as values
41+
* @param bool$eraseCredentials Whether to erase credentials after authentication or not
4242
*
4343
* @throws \InvalidArgumentException
4444
*/
45-
publicfunction__construct(array$providers,$eraseCredentials =true)
45+
publicfunction__construct($providers,$eraseCredentials =true)
4646
{
4747
if (!$providers) {
4848
thrownew \InvalidArgumentException('You must at least add one authentication provider.');
4949
}
5050

51-
foreach ($providersas$provider) {
52-
if (!$providerinstanceof AuthenticationProviderInterface) {
53-
thrownew \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->providersas$provider) {
69+
if (!$providerinstanceof AuthenticationProviderInterface) {
70+
thrownew \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‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
useSymfony\Component\Security\Core\Exception\ProviderNotFoundException;
1616
useSymfony\Component\Security\Core\Exception\AuthenticationException;
1717
useSymfony\Component\Security\Core\Exception\AccountStatusException;
18+
useSymfony\Component\Security\Core\Authentication\Token\TokenInterface;
1819
useSymfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
1920

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

4041
publicfunctiontestAuthenticateWhenNoProviderSupportsToken()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp