Skip to content

Updated security/* articles to Symfony 4 #8735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 78 additions & 71 deletions security.rst

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions security/access_control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Take the following ``access_control`` entries as an example:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...
access_control:
Expand All @@ -44,7 +44,7 @@ Take the following ``access_control`` entries as an example:

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down Expand Up @@ -171,7 +171,7 @@ pattern so that it is only accessible by requests from the local server itself:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...
access_control:
Expand All @@ -181,7 +181,7 @@ pattern so that it is only accessible by requests from the local server itself:

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down Expand Up @@ -252,7 +252,7 @@ key:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...
access_control:
Expand Down Expand Up @@ -300,15 +300,15 @@ the user will be redirected to ``https``:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...
access_control:
- { path: ^/cart/checkout, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down
3 changes: 2 additions & 1 deletion security/access_denied_handler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ configure it under your firewall:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
firewalls:
# ...

Expand All @@ -48,6 +48,7 @@ configure it under your firewall:

.. code-block:: xml

<!-- config/packages/security.xml -->
<config>
<firewall name="main">
<access_denied_handler>App\Security\AccessDeniedHandler</access_denied_handler>
Expand Down
14 changes: 7 additions & 7 deletions security/api_key_authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ The ``$userProvider`` might look something like this::
Next, make sure this class is registered as a service. If you're using the
:ref:`default services.yaml configuration <service-container-services-load-example>`,
that happens automatically. A little later, you'll reference this service in
your :ref:`security.yml configuration <security-api-key-config>`.
your :ref:`security.yaml configuration <security-api-key-config>`.

.. note::

Expand Down Expand Up @@ -292,7 +292,7 @@ and ``provider`` keys:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -310,7 +310,7 @@ and ``provider`` keys:

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down Expand Up @@ -364,7 +364,7 @@ If you have defined ``access_control``, make sure to add a new entry:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -373,7 +373,7 @@ If you have defined ``access_control``, make sure to add a new entry:

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down Expand Up @@ -423,7 +423,7 @@ configuration or set it to ``false``:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -435,7 +435,7 @@ configuration or set it to ``false``:

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down
16 changes: 8 additions & 8 deletions security/csrf_in_login_form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ file:

.. code-block:: yaml

# app/config/config.yml
# config/packages/framework.yaml
framework:
# ...
csrf_protection: ~
csrf_protection: { enabled: true }

.. code-block:: xml

<!-- app/config/config.xml -->
<!-- config/packages/framework.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -47,7 +47,7 @@ file:

.. code-block:: php

// app/config/config.php
// config/packages/framework.php
$container->loadFromExtension('framework', array(
'csrf_protection' => null,
));
Expand All @@ -59,7 +59,7 @@ use the default provider available in the security component:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -72,7 +72,7 @@ use the default provider available in the security component:

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down Expand Up @@ -171,7 +171,7 @@ After this, you have protected your login form against CSRF attacks.

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -185,7 +185,7 @@ After this, you have protected your login form against CSRF attacks.

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down
4 changes: 2 additions & 2 deletions security/custom_authentication_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ the ``PasswordDigest`` header value matches with the user's password::

// Try to fetch the cache item from pool
$cacheItem = $this->cachePool->getItem(md5($nonce));

// Validate that the nonce is *not* in cache
// if it is, this could be a replay attack
if ($cacheItem->isHit()) {
throw new NonceExpiredException('Previously used nonce detected');
}

// Store the item in cache for 5 minutes
$cacheItem->set(null)->expiresAfter(300);
$this->cachePool->save($cacheItem);
Expand Down
8 changes: 4 additions & 4 deletions security/custom_password_authenticator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ inside of it.

Inside this method, the password encoder is needed to check the password's validity::

$passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
$passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());

This is a service that is already available in Symfony and it uses the password algorithm
that is configured in the security configuration (e.g. ``security.yml``) under
that is configured in the security configuration (e.g. ``security.yaml``) under
the ``encoders`` key. Below, you'll see how to inject that into the ``TimeAuthenticator``.

.. _security-password-authenticator-config:
Expand All @@ -153,7 +153,7 @@ using the ``simple_form`` key:

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -168,7 +168,7 @@ using the ``simple_form`` key:

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down
22 changes: 11 additions & 11 deletions security/custom_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When a user submits a username and password, the authentication layer asks
the configured user provider to return a user object for a given username.
Symfony then checks whether the password of this user is correct and generates
a security token so the user stays authenticated during the current session.
Out of the box, Symfony has four user providers: ``memory``, ``entity``,
Out of the box, Symfony has four user providers: ``memory``, ``entity``,
``ldap`` and ``chain``. In this entry you'll see how you can create your
own user provider, which could be useful if your users are accessed via a
custom database, a file, or - as shown in this example - a web service.
Expand Down Expand Up @@ -174,18 +174,18 @@ Now you make the user provider available as a service. If you're using the
:ref:`default services.yaml configuration <service-container-services-load-example>`,
this happens automatically.

Modify ``security.yml``
-----------------------
Modify ``security.yaml``
------------------------

Everything comes together in your security configuration. Add the user provider
to the list of providers in the "security" section. Choose a name for the user provider
to the list of providers in the "security" config. Choose a name for the user provider
(e.g. "webservice") and mention the ``id`` of the service you just defined.

.. configuration-block::

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -195,7 +195,7 @@ to the list of providers in the "security" section. Choose a name for the user p

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down Expand Up @@ -233,7 +233,7 @@ users, e.g. by filling in a login form. You can do this by adding a line to the

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -242,7 +242,7 @@ users, e.g. by filling in a login form. You can do this by adding a line to the

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down Expand Up @@ -282,7 +282,7 @@ is compared to the hashed password returned by your ``getPassword()`` method.
Symfony uses a specific method to combine the salt and encode the password
before comparing it to your encoded password. If ``getSalt()`` returns
nothing, then the submitted password is simply encoded using the algorithm
you specify in ``security.yml``. If a salt *is* specified, then the following
you specify in ``security.yaml``. If a salt *is* specified, then the following
value is created and *then* hashed via the algorithm::

$password.'{'.$salt.'}'
Expand All @@ -301,7 +301,7 @@ is compared to the hashed password returned by your ``getPassword()`` method.

.. code-block:: yaml

# app/config/security.yml
# config/packages/security.yaml
security:
# ...

Expand All @@ -312,7 +312,7 @@ is compared to the hashed password returned by your ``getPassword()`` method.

.. code-block:: xml

<!-- app/config/security.xml -->
<!-- config/packages/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"
Expand Down
6 changes: 3 additions & 3 deletions security/entity_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Introduction
Loading users via a Doctrine entity has 2 basic steps:

#. :ref:`Create your User entity <security-crete-user-entity>`
#. :ref:`Configure security.yml to load from your entity <security-config-entity-provider>`
#. :ref:`Configure security.yaml to load from your entity <security-config-entity-provider>`

Afterwards, you can learn more about :ref:`forbidding inactive users <security-advanced-user-interface>`,
:ref:`using a custom query <authenticating-someone-with-a-custom-entity-provider>`
Expand Down Expand Up @@ -189,7 +189,7 @@ Want to know more? See :ref:`security-serialize-equatable`.
----------------------------------------------

Now that you have a ``User`` entity that implements ``UserInterface``, you
just need to tell Symfony's security system about it in ``security.yml``.
just need to tell Symfony's security system about it in ``security.yaml``.

In this example, the user will enter their username and password via HTTP
basic authentication. Symfony will query for a ``User`` entity matching
Expand Down Expand Up @@ -452,7 +452,7 @@ interface only requires one method: ``loadUserByUsername($username)``::
:doc:`mapping definition of your entity </doctrine/repository>`.

To finish this, just remove the ``property`` key from the user provider in
``security.yml``:
``security.yaml``:

.. configuration-block::

Expand Down
Loading