@@ -15,15 +15,17 @@ User checkers are classes that must implement the
15
15
:class: `Symfony\\ Component\\ Security\\ Core\\ User\\ UserCheckerInterface `. This interface
16
16
defines two methods called ``checkPreAuth() `` and ``checkPostAuth() `` to
17
17
perform 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::
21
23
22
24
namespace App\Security;
23
25
24
- use App\Exception\AccountDeletedException;
25
26
use App\Security\User as AppUser;
26
27
use Symfony\Component\Security\Core\Exception\AccountExpiredException;
28
+ use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
27
29
use Symfony\Component\Security\Core\User\UserCheckerInterface;
28
30
use Symfony\Component\Security\Core\User\UserInterface;
29
31
@@ -35,9 +37,9 @@ or :class:`Symfony\\Component\\Security\\Core\\Exception\\AuthenticationExceptio
35
37
return;
36
38
}
37
39
38
- // user is deleted, show a generic Account Not Found message.
39
40
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.');
41
43
}
42
44
}
43
45
@@ -54,6 +56,10 @@ or :class:`Symfony\\Component\\Security\\Core\\Exception\\AuthenticationExceptio
54
56
}
55
57
}
56
58
59
+ .. versionadded :: 5.1
60
+
61
+ The ``CustomUserMessageAccountStatusException `` class was introduced in Symfony 5.1.
62
+
57
63
Enabling the Custom User Checker
58
64
--------------------------------
59
65
0 commit comments