vendor/pimcore/portal-engine/src/Service/Security/Voter/GuestUserPermissionVoter.php line 23

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\Model\DataObject\PortalUserInterface;
  13. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\PortalConfigService;
  14. use Pimcore\Bundle\PortalEngineBundle\Service\Security\GuestUserPermissionService;
  15. use Pimcore\Bundle\PortalEngineBundle\Service\Security\Traits\SecurityServiceAware;
  16. use Pimcore\Model\DataObject\Concrete;
  17. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  18. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  19. class GuestUserPermissionVoter extends Voter
  20. {
  21.     use SecurityServiceAware;
  22.     /**
  23.      * @var PortalConfigService
  24.      */
  25.     protected $portalConfigService;
  26.     /**
  27.      * @var GuestUserPermissionService
  28.      */
  29.     protected $guestUserPermissionService;
  30.     /**
  31.      * @param PortalConfigService $portalConfigService
  32.      * @param GuestUserPermissionService $guestUserPermissionService
  33.      */
  34.     public function __construct(PortalConfigService $portalConfigServiceGuestUserPermissionService $guestUserPermissionService)
  35.     {
  36.         $this->portalConfigService $portalConfigService;
  37.         $this->guestUserPermissionService $guestUserPermissionService;
  38.     }
  39.     /**
  40.      * Determines if the attribute and subject are supported by this voter.
  41.      *
  42.      */
  43.     protected function supports(string $attributemixed $subject): bool
  44.     {
  45.         return $this->portalConfigService->isPortalEngineSite() &&
  46.             in_array($attribute$this->guestUserPermissionService->getGuestUserRelevantPermissions());
  47.     }
  48.     /**
  49.      * Perform a single access check operation on a given attribute, subject and token.
  50.      * It is safe to assume that $attribute and $subject already passed the "supports()" method check.
  51.      *
  52.      */
  53.     protected function voteOnAttribute(string $attributemixed $subjectTokenInterface $token): bool
  54.     {
  55.         /** @var PortalUserInterface|Concrete $user */
  56.         $user $this->securityService->getPortalUser();
  57.         return $this->guestUserPermissionService->checkGuestUserPermissions($attribute$user);
  58.     }
  59. }