src/Security/Voters/UserSystemAccessVoter.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Security\Voters;
  3. use App\Service\SystemServices\ISystemAccessService;
  4. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  5. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  6. use Symfony\Component\Security\Core\Security;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. class UserSystemAccessVoter extends Voter
  9. {
  10.     private $security;
  11.     private $systemService;
  12.     const SUPER_ADMIN_CONTROLLER_ACCESS 'FLEET_MGT_CONTROLLER_ACCESS';
  13.     /**
  14.      * @param Security $security
  15.      * @param ISystemAccessService $systemService
  16.      */
  17.     public function __construct(Security $securityISystemAccessService $systemService)
  18.     {
  19.         $this->security $security;
  20.         $this->systemService $systemService;
  21.     }
  22.     protected function supports(string $attribute$subject): bool
  23.     {
  24.         if ($attribute != self::SUPER_ADMIN_CONTROLLER_ACCESS) {
  25.             return false;
  26.         }
  27.         return true;
  28.     }
  29.     protected function voteOnAttribute(string $attribute$subjectTokenInterface $token): bool
  30.     {
  31.         $user $token->getUser();
  32.         if (!$user instanceof UserInterface || empty($subject)) {
  33.             return false;
  34.         }
  35.         if (!$this->security->isGranted($user->getRole()->getMetaCode())) {
  36.             return false;
  37.         }
  38.         /**
  39.          * super system access level check
  40.          */
  41.         return $this->systemService->subSystemModuleAccessValidation($user$subject);
  42.         //todo generate access log
  43.     }
  44. }