vendor/pimcore/portal-engine/src/Service/Security/Voter/StatisticExplorerAccessVoter.php line 30

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\Service\Security\Voter;
  12. use Pimcore\Bundle\PortalEngineBundle\Enum\Permission;
  13. use Pimcore\Bundle\PortalEngineBundle\Model\DataObject\PortalUserInterface;
  14. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\PortalConfigService;
  15. use Pimcore\Bundle\PortalEngineBundle\Service\Security\PermissionService;
  16. use Pimcore\Bundle\PortalEngineBundle\Service\Security\Traits\SecurityServiceAware;
  17. use Pimcore\Model\DataObject\Concrete;
  18. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  19. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  20. use Symfony\Component\Security\Core\Security;
  21. /**
  22.  * Class StatisticExplorerAccessVoter
  23.  *
  24.  * @package Pimcore\Bundle\PortalEngineBundle\Service\Security\Voter
  25.  */
  26. class StatisticExplorerAccessVoter extends Voter
  27. {
  28.     use SecurityServiceAware;
  29.     /**
  30.      * @var PortalConfigService
  31.      */
  32.     protected $portalConfigService;
  33.     /**
  34.      * @var Security $security
  35.      */
  36.     protected $security;
  37.     /**
  38.      * @var PermissionService
  39.      */
  40.     protected $permissionService;
  41.     /**
  42.      * StatisticExplorerAccessVoter constructor.
  43.      *
  44.      * @param PortalConfigService $portalConfigService
  45.      * @param Security $security
  46.      * @param PermissionService $permissionService
  47.      */
  48.     public function __construct(PortalConfigService $portalConfigServiceSecurity $securityPermissionService $permissionService)
  49.     {
  50.         $this->portalConfigService $portalConfigService;
  51.         $this->security $security;
  52.         $this->permissionService $permissionService;
  53.     }
  54.     /**
  55.      * Determines if the attribute and subject are supported by this voter.
  56.      *
  57.      * @param string $attribute An attribute
  58.      * @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
  59.      *
  60.      * @return bool True if the attribute and subject are supported, false otherwise
  61.      */
  62.     protected function supports($attribute$subject)
  63.     {
  64.         return $this->portalConfigService->isPortalEngineSite() && $attribute === Permission::STATISTIC_EXPLORER_ACCESS;
  65.     }
  66.     /**
  67.      * Perform a single access check operation on a given attribute, subject and token.
  68.      * It is safe to assume that $attribute and $subject already passed the "supports()" method check.
  69.      *
  70.      * @param string $attribute
  71.      * @param mixed $subject
  72.      *
  73.      * @return bool
  74.      */
  75.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  76.     {
  77.         /** @var int $portalId */
  78.         $portalId $this->portalConfigService->getCurrentPortalConfig()->getPortalId();
  79.         /** @var PortalUserInterface|Concrete $user */
  80.         $user $this->securityService->getPortalUser();
  81.         return $user instanceof PortalUserInterface && $this->permissionService->isAllowed($userPermission::STATISTIC_EXPLORER_ACCESS Permission::PERMISSION_DELIMITER $portalId);
  82.     }
  83. }