This repository was archived by the owner on May 31, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -37,23 +37,17 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
37
37
/**
38
38
* Constructor.
39
39
*
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
42
42
*
43
43
* @throws \InvalidArgumentException
44
44
*/
45
- public function __construct (array $ providers , $ eraseCredentials = true )
45
+ public function __construct ($ providers , $ eraseCredentials = true )
46
46
{
47
47
if (!$ providers ) {
48
48
throw new \InvalidArgumentException ('You must at least add one authentication provider. ' );
49
49
}
50
50
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
-
57
51
$ this ->providers = $ providers ;
58
52
$ this ->eraseCredentials = (bool ) $ eraseCredentials ;
59
53
}
@@ -72,6 +66,10 @@ public function authenticate(TokenInterface $token)
72
66
$ result = null ;
73
67
74
68
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
+
75
73
if (!$ provider ->supports ($ token )) {
76
74
continue ;
77
75
}
Original file line number Diff line number Diff line change 15
15
use Symfony \Component \Security \Core \Exception \ProviderNotFoundException ;
16
16
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
17
17
use Symfony \Component \Security \Core \Exception \AccountStatusException ;
18
+ use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
18
19
use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
19
20
20
21
class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
@@ -32,9 +33,9 @@ public function testAuthenticateWithoutProviders()
32
33
*/
33
34
public function testAuthenticateWithProvidersWithIncorrectInterface ()
34
35
{
35
- new AuthenticationProviderManager (array (
36
+ ( new AuthenticationProviderManager (array (
36
37
new \stdClass (),
37
- ));
38
+ )))-> authenticate ( $ this -> getMockBuilder (TokenInterface::class)-> getMock ()) ;
38
39
}
39
40
40
41
public function testAuthenticateWhenNoProviderSupportsToken ()
You can’t perform that action at this time.
0 commit comments