Skip to content

Commit 87d312a

Browse files
committed
minor #8735 Updated security/* articles to Symfony 4 (javiereguiluz)
This PR was squashed before being merged into the 4.0 branch (closes #8735). Discussion ---------- Updated security/* articles to Symfony 4 Created the PR to avoid collisions. Commits ------- c40a9d9 Fixed the last references to security.yml b7c987c Updated the main security article a668558 Updated security/* articles to Symfony 4 9c4b9fe (WIP) Updated security/* articles to Symfony 4
2 parents 64c505f + c40a9d9 commit 87d312a

28 files changed

+291
-254
lines changed

security.rst

Lines changed: 78 additions & 71 deletions
Large diffs are not rendered by default.

security/access_control.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Take the following ``access_control`` entries as an example:
3333

3434
.. code-block:: yaml
3535
36-
# app/config/security.yml
36+
# config/packages/security.yaml
3737
security:
3838
# ...
3939
access_control:
@@ -44,7 +44,7 @@ Take the following ``access_control`` entries as an example:
4444
4545
.. code-block:: xml
4646
47-
<!-- app/config/security.xml -->
47+
<!-- config/packages/security.xml -->
4848
<?xml version="1.0" encoding="UTF-8"?>
4949
<srv:container xmlns="http://symfony.com/schema/dic/security"
5050
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -171,7 +171,7 @@ pattern so that it is only accessible by requests from the local server itself:
171171

172172
.. code-block:: yaml
173173
174-
# app/config/security.yml
174+
# config/packages/security.yaml
175175
security:
176176
# ...
177177
access_control:
@@ -181,7 +181,7 @@ pattern so that it is only accessible by requests from the local server itself:
181181
182182
.. code-block:: xml
183183
184-
<!-- app/config/security.xml -->
184+
<!-- config/packages/security.xml -->
185185
<?xml version="1.0" encoding="UTF-8"?>
186186
<srv:container xmlns="http://symfony.com/schema/dic/security"
187187
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -252,7 +252,7 @@ key:
252252

253253
.. code-block:: yaml
254254
255-
# app/config/security.yml
255+
# config/packages/security.yaml
256256
security:
257257
# ...
258258
access_control:
@@ -300,15 +300,15 @@ the user will be redirected to ``https``:
300300

301301
.. code-block:: yaml
302302
303-
# app/config/security.yml
303+
# config/packages/security.yaml
304304
security:
305305
# ...
306306
access_control:
307307
- { path: ^/cart/checkout, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
308308
309309
.. code-block:: xml
310310
311-
<!-- app/config/security.xml -->
311+
<!-- config/packages/security.xml -->
312312
<?xml version="1.0" encoding="UTF-8"?>
313313
<srv:container xmlns="http://symfony.com/schema/dic/security"
314314
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

security/access_denied_handler.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ configure it under your firewall:
3838

3939
.. code-block:: yaml
4040
41-
# app/config/security.yml
41+
# config/packages/security.yaml
4242
firewalls:
4343
# ...
4444
@@ -48,6 +48,7 @@ configure it under your firewall:
4848
4949
.. code-block:: xml
5050
51+
<!-- config/packages/security.xml -->
5152
<config>
5253
<firewall name="main">
5354
<access_denied_handler>App\Security\AccessDeniedHandler</access_denied_handler>

security/api_key_authentication.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ The ``$userProvider`` might look something like this::
211211
Next, make sure this class is registered as a service. If you're using the
212212
:ref:`default services.yaml configuration <service-container-services-load-example>`,
213213
that happens automatically. A little later, you'll reference this service in
214-
your :ref:`security.yml configuration <security-api-key-config>`.
214+
your :ref:`security.yaml configuration <security-api-key-config>`.
215215

216216
.. note::
217217

@@ -292,7 +292,7 @@ and ``provider`` keys:
292292

293293
.. code-block:: yaml
294294
295-
# app/config/security.yml
295+
# config/packages/security.yaml
296296
security:
297297
# ...
298298
@@ -310,7 +310,7 @@ and ``provider`` keys:
310310
311311
.. code-block:: xml
312312
313-
<!-- app/config/security.xml -->
313+
<!-- config/packages/security.xml -->
314314
<?xml version="1.0" encoding="UTF-8"?>
315315
<srv:container xmlns="http://symfony.com/schema/dic/security"
316316
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -364,7 +364,7 @@ If you have defined ``access_control``, make sure to add a new entry:
364364

365365
.. code-block:: yaml
366366
367-
# app/config/security.yml
367+
# config/packages/security.yaml
368368
security:
369369
# ...
370370
@@ -373,7 +373,7 @@ If you have defined ``access_control``, make sure to add a new entry:
373373
374374
.. code-block:: xml
375375
376-
<!-- app/config/security.xml -->
376+
<!-- config/packages/security.xml -->
377377
<?xml version="1.0" encoding="UTF-8"?>
378378
<srv:container xmlns="http://symfony.com/schema/dic/security"
379379
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -423,7 +423,7 @@ configuration or set it to ``false``:
423423

424424
.. code-block:: yaml
425425
426-
# app/config/security.yml
426+
# config/packages/security.yaml
427427
security:
428428
# ...
429429
@@ -435,7 +435,7 @@ configuration or set it to ``false``:
435435
436436
.. code-block:: xml
437437
438-
<!-- app/config/security.xml -->
438+
<!-- config/packages/security.xml -->
439439
<?xml version="1.0" encoding="UTF-8"?>
440440
<srv:container xmlns="http://symfony.com/schema/dic/security"
441441
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

security/csrf_in_login_form.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ file:
2323

2424
.. code-block:: yaml
2525
26-
# app/config/config.yml
26+
# config/packages/framework.yaml
2727
framework:
2828
# ...
29-
csrf_protection: ~
29+
csrf_protection: { enabled: true }
3030
3131
.. code-block:: xml
3232
33-
<!-- app/config/config.xml -->
33+
<!-- config/packages/framework.xml -->
3434
<?xml version="1.0" encoding="UTF-8" ?>
3535
<container xmlns="http://symfony.com/schema/dic/services"
3636
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -47,7 +47,7 @@ file:
4747
4848
.. code-block:: php
4949
50-
// app/config/config.php
50+
// config/packages/framework.php
5151
$container->loadFromExtension('framework', array(
5252
'csrf_protection' => null,
5353
));
@@ -59,7 +59,7 @@ use the default provider available in the security component:
5959

6060
.. code-block:: yaml
6161
62-
# app/config/security.yml
62+
# config/packages/security.yaml
6363
security:
6464
# ...
6565
@@ -72,7 +72,7 @@ use the default provider available in the security component:
7272
7373
.. code-block:: xml
7474
75-
<!-- app/config/security.xml -->
75+
<!-- config/packages/security.xml -->
7676
<?xml version="1.0" encoding="UTF-8" ?>
7777
<srv:container xmlns="http://symfony.com/schema/dic/security"
7878
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -171,7 +171,7 @@ After this, you have protected your login form against CSRF attacks.
171171

172172
.. code-block:: yaml
173173
174-
# app/config/security.yml
174+
# config/packages/security.yaml
175175
security:
176176
# ...
177177
@@ -185,7 +185,7 @@ After this, you have protected your login form against CSRF attacks.
185185
186186
.. code-block:: xml
187187
188-
<!-- app/config/security.xml -->
188+
<!-- config/packages/security.xml -->
189189
<?xml version="1.0" encoding="UTF-8" ?>
190190
<srv:container xmlns="http://symfony.com/schema/dic/security"
191191
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

security/custom_authentication_provider.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ the ``PasswordDigest`` header value matches with the user's password::
255255

256256
// Try to fetch the cache item from pool
257257
$cacheItem = $this->cachePool->getItem(md5($nonce));
258-
258+
259259
// Validate that the nonce is *not* in cache
260260
// if it is, this could be a replay attack
261261
if ($cacheItem->isHit()) {
262262
throw new NonceExpiredException('Previously used nonce detected');
263263
}
264-
264+
265265
// Store the item in cache for 5 minutes
266266
$cacheItem->set(null)->expiresAfter(300);
267267
$this->cachePool->save($cacheItem);

security/custom_password_authenticator.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ inside of it.
131131

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

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

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

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

154154
.. code-block:: yaml
155155
156-
# app/config/security.yml
156+
# config/packages/security.yaml
157157
security:
158158
# ...
159159
@@ -168,7 +168,7 @@ using the ``simple_form`` key:
168168
169169
.. code-block:: xml
170170
171-
<!-- app/config/security.xml -->
171+
<!-- config/packages/security.xml -->
172172
<?xml version="1.0" encoding="UTF-8"?>
173173
<srv:container xmlns="http://symfony.com/schema/dic/security"
174174
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

security/custom_provider.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When a user submits a username and password, the authentication layer asks
99
the configured user provider to return a user object for a given username.
1010
Symfony then checks whether the password of this user is correct and generates
1111
a security token so the user stays authenticated during the current session.
12-
Out of the box, Symfony has four user providers: ``memory``, ``entity``,
12+
Out of the box, Symfony has four user providers: ``memory``, ``entity``,
1313
``ldap`` and ``chain``. In this entry you'll see how you can create your
1414
own user provider, which could be useful if your users are accessed via a
1515
custom database, a file, or - as shown in this example - a web service.
@@ -174,18 +174,18 @@ Now you make the user provider available as a service. If you're using the
174174
:ref:`default services.yaml configuration <service-container-services-load-example>`,
175175
this happens automatically.
176176

177-
Modify ``security.yml``
178-
-----------------------
177+
Modify ``security.yaml``
178+
------------------------
179179

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

184184
.. configuration-block::
185185

186186
.. code-block:: yaml
187187
188-
# app/config/security.yml
188+
# config/packages/security.yaml
189189
security:
190190
# ...
191191
@@ -195,7 +195,7 @@ to the list of providers in the "security" section. Choose a name for the user p
195195
196196
.. code-block:: xml
197197
198-
<!-- app/config/security.xml -->
198+
<!-- config/packages/security.xml -->
199199
<?xml version="1.0" encoding="UTF-8"?>
200200
<srv:container xmlns="http://symfony.com/schema/dic/security"
201201
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -233,7 +233,7 @@ users, e.g. by filling in a login form. You can do this by adding a line to the
233233

234234
.. code-block:: yaml
235235
236-
# app/config/security.yml
236+
# config/packages/security.yaml
237237
security:
238238
# ...
239239
@@ -242,7 +242,7 @@ users, e.g. by filling in a login form. You can do this by adding a line to the
242242
243243
.. code-block:: xml
244244
245-
<!-- app/config/security.xml -->
245+
<!-- config/packages/security.xml -->
246246
<?xml version="1.0" encoding="UTF-8"?>
247247
<srv:container xmlns="http://symfony.com/schema/dic/security"
248248
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -282,7 +282,7 @@ is compared to the hashed password returned by your ``getPassword()`` method.
282282
Symfony uses a specific method to combine the salt and encode the password
283283
before comparing it to your encoded password. If ``getSalt()`` returns
284284
nothing, then the submitted password is simply encoded using the algorithm
285-
you specify in ``security.yml``. If a salt *is* specified, then the following
285+
you specify in ``security.yaml``. If a salt *is* specified, then the following
286286
value is created and *then* hashed via the algorithm::
287287

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

302302
.. code-block:: yaml
303303
304-
# app/config/security.yml
304+
# config/packages/security.yaml
305305
security:
306306
# ...
307307
@@ -312,7 +312,7 @@ is compared to the hashed password returned by your ``getPassword()`` method.
312312
313313
.. code-block:: xml
314314
315-
<!-- app/config/security.xml -->
315+
<!-- config/packages/security.xml -->
316316
<?xml version="1.0" encoding="UTF-8"?>
317317
<srv:container xmlns="http://symfony.com/schema/dic/security"
318318
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

security/entity_provider.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Introduction
2424
Loading users via a Doctrine entity has 2 basic steps:
2525

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

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

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

195195
In this example, the user will enter their username and password via HTTP
196196
basic authentication. Symfony will query for a ``User`` entity matching
@@ -448,7 +448,7 @@ interface only requires one method: ``loadUserByUsername($username)``::
448448
}
449449

450450
To finish this, just remove the ``property`` key from the user provider in
451-
``security.yml``:
451+
``security.yaml``:
452452

453453
.. configuration-block::
454454

0 commit comments

Comments
 (0)