vendor/symfony/security-core/Authorization/AuthorizationChecker.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Security\Core\Authorization;
  11. use Symfony\Component\Security\Core\Authentication\Token\NullToken;
  12. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  13. /**
  14.  * AuthorizationChecker is the main authorization point of the Security component.
  15.  *
  16.  * It gives access to the token representing the current user authentication.
  17.  *
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  20.  */
  21. class AuthorizationChecker implements AuthorizationCheckerInterface
  22. {
  23.     private TokenStorageInterface $tokenStorage;
  24.     private AccessDecisionManagerInterface $accessDecisionManager;
  25.     public function __construct(TokenStorageInterface $tokenStorageAccessDecisionManagerInterface $accessDecisionManagerbool $exceptionOnNoToken false)
  26.     {
  27.         if ($exceptionOnNoToken) {
  28.             throw new \LogicException(sprintf('Argument $exceptionOnNoToken of "%s()" must be set to "false".'__METHOD__));
  29.         }
  30.         $this->tokenStorage $tokenStorage;
  31.         $this->accessDecisionManager $accessDecisionManager;
  32.     }
  33.     final public function isGranted(mixed $attributemixed $subject null): bool
  34.     {
  35.         $token $this->tokenStorage->getToken();
  36.         if (!$token || !$token->getUser()) {
  37.             $token = new NullToken();
  38.         }
  39.         return $this->accessDecisionManager->decide($token, [$attribute], $subject);
  40.     }
  41. }