From a309c60dbf256180b6df71bd761e3c6887de364f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Barray?= Date: Wed, 1 Oct 2014 09:53:20 +0200 Subject: [PATCH 1/2] Use the `is_granted` expression to keep consistency with php example above As `has_role` only check for roles without calling the voter, it does not do the same job that `$this->get('security.context')->isGranted('ROLE_ADMIN')` So it is quiete confusing. --- book/security.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/security.rst b/book/security.rst index beb2724fc22..5806de71eae 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1091,7 +1091,7 @@ Thanks to the SensioFrameworkExtraBundle, you can also secure your controller us use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; /** - * @Security("has_role('ROLE_ADMIN')") + * @Security("is_granted('ROLE_ADMIN')") */ public function helloAction($name) { From f96aca8ba7569633bce656a7a10fec6dbb2dd390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Barray?= Date: Mon, 6 Oct 2014 10:05:53 +0200 Subject: [PATCH 2/2] [Security] Add mention to `is_granted` expression --- book/security.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/book/security.rst b/book/security.rst index 5806de71eae..fdf8922a8d0 100644 --- a/book/security.rst +++ b/book/security.rst @@ -1786,6 +1786,8 @@ Additionally, you have access to a number of functions inside the expression: 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``: Similar to the php code like `$securityContext->isGranted('ROLE_USER')`. + Unlike `has_role` expression, `is_granted` will call your custom voters if defined. .. sidebar:: ``is_remember_me`` is different than checking ``IS_AUTHENTICATED_REMEMBERED``