Skip to content

Commit 79db0b9

Browse files
committed
bug #4699 Use new security.authorization_checker service (xelaris)
This PR was merged into the 2.6 branch. Discussion ---------- Use new security.authorization_checker service | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.6+ | Fixed tickets | Replace deprecated `security.context` with the `security.authorization_checker` service. Commits ------- 58f4a00 Use denyAccessUnlessGranted shortcut 8ded86a Use new security.authorization_checker service
2 parents 9c819b4 + 58f4a00 commit 79db0b9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

best_practices/security.rst

+10-6
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ Authorization (i.e. Denying Access)
7575
Symfony gives you several ways to enforce authorization, including the ``access_control``
7676
configuration in :doc:`security.yml </reference/configuration/security>` the
7777
:ref:`@Security annotation <best-practices-security-annotation>` and using
78-
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.context``
78+
:ref:`isGranted <best-practices-directly-isGranted>` on the ``security.authorization_checker``
7979
service directly.
8080

8181
.. best-practice::
8282

8383
* For protecting broad URL patterns, use ``access_control``;
8484
* Whenever possible, use the ``@Security`` annotation;
85-
* Check security directly on the ``security.context`` service whenever
85+
* Check security directly on the ``security.authorization_checker`` service whenever
8686
you have a more complex situation.
8787

8888
There are also different ways to centralize your authorization logic, like
@@ -315,7 +315,7 @@ Now, you can use the voter with the ``@Security`` annotation:
315315
// ...
316316
}
317317
318-
You can also use this directly with the ``security.context`` service, or
318+
You can also use this directly with the ``security.authorization_checker`` service, or
319319
via the even easier shortcut in a controller:
320320

321321
.. code-block:: php
@@ -327,9 +327,13 @@ via the even easier shortcut in a controller:
327327
{
328328
$post = // query for the post ...
329329
330-
if (!$this->get('security.context')->isGranted('edit', $post)) {
331-
throw $this->createAccessDeniedException();
332-
}
330+
$this->denyAccessUnlessGranted('edit', $post);
331+
332+
// or without the shortcut:
333+
//
334+
// if (!$this->get('security.authorization_checker')->isGranted('edit', $post)) {
335+
// throw $this->createAccessDeniedException();
336+
// }
333337
}
334338
335339
Learn More

0 commit comments

Comments
 (0)