@@ -9,24 +9,28 @@ if the identified user is allowed to log in. By defining a custom user checker,
9
9
can define per firewall which checker should be used.
10
10
11
11
.. versionadded :: 2.8
12
- Defining a custom user checker was introduced in Symfony 2.8.
13
-
12
+ The ability to configure a custom user checker per firewall was introduced
13
+ in Symfony 2.8.
14
14
15
15
Creating a Custom User Checker
16
16
------------------------------
17
17
18
- User checkers are defined in PHP classes that must implement the
19
- :class: `UserCheckerInterface Symfony\\ Component\\ Security\\ Core\\ UserCheckerInterface `.
20
- This interface defines two methods called ``checkPreAuth() `` and ``checkPostAuth() ``
21
- to perform checks before and after user authentication. If one or more
22
- conditions are not met, an exception should be thrown which extends the
23
- :class: `AccountStatusException Symfony\\ Component\\ Security\\ Core\\ Exception\\ AccountStatusException `
18
+ User checkers are classes that must implement the
19
+ :class: `Symfony\\ Component\\ Security\\ Core\\ UserCheckerInterface `. This interface
20
+ defines two methods called ``checkPreAuth() `` and ``checkPostAuth() `` to
21
+ perform checks before and after user authentication. If one or more conditions
22
+ are not met, an exception should be thrown which extends the
23
+ :class: `Symfony\\ Component\\ Security\\ Core\\ Exception\\ AccountStatusException `.
24
24
25
25
.. code-block :: php
26
26
27
- namespace App \Security;
27
+ namespace AppBundle \Security;
28
28
29
+ use AppBundle\Exception\AccountDeletedException;
30
+ use AppBundle\Security\User as AppUser;
31
+ use Symfony\Component\Security\Core\Exception\AccountExpiredException;
29
32
use Symfony\Component\Security\Core\User\UserCheckInterface;
33
+ use Symfony\Component\Security\Core\User\UserInterface;
30
34
31
35
class UserChecker implements UserCheckerInterface
32
36
{
@@ -69,7 +73,7 @@ other service:
69
73
# app/config/services.yml
70
74
services :
71
75
app.user_checker :
72
- class : App \Security\UserChecker
76
+ class : AppBundle \Security\UserChecker
73
77
74
78
.. code-block :: xml
75
79
@@ -80,17 +84,14 @@ other service:
80
84
xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
81
85
82
86
<services >
83
- <service id =" app.user_checker" class =" App \Security\UserChecker" />
87
+ <service id =" app.user_checker" class =" AppBundle \Security\UserChecker" />
84
88
</services >
85
89
</container >
86
90
87
91
.. code-block :: php
88
92
89
93
// app/config/services.php
90
- use Symfony\Component\DependencyInjection\Definition;
91
-
92
- $userChecker = new Definition('App\Security\UserChecker');
93
- $container->setDefinition('app.user_checker', $userChecker);
94
+ $container->register('app.user_checker', 'AppBundle\Security\UserChecker');
94
95
95
96
All that's left to do is add the checker to the desired firewall where the value
96
97
is the service id of your user checker:
@@ -211,5 +212,5 @@ It's possible to have a different user checker per firewall.
211
212
212
213
.. note ::
213
214
214
- Internally the user checkers are aliased per firewall. For `secured_area ` the alias
215
- ` security.user_checker.secured_area ` would point to `app.user_checker `.
215
+ Internally the user checkers are aliased per firewall. For `` secured_area ``
216
+ the alias `` security.user_checker.secured_area `` would point to `` app.user_checker ` `.
0 commit comments