diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2013-12-30 22:49:15 +0100 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2013-12-31 11:55:25 +0100 |
commit | f3427fa7d44637866e038bf49ae336509e99800b (patch) | |
tree | 9c05b8561074da10ab033cc31e7b63652fea6f65 | |
parent | 47a99c77ac4ea45ab1e20b3d95450cd39204e123 (diff) | |
download | symfony-security-f3427fa7d44637866e038bf49ae336509e99800b.zip symfony-security-f3427fa7d44637866e038bf49ae336509e99800b.tar.gz symfony-security-f3427fa7d44637866e038bf49ae336509e99800b.tar.bz2 |
[Security] fixed pre/post authentication checks
-rw-r--r-- | Core/User/UserChecker.php | 32 | ||||
-rw-r--r-- | Tests/Core/User/UserCheckerTest.php | 32 |
2 files changed, 32 insertions, 32 deletions
diff --git a/Core/User/UserChecker.php b/Core/User/UserChecker.php index 8dde3a6..ac577a3 100644 --- a/Core/User/UserChecker.php +++ b/Core/User/UserChecker.php @@ -32,22 +32,6 @@ class UserChecker implements UserCheckerInterface return; } - if (!$user->isCredentialsNonExpired()) { - $ex = new CredentialsExpiredException('User credentials have expired.'); - $ex->setUser($user); - throw $ex; - } - } - - /** - * {@inheritdoc} - */ - public function checkPostAuth(UserInterface $user) - { - if (!$user instanceof AdvancedUserInterface) { - return; - } - if (!$user->isAccountNonLocked()) { $ex = new LockedException('User account is locked.'); $ex->setUser($user); @@ -66,4 +50,20 @@ class UserChecker implements UserCheckerInterface throw $ex; } } + + /** + * {@inheritdoc} + */ + public function checkPostAuth(UserInterface $user) + { + if (!$user instanceof AdvancedUserInterface) { + return; + } + + if (!$user->isCredentialsNonExpired()) { + $ex = new CredentialsExpiredException('User credentials have expired.'); + $ex->setUser($user); + throw $ex; + } + } } diff --git a/Tests/Core/User/UserCheckerTest.php b/Tests/Core/User/UserCheckerTest.php index f28067f..dca6311 100644 --- a/Tests/Core/User/UserCheckerTest.php +++ b/Tests/Core/User/UserCheckerTest.php @@ -15,44 +15,44 @@ use Symfony\Component\Security\Core\User\UserChecker; class UserCheckerTest extends \PHPUnit_Framework_TestCase { - public function testCheckPreAuthNotAdvancedUserInterface() + public function testCheckPostAuthNotAdvancedUserInterface() { $checker = new UserChecker(); - $this->assertNull($checker->checkPreAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface'))); + $this->assertNull($checker->checkPostAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface'))); } - public function testCheckPreAuthPass() + public function testCheckPostAuthPass() { $checker = new UserChecker(); $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface'); $account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(true)); - $this->assertNull($checker->checkPreAuth($account)); + $this->assertNull($checker->checkPostAuth($account)); } /** * @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException */ - public function testCheckPreAuthCredentialsExpired() + public function testCheckPostAuthCredentialsExpired() { $checker = new UserChecker(); $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface'); $account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false)); - $checker->checkPreAuth($account); + $checker->checkPostAuth($account); } - public function testCheckPostAuthNotAdvancedUserInterface() + public function testCheckPreAuthNotAdvancedUserInterface() { $checker = new UserChecker(); - $this->assertNull($checker->checkPostAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface'))); + $this->assertNull($checker->checkPreAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface'))); } - public function testCheckPostAuthPass() + public function testCheckPreAuthPass() { $checker = new UserChecker(); @@ -61,26 +61,26 @@ class UserCheckerTest extends \PHPUnit_Framework_TestCase $account->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(true)); - $this->assertNull($checker->checkPostAuth($account)); + $this->assertNull($checker->checkPreAuth($account)); } /** * @expectedException \Symfony\Component\Security\Core\Exception\LockedException */ - public function testCheckPostAuthAccountLocked() + public function testCheckPreAuthAccountLocked() { $checker = new UserChecker(); $account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface'); $account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(false)); - $checker->checkPostAuth($account); + $checker->checkPreAuth($account); } /** * @expectedException \Symfony\Component\Security\Core\Exception\DisabledException */ - public function testCheckPostAuthDisabled() + public function testCheckPreAuthDisabled() { $checker = new UserChecker(); @@ -88,13 +88,13 @@ class UserCheckerTest extends \PHPUnit_Framework_TestCase $account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true)); $account->expects($this->once())->method('isEnabled')->will($this->returnValue(false)); - $checker->checkPostAuth($account); + $checker->checkPreAuth($account); } /** * @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException */ - public function testCheckPostAuthAccountExpired() + public function testCheckPreAuthAccountExpired() { $checker = new UserChecker(); @@ -103,6 +103,6 @@ class UserCheckerTest extends \PHPUnit_Framework_TestCase $account->expects($this->once())->method('isEnabled')->will($this->returnValue(true)); $account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(false)); - $checker->checkPostAuth($account); + $checker->checkPreAuth($account); } } |