src/Platform/SecurityBundle/Security/Voter/InternalUserVoter.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 InternalUserVoter 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.         // for this to be an internal vote, the permission should be prefixed a certain way
  19.         if ( ! $this->sentry->isInternalPermission($attribute)) {
  20.             return false;
  21.         }
  22.         return true;
  23.     }
  24.     /**
  25.      * {@inheritdoc}
  26.      */
  27.     protected function poll(
  28.         Account $account,
  29.         string $permission,
  30.         ?PlatformSubject $subject null
  31.     ): int
  32.     {
  33.         // go ahead and double check that we are an internal user
  34.         // since we have verified that we are checking an internal permission, we should deny access if the account is not internal itself
  35.         // this is done to help prevent the superuser voter from allowing access
  36.         if ( ! $account->isInternal()) {
  37.             return VoterInterface::ACCESS_DENIED;
  38.         }
  39.         // just see if the permission being checked is in our account's internal set
  40.         return in_array($permission$account->getInternalPermissions(), true)
  41.             ? VoterInterface::ACCESS_GRANTED
  42.             VoterInterface::ACCESS_ABSTAIN;
  43.     }
  44.     /**
  45.      * {@inheritdoc}
  46.      */
  47.     protected function try(
  48.         Account $account,
  49.         string $permission
  50.     ): int
  51.     {
  52.         return $this->poll($account$permission);
  53.     }
  54. }