Skip to content

Commit

Permalink
Merge branch '4.4' into 5.3
Browse files Browse the repository at this point in the history
* 4.4:
  [Security] Small improvement
  • Loading branch information
OskarStark committed Aug 4, 2021
2 parents 7627d35 + c99bfc0 commit a5ffe5b
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 role_names or (not is_anonymous() and user.isSuperAdmin())'
));
public function index(): Response
{
$this->denyAccessUnlessGranted(new Expression(
'"ROLE_ADMIN" in role_names 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 a5ffe5b

Please sign in to comment.