Skip to content

Commit

Permalink
Updated according to the feature modifications
Browse files Browse the repository at this point in the history
Instead of multiple User Checkers, only 1 is configured
  • Loading branch information
Iltar van der Berg committed Oct 1, 2015
1 parent 2a85e4f commit 9d2d604
Showing 1 changed file with 7 additions and 81 deletions.
88 changes: 7 additions & 81 deletions cookbook/security/user_checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ How to Create and Enable Custom User Checkers
=============================================

During the authentication of a user, additional checks might be required to verify
if the identified user is allowed to log in. By defining custom user checkers, you
can define per firewall which checkers should be used.
if the identified user is allowed to log in. By defining a custom user checker, you
can define per firewall which checker should be used.

.. versionadded:: 2.8
Adding custom user checkers was introduced in Symfony 2.8.
Defining a custom user checker was introduced in Symfony 2.8.


Creating a Custom User Checker
Expand Down Expand Up @@ -80,8 +80,7 @@ other service:
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="app.user_checker" class="App\Security\UserChecker">
</service>
<service id="app.user_checker" class="App\Security\UserChecker" />
</services>
</container>
Expand All @@ -107,7 +106,7 @@ is the service id of your user checker:
firewalls:
secured_area:
pattern: ^/
user_checkers: ["app.user_checker"]
user_checker: app.user_checker
# ...
.. code-block:: xml
Expand All @@ -123,7 +122,7 @@ is the service id of your user checker:
<config>
<!-- ... -->
<firewall name="secured_area" pattern="^/">
<user-checkers>app.user_checker</user-checkers>
<user-checker>app.user_checker</user-checker>
<!-- ... -->
</firewall>
</config>
Expand All @@ -138,80 +137,7 @@ is the service id of your user checker:
'firewalls' => array(
'secured_area' => array(
'pattern' => '^/',
'user_checkers' => array('app.user_checker'),
// ...
),
),
));
Additional Configurations
-------------------------

It's possible to add multiple user checkers to one firewall while
configuring only one user checker for another firewall. When adding
multiple user checkers, they are executed in the same sequence as
defined in your configuration.

.. configuration-block::

.. code-block:: yaml
# app/config/security.yml
# ...
security:
firewalls:
admin:
pattern: ^/admin
user_checkers: ["app.user_checker", "app.admin_checker"]
# ...
secured_area:
pattern: ^/
user_checkers: ["app.user_checker"]
.. code-block:: xml
<!-- app/config/security.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<srv:container xmlns="http://symfony.com/schema/dic/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">
<config>
<!-- ... -->
<firewall name="admin" pattern="^/admin">
<user-checkers>app.user_checker</user-checkers>
<user-checkers>app.admin_checker</user-checkers>
<!-- ... -->
</firewall>
<firewall name="secured_area" pattern="^/">
<user-checkers>app.user_checker</user-checkers>
<!-- ... -->
</firewall>
</config>
</srv:container>
.. code-block:: php
// app/config/security.php
// ...
$container->loadFromExtension('security', array(
'firewalls' => array(
'admin' => array(
'pattern' => '^/admin',
'user_checkers' => array(
'app.user_checker',
'app.admin_checker',
),
// ...
),
'secured_area' => array(
'pattern' => '^/',
'user_checkers' => array('app.user_checker'),
'user_checker' => 'app.user_checker',
// ...
),
),
Expand Down

0 comments on commit 9d2d604

Please sign in to comment.