bug #11058 [Security] bug #10242 Missing checkPreAuth from RememberMeAuthenticationProvider (glutamatt)

This PR was submitted for the 2.4 branch but it was merged into the 2.3 branch instead (closes #11058).

Discussion
----------

[Security] bug #10242 Missing checkPreAuth from RememberMeAuthenticationProvider

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10242
| License       | MIT

[Security] fixed missing call to UserChecker::checkPreAuth

edit : after the discution with @hellomedia , i replaced postcheck with precheck
e0730e07ed (commitcomment-6580764)

Commits
-------

a38d1cd bug #10242 Missing checkPreAuth from RememberMeAuthenticationProvider
This commit is contained in:
Fabien Potencier 2014-09-24 17:03:22 +02:00
commit a05a95c30e
2 changed files with 9 additions and 13 deletions

View File

@ -50,7 +50,7 @@ class RememberMeAuthenticationProvider implements AuthenticationProviderInterfac
}
$user = $token->getUser();
$this->userChecker->checkPostAuth($user);
$this->userChecker->checkPreAuth($user);
$authenticatedToken = new RememberMeToken($user, $this->providerKey, $this->key);
$authenticatedToken->setAttributes($token->getAttributes());

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Security\Tests\Core\Authentication\Provider;
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
use Symfony\Component\Security\Core\Exception\DisabledException;
use Symfony\Component\Security\Core\Role\Role;
class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
@ -45,15 +45,14 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
}
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
*/
public function testAuthenticateWhenPostChecksFails()
public function testAuthenticateWhenPreChecksFails()
{
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
$userChecker->expects($this->once())
->method('checkPostAuth')
->will($this->throwException(new AccountExpiredException()))
;
->method('checkPreAuth')
->will($this->throwException(new DisabledException()));
$provider = $this->getProvider($userChecker);
@ -65,8 +64,7 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
$user->expects($this->exactly(2))
->method('getRoles')
->will($this->returnValue(array('ROLE_FOO')))
;
->will($this->returnValue(array('ROLE_FOO')));
$provider = $this->getProvider();
@ -86,16 +84,14 @@ class RememberMeAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
$user
->expects($this->any())
->method('getRoles')
->will($this->returnValue(array()))
;
->will($this->returnValue(array()));
}
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('getProviderKey'), array($user, 'foo', $key));
$token
->expects($this->once())
->method('getProviderKey')
->will($this->returnValue('foo'))
;
->will($this->returnValue('foo'));
return $token;
}