Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e6031b

Browse files
committed
use is_granted() instead of deprecated has_role()
Deprecated in symfony/symfony#27305
1 parent 3235d06 commit 5e6031b

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

best_practices/security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Using ``@Security``, this looks like:
121121
* Displays a form to create a new Post entity.
122122
*
123123
* @Route("/new", name="admin_post_new")
124-
* @Security("has_role('ROLE_ADMIN')")
124+
* @Security("is_granted('ROLE_ADMIN')")
125125
*/
126126
public function new()
127127
{

security.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ using annotations::
892892
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
893893

894894
/**
895-
* @Security("has_role('ROLE_ADMIN')")
895+
* @Security("is_granted('ROLE_ADMIN')")
896896
*/
897897
public function hello($name)
898898
{

security/access_control.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ key:
265265
access_control:
266266
-
267267
path: ^/_internal/secure
268-
allow_if: "'127.0.0.1' == request.getClientIp() or has_role('ROLE_ADMIN')"
268+
allow_if: "'127.0.0.1' == request.getClientIp() or is_granted('ROLE_ADMIN')"
269269
270270
.. code-block:: xml
271271
@@ -279,7 +279,7 @@ key:
279279
280280
<config>
281281
<rule path="^/_internal/secure"
282-
allow-if="'127.0.0.1' == request.getClientIp() or has_role('ROLE_ADMIN')" />
282+
allow-if="'127.0.0.1' == request.getClientIp() or is_granted('ROLE_ADMIN')" />
283283
</config>
284284
</srv:container>
285285
@@ -288,7 +288,7 @@ key:
288288
'access_control' => array(
289289
array(
290290
'path' => '^/_internal/secure',
291-
'allow_if' => '"127.0.0.1" == request.getClientIp() or has_role("ROLE_ADMIN")',
291+
'allow_if' => '"127.0.0.1" == request.getClientIp() or is_granted("ROLE_ADMIN")',
292292
),
293293
),
294294

security/expressions.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ Additionally, you have access to a number of functions inside the expression:
6161
Similar, but not equal to ``IS_AUTHENTICATED_REMEMBERED``, see below.
6262
``is_fully_authenticated``
6363
Similar, but not equal to ``IS_AUTHENTICATED_FULLY``, see below.
64-
``has_role``
65-
Checks to see if the user has the given role - equivalent to an expression like
66-
``'ROLE_ADMIN' in roles``.
64+
``is_granted``
65+
Checks if the user has the given permission. Optionally accepts a second argument
66+
with the object where permission is checked on. It's equivalent to using
67+
the :doc:`isGranted() method </security/securing_services>` from the authorization
68+
checker service.
6769

6870
.. sidebar:: ``is_remember_me`` is different than checking ``IS_AUTHENTICATED_REMEMBERED``
6971

0 commit comments

Comments
 (0)