Skip to content

Commit ada82a2

Browse files
committed
[Security] fixed pre/post authentication checks
1 parent 63d226d commit ada82a2

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

src/Symfony/Component/Security/Core/User/UserChecker.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ public function checkPreAuth(UserInterface $user)
3232
return;
3333
}
3434

35-
if (!$user->isCredentialsNonExpired()) {
36-
$ex = new CredentialsExpiredException('User credentials have expired.');
37-
$ex->setUser($user);
38-
throw $ex;
39-
}
40-
}
41-
42-
/**
43-
* {@inheritdoc}
44-
*/
45-
public function checkPostAuth(UserInterface $user)
46-
{
47-
if (!$user instanceof AdvancedUserInterface) {
48-
return;
49-
}
50-
5135
if (!$user->isAccountNonLocked()) {
5236
$ex = new LockedException('User account is locked.');
5337
$ex->setUser($user);
@@ -66,4 +50,20 @@ public function checkPostAuth(UserInterface $user)
6650
throw $ex;
6751
}
6852
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function checkPostAuth(UserInterface $user)
58+
{
59+
if (!$user instanceof AdvancedUserInterface) {
60+
return;
61+
}
62+
63+
if (!$user->isCredentialsNonExpired()) {
64+
$ex = new CredentialsExpiredException('User credentials have expired.');
65+
$ex->setUser($user);
66+
throw $ex;
67+
}
68+
}
6969
}

src/Symfony/Component/Security/Tests/Core/User/UserCheckerTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,44 @@
1515

1616
class UserCheckerTest extends \PHPUnit_Framework_TestCase
1717
{
18-
public function testCheckPreAuthNotAdvancedUserInterface()
18+
public function testCheckPostAuthNotAdvancedUserInterface()
1919
{
2020
$checker = new UserChecker();
2121

22-
$this->assertNull($checker->checkPreAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
22+
$this->assertNull($checker->checkPostAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
2323
}
2424

25-
public function testCheckPreAuthPass()
25+
public function testCheckPostAuthPass()
2626
{
2727
$checker = new UserChecker();
2828

2929
$account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
3030
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(true));
3131

32-
$this->assertNull($checker->checkPreAuth($account));
32+
$this->assertNull($checker->checkPostAuth($account));
3333
}
3434

3535
/**
3636
* @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException
3737
*/
38-
public function testCheckPreAuthCredentialsExpired()
38+
public function testCheckPostAuthCredentialsExpired()
3939
{
4040
$checker = new UserChecker();
4141

4242
$account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
4343
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false));
4444

45-
$checker->checkPreAuth($account);
45+
$checker->checkPostAuth($account);
4646
}
4747

48-
public function testCheckPostAuthNotAdvancedUserInterface()
48+
public function testCheckPreAuthNotAdvancedUserInterface()
4949
{
5050
$checker = new UserChecker();
5151

52-
$this->assertNull($checker->checkPostAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
52+
$this->assertNull($checker->checkPreAuth($this->getMock('Symfony\Component\Security\Core\User\UserInterface')));
5353
}
5454

55-
public function testCheckPostAuthPass()
55+
public function testCheckPreAuthPass()
5656
{
5757
$checker = new UserChecker();
5858

@@ -61,40 +61,40 @@ public function testCheckPostAuthPass()
6161
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
6262
$account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(true));
6363

64-
$this->assertNull($checker->checkPostAuth($account));
64+
$this->assertNull($checker->checkPreAuth($account));
6565
}
6666

6767
/**
6868
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
6969
*/
70-
public function testCheckPostAuthAccountLocked()
70+
public function testCheckPreAuthAccountLocked()
7171
{
7272
$checker = new UserChecker();
7373

7474
$account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
7575
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(false));
7676

77-
$checker->checkPostAuth($account);
77+
$checker->checkPreAuth($account);
7878
}
7979

8080
/**
8181
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
8282
*/
83-
public function testCheckPostAuthDisabled()
83+
public function testCheckPreAuthDisabled()
8484
{
8585
$checker = new UserChecker();
8686

8787
$account = $this->getMock('Symfony\Component\Security\Core\User\AdvancedUserInterface');
8888
$account->expects($this->once())->method('isAccountNonLocked')->will($this->returnValue(true));
8989
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(false));
9090

91-
$checker->checkPostAuth($account);
91+
$checker->checkPreAuth($account);
9292
}
9393

9494
/**
9595
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
9696
*/
97-
public function testCheckPostAuthAccountExpired()
97+
public function testCheckPreAuthAccountExpired()
9898
{
9999
$checker = new UserChecker();
100100

@@ -103,6 +103,6 @@ public function testCheckPostAuthAccountExpired()
103103
$account->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
104104
$account->expects($this->once())->method('isAccountNonExpired')->will($this->returnValue(false));
105105

106-
$checker->checkPostAuth($account);
106+
$checker->checkPreAuth($account);
107107
}
108108
}

0 commit comments

Comments
 (0)