Skip to content

use is_granted() instead of deprecated has_role() #9919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion best_practices/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Using ``@Security``, this looks like:
* Displays a form to create a new Post entity.
*
* @Route("/new", name="admin_post_new")
* @Security("has_role('ROLE_ADMIN')")
* @Security("is_granted('ROLE_ADMIN')")
*/
public function new()
{
Expand Down
2 changes: 1 addition & 1 deletion security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ using annotations::
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

/**
* @Security("has_role('ROLE_ADMIN')")
* @Security("is_granted('ROLE_ADMIN')")
*/
public function hello($name)
{
Expand Down
6 changes: 3 additions & 3 deletions security/access_control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ key:
access_control:
-
path: ^/_internal/secure
allow_if: "'127.0.0.1' == request.getClientIp() or has_role('ROLE_ADMIN')"
allow_if: "'127.0.0.1' == request.getClientIp() or is_granted('ROLE_ADMIN')"

.. code-block:: xml

Expand All @@ -279,7 +279,7 @@ key:

<config>
<rule path="^/_internal/secure"
allow-if="'127.0.0.1' == request.getClientIp() or has_role('ROLE_ADMIN')" />
allow-if="'127.0.0.1' == request.getClientIp() or is_granted('ROLE_ADMIN')" />
</config>
</srv:container>

Expand All @@ -288,7 +288,7 @@ key:
'access_control' => array(
array(
'path' => '^/_internal/secure',
'allow_if' => '"127.0.0.1" == request.getClientIp() or has_role("ROLE_ADMIN")',
'allow_if' => '"127.0.0.1" == request.getClientIp() or is_granted("ROLE_ADMIN")',
),
),

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

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

Expand Down