Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2369c30

Browse filesBrowse files
committed
Updated security/* articles to Symfony 4
1 parent 4c1ddb3 commit 2369c30
Copy full SHA for 2369c30
Expand file treeCollapse file tree

27 files changed

+153
-123
lines changed

‎security/access_control.rst

Copy file name to clipboardExpand all lines: security/access_control.rst
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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"
@@ -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"
@@ -308,7 +308,7 @@ the user will be redirected to ``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

Copy file name to clipboardExpand all lines: security/access_denied_handler.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Copy file name to clipboardExpand all lines: security/api_key_authentication.rst
+4-4Lines changed: 4 additions & 4 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

@@ -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"
@@ -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"
@@ -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

Copy file name to clipboardExpand all lines: security/csrf_in_login_form.rst
+6-6Lines changed: 6 additions & 6 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
));
@@ -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"
@@ -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

Copy file name to clipboardExpand all lines: security/custom_authentication_provider.rst
+2-2Lines 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

Copy file name to clipboardExpand all lines: security/custom_password_authenticator.rst
+3-3Lines changed: 3 additions & 3 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:
@@ -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

Copy file name to clipboardExpand all lines: security/custom_provider.rst
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ 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::
@@ -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"
@@ -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.'}'
@@ -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

Copy file name to clipboardExpand all lines: security/entity_provider.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Want to know more? See :ref:`security-serialize-equatable`.
189189
----------------------------------------------
190190

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

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

454454
To finish this, just remove the ``property`` key from the user provider in
455-
``security.yml``:
455+
``security.yaml``:
456456

457457
.. configuration-block::
458458

‎security/expressions.rst

Copy file name to clipboardExpand all lines: security/expressions.rst
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object::
1515
use Symfony\Component\ExpressionLanguage\Expression;
1616
// ...
1717

18-
public function indexAction()
18+
public function index()
1919
{
2020
$this->denyAccessUnlessGranted(new Expression(
2121
'"ROLE_ADMIN" in roles or (user and user.isSuperAdmin())'
@@ -70,17 +70,20 @@ Additionally, you have access to a number of functions inside the expression:
7070
The ``is_remember_me()`` and ``is_authenticated_fully()`` functions are *similar*
7171
to using ``IS_AUTHENTICATED_REMEMBERED`` and ``IS_AUTHENTICATED_FULLY``
7272
with the ``isGranted()`` function - but they are **not** the same. The
73-
following shows the difference::
73+
following controller snippet shows the difference::
7474

7575
use Symfony\Component\ExpressionLanguage\Expression;
76+
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
7677
// ...
7778

78-
$ac = $this->get('security.authorization_checker');
79-
$access1 = $ac->isGranted('IS_AUTHENTICATED_REMEMBERED');
79+
public function index(AuthorizationCheckerInterface $auth)
80+
{
81+
$access1 = $auth->isGranted('IS_AUTHENTICATED_REMEMBERED');
8082

81-
$access2 = $ac->isGranted(new Expression(
82-
'is_remember_me() or is_fully_authenticated()'
83-
));
83+
$access2 = $auth->isGranted(new Expression(
84+
'is_remember_me() or is_fully_authenticated()'
85+
));
86+
}
8487

8588
Here, ``$access1`` and ``$access2`` will be the same value. Unlike the
8689
behavior of ``IS_AUTHENTICATED_REMEMBERED`` and ``IS_AUTHENTICATED_FULLY``,

‎security/firewall_restriction.rst

Copy file name to clipboardExpand all lines: security/firewall_restriction.rst
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ matches the configured ``pattern``.
3434
3535
.. code-block:: xml
3636
37-
<!-- app/config/security.xml -->
37+
<!-- config/packages/security.xml -->
3838
<?xml version="1.0" encoding="UTF-8"?>
3939
<srv:container xmlns="http://symfony.com/schema/dic/security"
4040
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -91,7 +91,7 @@ only initialize if the host from the request matches against the configuration.
9191
9292
.. code-block:: xml
9393
94-
<!-- app/config/security.xml -->
94+
<!-- config/packages/security.xml -->
9595
<?xml version="1.0" encoding="UTF-8"?>
9696
<srv:container xmlns="http://symfony.com/schema/dic/security"
9797
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -149,7 +149,7 @@ the provided HTTP methods.
149149
150150
.. code-block:: xml
151151
152-
<!-- app/config/security.xml -->
152+
<!-- config/packages/security.xml -->
153153
<?xml version="1.0" encoding="UTF-8"?>
154154
<srv:container xmlns="http://symfony.com/schema/dic/security"
155155
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

‎security/force_https.rst

Copy file name to clipboardExpand all lines: security/force_https.rst
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ to use HTTPS then you could use the following configuration:
2222
2323
.. code-block:: xml
2424
25-
<!-- app/config/security.xml -->
25+
<!-- config/packages/security.xml -->
2626
<?xml version="1.0" encoding="UTF-8"?>
2727
<srv:container xmlns="http://symfony.com/schema/dic/security"
2828
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -70,7 +70,7 @@ role:
7070
7171
.. code-block:: xml
7272
73-
<!-- app/config/security.xml -->
73+
<!-- config/packages/security.xml -->
7474
<?xml version="1.0" encoding="UTF-8"?>
7575
<srv:container xmlns="http://symfony.com/schema/dic/security"
7676
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

‎security/form_login.rst

Copy file name to clipboardExpand all lines: security/form_login.rst
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ a relative/absolute URL or a Symfony route name:
5454
5555
.. code-block:: xml
5656
57-
<!-- app/config/security.xml -->
57+
<!-- config/packages/security.xml -->
5858
<?xml version="1.0" encoding="UTF-8"?>
5959
<srv:container xmlns="http://symfony.com/schema/dic/security"
6060
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -111,7 +111,7 @@ previously requested URL and always redirect to the default page:
111111
112112
.. code-block:: xml
113113
114-
<!-- app/config/security.xml -->
114+
<!-- config/packages/security.xml -->
115115
<?xml version="1.0" encoding="UTF-8"?>
116116
<srv:container xmlns="http://symfony.com/schema/dic/security"
117117
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -211,7 +211,7 @@ parameter is included in the request, you may use the value of the
211211
212212
.. code-block:: xml
213213
214-
<!-- app/config/security.xml -->
214+
<!-- config/packages/security.xml -->
215215
<?xml version="1.0" encoding="UTF-8"?>
216216
<srv:container xmlns="http://symfony.com/schema/dic/security"
217217
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -277,7 +277,7 @@ option to define a new target via a relative/absolute URL or a Symfony route nam
277277
278278
.. code-block:: xml
279279
280-
<!-- app/config/security.xml -->
280+
<!-- config/packages/security.xml -->
281281
<?xml version="1.0" encoding="UTF-8"?>
282282
<srv:container xmlns="http://symfony.com/schema/dic/security"
283283
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -364,7 +364,7 @@ redirects can be customized using the ``target_path_parameter`` and
364364
365365
.. code-block:: xml
366366
367-
<!-- app/config/security.xml -->
367+
<!-- config/packages/security.xml -->
368368
<?xml version="1.0" encoding="UTF-8"?>
369369
<srv:container xmlns="http://symfony.com/schema/dic/security"
370370
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.