vendor/sulu/sulu/src/Sulu/Component/Security/Authorization/SecurityChecker.php line 42

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Component\Security\Authorization;
  11. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  12. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  13. /**
  14.  * Implementation of Sulu specific security checks, includes a subject, the type of permission and the localization.
  15.  */
  16. class SecurityChecker extends AbstractSecurityChecker
  17. {
  18.     /**
  19.      * @var TokenStorageInterface
  20.      */
  21.     private $tokenStorage;
  22.     /**
  23.      * @var AuthorizationCheckerInterface
  24.      */
  25.     private $authorizationChecker;
  26.     public function __construct(
  27.         TokenStorageInterface $tokenStorage,
  28.         AuthorizationCheckerInterface $authorizationChecker
  29.     ) {
  30.         $this->tokenStorage $tokenStorage;
  31.         $this->authorizationChecker $authorizationChecker;
  32.     }
  33.     public function hasPermission($subject$permission)
  34.     {
  35.         if (!$subject || !$this->tokenStorage->getToken()) {
  36.             // if there is no subject the operation is allowed, since we have nothing to check against
  37.             // if there is no token we are not behind a firewall, so the action is also allowed (e.g. command execution)
  38.             return true;
  39.         }
  40.         if (\is_string($subject)) {
  41.             $subject = new SecurityCondition($subject);
  42.         }
  43.         $granted $this->authorizationChecker->isGranted($permission$subject);
  44.         return $granted;
  45.     }
  46. }