diff --git a/security.rst b/security.rst
index 87d1a029c7d..5049a1eb78d 100644
--- a/security.rst
+++ b/security.rst
@@ -964,7 +964,7 @@ You can also use expressions inside your templates:
.. code-block:: html+jinja
{% if is_granted(expression(
- '"ROLE_ADMIN" in roles or (user and user.isSuperAdmin())'
+ '"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
)) %}
Delete
{% endif %}
@@ -972,7 +972,7 @@ You can also use expressions inside your templates:
.. code-block:: html+php
isGranted(new Expression(
- '"ROLE_ADMIN" in roles or (user and user.isSuperAdmin())'
+ '"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
))): ?>
Delete
diff --git a/security/expressions.rst b/security/expressions.rst
index 6d946e2523d..8fb75c501d9 100644
--- a/security/expressions.rst
+++ b/security/expressions.rst
@@ -18,7 +18,7 @@ accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object::
public function indexAction()
{
$this->denyAccessUnlessGranted(new Expression(
- '"ROLE_ADMIN" in roles or (user and user.isSuperAdmin())'
+ '"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
));
// ...