|
| 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 webservers, |
| 8 | +including Apache. These modules generally set some environment variables |
| 9 | +that can be used to know which user is accessing your application. Out of the |
| 10 | +box, Symfony supports most authentication mecanisms. |
| 11 | +These are called *pre authenticated* requests because the user is already |
| 12 | +authenticated when reaching your application. |
| 13 | + |
| 14 | +.. note:: |
| 15 | + |
| 16 | + An authentication provider will only inform the user provider of the username |
| 17 | + that made the request. You will need to either use an available |
| 18 | + :class:`Symfony\\Component\\Security\\Core\\User\\UserProviderInterface` |
| 19 | + or implement your own: |
| 20 | + |
| 21 | + * :doc:`/cookbook/security/entity_provider` |
| 22 | + * :doc:`/cookbook/security/custom_provider` |
| 23 | + |
| 24 | +X.509 Client certificate authentication |
| 25 | +--------------------------------------- |
| 26 | + |
| 27 | +When using client certificate, your webserver is doing all the authentication |
| 28 | +process itself. For Apache, on your VirtualHost, you may use the |
| 29 | +``SSLVerifyClient Require`` directive. |
| 30 | + |
| 31 | +On your Symfony2 application security configuration, you can enable the x509 |
| 32 | +authentication firewall: |
| 33 | + |
| 34 | +.. configuration-block:: |
| 35 | + |
| 36 | + .. code-block:: yaml |
| 37 | +
|
| 38 | + # app/config/security.yml |
| 39 | + security: |
| 40 | + firewalls: |
| 41 | + secured_area: |
| 42 | + pattern: ^/ |
| 43 | + x509: |
| 44 | + provider: your_user_provider |
| 45 | +
|
| 46 | + .. code-block:: xml |
| 47 | +
|
| 48 | + <!-- app/config/security.xml --> |
| 49 | + <config> |
| 50 | + <firewall name="secured_area" pattern="^/"> |
| 51 | + <x509 provider="your_user_provider"/> |
| 52 | + </firewall> |
| 53 | + </config> |
| 54 | +
|
| 55 | + .. code-block:: php |
| 56 | +
|
| 57 | + // app/config/security.php |
| 58 | + $container->loadFromExtension('security', array( |
| 59 | + 'firewalls' => array( |
| 60 | + 'secured_area' => array( |
| 61 | + 'pattern' => '^/' |
| 62 | + 'x509' => array( |
| 63 | + 'provider' => 'your_user_provider', |
| 64 | + ), |
| 65 | + ), |
| 66 | + ), |
| 67 | + )); |
| 68 | +
|
| 69 | +By default, the firewall will provide the ``SSL_CLIENT_S_DN_Email`` variable to |
| 70 | +your user provider, and set the ``SSL_CLIENT_S_DN`` as credentials in the |
| 71 | +:class:`Symfony\\Component\\Security\\Core\\Authentication\\Token\\PreAuthenticatedToken`. |
| 72 | +You can override these by setting respectively the ``user`` and the ``credentials`` keys |
| 73 | +in the x509 firewall configuration. |
0 commit comments