@@ -9,24 +9,28 @@ if the identified user is allowed to log in. By defining a custom user checker,
99can define per firewall which checker should be used.
1010
1111.. 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.
1414
1515Creating a Custom User Checker
1616------------------------------
1717
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 `.
2424
2525.. code-block :: php
2626
27- namespace App \Security;
27+ namespace AppBundle \Security;
2828
29+ use AppBundle\Exception\AccountDeletedException;
30+ use AppBundle\Security\User as AppUser;
31+ use Symfony\Component\Security\Core\Exception\AccountExpiredException;
2932 use Symfony\Component\Security\Core\User\UserCheckInterface;
33+ use Symfony\Component\Security\Core\User\UserInterface;
3034
3135 class UserChecker implements UserCheckerInterface
3236 {
@@ -69,7 +73,7 @@ other service:
6973 # app/config/services.yml
7074 services :
7175 app.user_checker :
72- class : App \Security\UserChecker
76+ class : AppBundle \Security\UserChecker
7377
7478 .. code-block :: xml
7579
@@ -80,17 +84,14 @@ other service:
8084 xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
8185
8286 <services >
83- <service id =" app.user_checker" class =" App \Security\UserChecker" />
87+ <service id =" app.user_checker" class =" AppBundle \Security\UserChecker" />
8488 </services >
8589 </container >
8690
8791 .. code-block :: php
8892
8993 // 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');
9495
9596 All that's left to do is add the checker to the desired firewall where the value
9697is the service id of your user checker:
@@ -211,5 +212,5 @@ It's possible to have a different user checker per firewall.
211212
212213 .. note ::
213214
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