Explorar el Código

Merge remote branch 'schmittjoh/security'

* schmittjoh/security:
  [Security] added method to retrieve the configured remember-me parameter
  [Security] Copy token attributes when auth providers create a new token from another
Fabien Potencier hace 14 años
padre
commit
c99a44b1e8

+ 4 - 1
src/Symfony/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php

@@ -68,7 +68,10 @@ class PreAuthenticatedAuthenticationProvider implements AuthenticationProviderIn
 
         $this->accountChecker->checkPostAuth($user);
 
-        return new PreAuthenticatedToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
+        $authenticatedToken = new PreAuthenticatedToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
+        $authenticatedToken->setAttributes($token->getAttributes());
+
+        return $authenticatedToken;
     }
 
     /**

+ 4 - 1
src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php

@@ -70,7 +70,10 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter
             $this->checkAuthentication($user, $token);
             $this->accountChecker->checkPostAuth($user);
 
-            return new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
+            $authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
+            $authenticatedToken->setAttributes($token->getAttributes());
+
+            return $authenticatedToken;
         } catch (UsernameNotFoundException $notFound) {
             if ($this->hideUserNotFoundExceptions) {
                 throw new BadCredentialsException('Bad credentials', 0, $notFound);

+ 11 - 0
src/Symfony/Component/Security/Http/RememberMe/RememberMeServices.php

@@ -62,6 +62,17 @@ abstract class RememberMeServices implements RememberMeServicesInterface, Logout
         $this->logger = $logger;
     }
 
+    /**
+     * Returns the parameter that is used for checking whether remember-me
+     * services have been requested.
+     *
+     * @return string
+     */
+    public function getRememberMeParameter()
+    {
+        return $this->options['remember_me_parameter'];
+    }
+
     /**
      * Implementation of RememberMeServicesInterface. Detects whether a remember-me
      * cookie was set, decodes it, and hands it to subclasses for further processing.

+ 3 - 0
tests/Symfony/Tests/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php

@@ -60,6 +60,7 @@ class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_Test
         $this->assertEquals('pass', $token->getCredentials());
         $this->assertEquals('key', $token->getProviderKey());
         $this->assertEquals(array(), $token->getRoles());
+        $this->assertEquals(array('foo' => 'bar'), $token->getAttributes(), '->authenticate() copies token attributes');
         $this->assertSame($user, $token->getUser());
     }
 
@@ -103,6 +104,8 @@ class PreAuthenticatedAuthenticationProviderTest extends \PHPUnit_Framework_Test
             ->will($this->returnValue('key'))
         ;
 
+        $token->setAttributes(array('foo' => 'bar'));
+
         return $token;
     }
 

+ 3 - 0
tests/Symfony/Tests/Component/Security/Core/Authentication/Provider/UserAuthenticationProviderTest.php

@@ -157,6 +157,7 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
         $this->assertSame($user, $authToken->getUser());
         $this->assertEquals(array(new Role('ROLE_FOO')), $authToken->getRoles());
         $this->assertEquals('foo', $authToken->getCredentials());
+        $this->assertEquals(array('foo' => 'bar'), $authToken->getAttributes(), '->authenticate() copies token attributes');
     }
 
     protected function getSupportedToken()
@@ -168,6 +169,8 @@ class UserAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
             ->will($this->returnValue('key'))
         ;
 
+        $mock->setAttributes(array('foo' => 'bar'));
+
         return $mock;
     }
 

+ 7 - 0
tests/Symfony/Tests/Component/Security/Http/RememberMe/RememberMeServicesTest.php

@@ -7,6 +7,13 @@ use Symfony\Component\HttpFoundation\Response;
 
 class RememberMeServicesTest extends \PHPUnit_Framework_TestCase
 {
+    public function testGetRememberMeParameter()
+    {
+        $service = $this->getService(null, array('remember_me_parameter' => 'foo'));
+
+        $this->assertEquals('foo', $service->getRememberMeParameter());
+    }
+
     public function testAutoLoginReturnsNullWhenNoCookie()
     {
         $service = $this->getService(null, array('name' => 'foo'));