浏览代码

[Security] small performance optimization

Johannes M. Schmitt 14 年之前
父节点
当前提交
4539b47522

+ 4 - 0
src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php

@@ -59,6 +59,10 @@ class AuthenticationProviderManager implements AuthenticationManagerInterface
 
             try {
                 $result = $provider->authenticate($token);
+
+                if (null !== $result) {
+                    break;
+                }
             } catch (AccountStatusException $e) {
                 $e->setExtraInformation($token);
 

+ 7 - 2
tests/Symfony/Tests/Component/Security/Core/Authentication/AuthenticationProviderManagerTest.php

@@ -80,11 +80,16 @@ class AuthenticationProviderManagerTest extends \PHPUnit_Framework_TestCase
         $this->assertSame($expected, $token);
     }
 
-    public function testAuthenticateReturnsTokenForTheLastMatch()
+    public function testAuthenticateReturnsTokenOfTheFirstMatchingProvider()
     {
+        $second = $this->getMock('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface');
+        $second
+            ->expects($this->never())
+            ->method('supports')
+        ;
         $manager = new AuthenticationProviderManager(array(
-            $this->getAuthenticationProvider(true, $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')),
             $this->getAuthenticationProvider(true, $expected = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')),
+            $second,
         ));
 
         $token = $manager->authenticate($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));