@@ -15,15 +15,17 @@ User checkers are classes that must implement the
1515:class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserCheckerInterface `. This interface
1616defines two methods called ``checkPreAuth() `` and ``checkPostAuth() `` to
1717perform checks before and after user authentication. If one or more conditions
18- are not met, an exception should be thrown which extends the
19- :class: `Symfony\\ Component\\ Security\\ Core\\ Exception\\ AccountStatusException `
20- or :class: `Symfony\\ Component\\ Security\\ Core\\ Exception\\ AuthenticationException `::
18+ are not met, throw an exception which extends the
19+ :class: `Symfony\\ Component\\ Security\\ Core\\ Exception\\ AccountStatusException ` class.
20+ Consider using :class: `Symfony\\ Component\\ Security\\ Core\\ Exception\\ CustomUserMessageAccountStatusException `,
21+ which extends ``AccountStatusException `` and allows to customize the error message
22+ displayed to the user::
2123
2224 namespace App\Security;
2325
24- use App\Exception\AccountDeletedException;
2526 use App\Security\User as AppUser;
2627 use Symfony\Component\Security\Core\Exception\AccountExpiredException;
28+ use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
2729 use Symfony\Component\Security\Core\User\UserCheckerInterface;
2830 use Symfony\Component\Security\Core\User\UserInterface;
2931
@@ -35,9 +37,9 @@ or :class:`Symfony\\Component\\Security\\Core\\Exception\\AuthenticationExceptio
3537 return;
3638 }
3739
38- // user is deleted, show a generic Account Not Found message.
3940 if ($user->isDeleted()) {
40- throw new AccountDeletedException();
41+ // the message passed to this exception is meant to be displayed to the user
42+ throw new CustomUserMessageAccountStatusException('Your user account no longer exists.');
4143 }
4244 }
4345
@@ -54,6 +56,10 @@ or :class:`Symfony\\Component\\Security\\Core\\Exception\\AuthenticationExceptio
5456 }
5557 }
5658
59+ .. versionadded :: 5.1
60+
61+ The ``CustomUserMessageAccountStatusException `` class was introduced in Symfony 5.1.
62+
5763Enabling the Custom User Checker
5864--------------------------------
5965
0 commit comments