Skip to content

Commit

Permalink
minor #15578 [Security] Small improvement (noniagriconomie)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[Security] Small improvement

Small improvement

Commits
-------

0380688 [Security] Small improvement
  • Loading branch information
OskarStark committed Aug 4, 2021
2 parents 6124a80 + 0380688 commit c99bfc0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions security/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ Security: Complex Access Controls with Expressions
In addition to a role like ``ROLE_ADMIN``, the ``isGranted()`` method also
accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object::

// src/Controller/MyController.php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\ExpressionLanguage\Expression;
// ...
use Symfony\Component\HttpFoundation\Response;

public function index(): Response
class MyController extends AbstractController
{
$this->denyAccessUnlessGranted(new Expression(
'"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
));
public function index(): Response
{
$this->denyAccessUnlessGranted(new Expression(
'"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
));

// ...
// ...
}
}

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

0 comments on commit c99bfc0

Please sign in to comment.