Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UserChecker
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 checkPreAuth
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 checkPostAuth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Identity\Infrastructure\Security;
6
7use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
8use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
9use Symfony\Component\Security\Core\User\UserCheckerInterface;
10use 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 */
18final 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}