1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Security\Core\User;
13:
14: use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
15: use Symfony\Component\Security\Core\Exception\LockedException;
16: use Symfony\Component\Security\Core\Exception\DisabledException;
17: use Symfony\Component\Security\Core\Exception\AccountExpiredException;
18:
19: 20: 21: 22: 23:
24: class UserChecker implements UserCheckerInterface
25: {
26: 27: 28:
29: public function checkPreAuth(UserInterface $user)
30: {
31: if (!$user instanceof AdvancedUserInterface) {
32: return;
33: }
34:
35: if (!$user->isAccountNonLocked()) {
36: $ex = new LockedException('User account is locked.');
37: $ex->setUser($user);
38: throw $ex;
39: }
40:
41: if (!$user->isEnabled()) {
42: $ex = new DisabledException('User account is disabled.');
43: $ex->setUser($user);
44: throw $ex;
45: }
46:
47: if (!$user->isAccountNonExpired()) {
48: $ex = new AccountExpiredException('User account has expired.');
49: $ex->setUser($user);
50: throw $ex;
51: }
52: }
53:
54: 55: 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: }
69: }
70: