Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserChecker | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| checkPreAuth | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| checkPostAuth | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Identity\Infrastructure\Security; |
| 6 | |
| 7 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
| 8 | use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException; |
| 9 | use Symfony\Component\Security\Core\User\UserCheckerInterface; |
| 10 | use Symfony\Component\Security\Core\User\UserInterface; |
| 11 | |
| 12 | /** |
| 13 | * Refuses a suspended account at the authentication boundary. The firewall is |
| 14 | * stateless and reloads the user every request, so checkPreAuth runs for the JWT |
| 15 | * authenticator too — a suspension takes effect on the user's very next request |
| 16 | * (and blocks token refresh), not only at JWT expiry. |
| 17 | */ |
| 18 | final class UserChecker implements UserCheckerInterface |
| 19 | { |
| 20 | public function checkPreAuth(UserInterface $user, ?TokenInterface $token = null): void |
| 21 | { |
| 22 | if ($user instanceof SecurityUser && $user->isSuspended()) { |
| 23 | throw new CustomUserMessageAccountStatusException('Your account is suspended.'); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | public function checkPostAuth(UserInterface $user, ?TokenInterface $token = null): void |
| 28 | { |
| 29 | } |
| 30 | } |