src/Platform/SecurityBundle/Security/Voter/SuperUserVoter.php line 10

Open in your IDE?
  1. <?php
  2. namespace Platform\SecurityBundle\Security\Voter;
  3. use Platform\SecurityBundle\Entity\Identity\Account;
  4. use Platform\SecurityBundle\Model\PlatformSubject;
  5. use Platform\SecurityBundle\Security\PlatformVoter;
  6. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  7. final class SuperUserVoter extends PlatformVoter
  8. {
  9.     /**
  10.      * {@inheritDoc}
  11.      */
  12.     protected function supports(
  13.         Account $account,
  14.         string $attribute,
  15.         ?PlatformSubject $subject null
  16.     ): bool
  17.     {
  18.         // skip checking internal stuff
  19.         if ($this->sentry->isInternalPermission($attribute)) {
  20.             return false;
  21.         }
  22.         // no reason to run this voter if the account is not a superuser...
  23.         return $account->getSpecialPermissions()->isSuperUser();
  24.     }
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     protected function poll(
  29.         Account $account,
  30.         string $permission,
  31.         ?PlatformSubject $subject null
  32.     ): int
  33.     {
  34.         return $account->getSpecialPermissions()->isSuperUser()
  35.             ? VoterInterface::ACCESS_GRANTED
  36.             VoterInterface::ACCESS_ABSTAIN;
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     protected function try(
  42.         Account $account,
  43.         string $permission
  44.     ): int
  45.     {
  46.         return $this->poll($account$permission);
  47.     }
  48. }