Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a5ffe5b

Browse filesBrowse files
committed
Merge branch '4.4' into 5.3
* 4.4: [Security] Small improvement
2 parents 7627d35 + c99bfc0 commit a5ffe5b
Copy full SHA for a5ffe5b

File tree

Expand file treeCollapse file tree

1 file changed

+13
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-6
lines changed

‎security/expressions.rst

Copy file name to clipboardExpand all lines: security/expressions.rst
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,23 @@ Security: Complex Access Controls with Expressions
1212
In addition to a role like ``ROLE_ADMIN``, the ``isGranted()`` method also
1313
accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object::
1414

15+
// src/Controller/MyController.php
16+
namespace App\Controller;
17+
18+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1519
use Symfony\Component\ExpressionLanguage\Expression;
16-
// ...
20+
use Symfony\Component\HttpFoundation\Response;
1721

18-
public function index(): Response
22+
class MyController extends AbstractController
1923
{
20-
$this->denyAccessUnlessGranted(new Expression(
21-
'"ROLE_ADMIN" in role_names or (not is_anonymous() and user.isSuperAdmin())'
22-
));
24+
public function index(): Response
25+
{
26+
$this->denyAccessUnlessGranted(new Expression(
27+
'"ROLE_ADMIN" in role_names or (not is_anonymous() and user.isSuperAdmin())'
28+
));
2329

24-
// ...
30+
// ...
31+
}
2532
}
2633

2734
In this example, if the current user has ``ROLE_ADMIN`` or if the current

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.