|
| 1 | +.. index:: |
| 2 | + single: Security; Pre authenticated providers |
| 3 | + |
| 4 | +Using pre Authenticated Security Firewalls |
| 5 | +========================================== |
| 6 | + |
| 7 | +A lot of authentication modules are already provided by some web servers, |
| 8 | +including Apache. These modules generally set some environment variables |
| 9 | +that can be used to determine which user is accessing your application. Out of the |
| 10 | +box, Symfony supports most authentication mechanisms. |
| 11 | +These requests are called *pre authenticated* requests because the user is already |
| 12 | +authenticated when reaching your application. |
| 13 | + |
| 14 | +X.509 Client Certificate Authentication |
| 15 | +--------------------------------------- |
| 16 | + |
| 17 | +When using client certificates, your webserver is doing all the authentication |
| 18 | +process itself. With Apache, for example, you would use the |
| 19 | +``SSLVerifyClient Require`` directive. |
| 20 | + |
| 21 | +Enable the x509 authentication for a particular firewall in the security configuration: |
| 22 | + |
| 23 | +.. configuration-block:: |
| 24 | + |
| 25 | + .. code-block:: yaml |
| 26 | +
|
| 27 | + # app/config/security.yml |
| 28 | + security: |
| 29 | + firewalls: |
| 30 | + secured_area: |
| 31 | + pattern: ^/ |
| 32 | + x509: |
| 33 | + provider: your_user_provider |
| 34 | +
|
| 35 | + .. code-block:: xml |
| 36 | +
|
| 37 | + <?xml version="1.0" ?> |
| 38 | + <!-- app/config/security.xml --> |
| 39 | + <srv:container xmlns="http://symfony.com/schema/dic/security" |
| 40 | + xmlns:srv="http://symfony.com/schema/dic/services"> |
| 41 | +
|
| 42 | + <config> |
| 43 | + <firewall name="secured_area" pattern="^/"> |
| 44 | + <x509 provider="your_user_provider"/> |
| 45 | + </firewall> |
| 46 | + </config> |
| 47 | + </srv:container> |
| 48 | +
|
| 49 | + .. code-block:: php |
| 50 | +
|
| 51 | + // app/config/security.php |
| 52 | + $container->loadFromExtension('security', array( |
| 53 | + 'firewalls' => array( |
| 54 | + 'secured_area' => array( |
| 55 | + 'pattern' => '^/' |
| 56 | + 'x509' => array( |
| 57 | + 'provider' => 'your_user_provider', |
| 58 | + ), |
| 59 | + ), |
| 60 | + ), |
| 61 | + )); |
| 62 | +
|
| 63 | +By default, the firewall provides the ``SSL_CLIENT_S_DN_Email`` variable to |
| 64 | +the user provider, and sets the ``SSL_CLIENT_S_DN`` as credentials in the |
| 65 | +:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\PreAuthenticatedToken`. |
| 66 | +You can override these by setting the ``user`` and the ``credentials`` keys |
| 67 | +in the x509 firewall configuration respectively. |
| 68 | + |
| 69 | +.. note:: |
| 70 | + |
| 71 | + An authentication provider will only inform the user provider of the username |
| 72 | + that made the request. You will need to create (or use) a "user provider" that |
| 73 | + turns that username into a User object of your choice: |
| 74 | + |
| 75 | + * :doc:`/cookbook/security/custom_provider` |
| 76 | + * :doc:`/cookbook/security/entity_provider` |
0 commit comments