@@ -74,15 +74,13 @@ Authorization (i.e. Denying Access)
74
74
-----------------------------------
75
75
76
76
Symfony gives you several ways to enforce authorization, including the ``access_control ``
77
- configuration in :doc: `security.yml </reference/configuration/security >`, the
78
- :ref: `@Security annotation <best-practices-security-annotation >` and using
79
- :ref: `isGranted <best-practices-directly-isGranted >` on the ``security.context ``
77
+ configuration in :doc: `security.yml </reference/configuration/security >` and
78
+ using :ref: `isGranted <best-practices-directly-isGranted >` on the ``security.context ``
80
79
service directly.
81
80
82
81
.. best-practice ::
83
82
84
83
* For protecting broad URL patterns, use ``access_control ``;
85
- * Whenever possible, use the ``@Security `` annotation;
86
84
* Check security directly on the ``security.context `` service whenever
87
85
you have a more complex situation.
88
86
@@ -208,14 +206,13 @@ Now you can reuse this method both in the template and in the security expressio
208
206
{% endif %}
209
207
210
208
.. _best-practices-directly-isGranted :
209
+ .. _checking-permissions-without-security :
211
210
212
- Checking Permissions without @Security
213
- --------------------------------------
211
+ Manually Checking Permissions
212
+ -----------------------------
214
213
215
- The above example with ``@Security `` only works because we're using the
216
- :ref: `ParamConverter <best-practices-paramconverter >`, which gives the expression
217
- access to the a ``post `` variable. If you don't use this, or have some other
218
- more advanced use-case, you can always do the same security check in PHP:
214
+ If you cannot control the access based on URL patterns, you can always do
215
+ the security checks in PHP:
219
216
220
217
.. code-block :: php
221
218
@@ -303,21 +300,7 @@ To enable the security voter in the application, define a new service:
303
300
tags :
304
301
- { name: security.voter }
305
302
306
- Now, you can use the voter with the ``@Security `` annotation:
307
-
308
- .. code-block :: php
309
-
310
- /**
311
- * @Route("/{id}/edit", name="admin_post_edit")
312
- * @Security("is_granted('edit', post)")
313
- */
314
- public function editAction(Post $post)
315
- {
316
- // ...
317
- }
318
-
319
- You can also use this directly with the ``security.context `` service or via
320
- the even easier shortcut in a controller:
303
+ Now, you can use the voter with the ``security.context `` service:
321
304
322
305
.. code-block :: php
323
306
0 commit comments