. */ declare(strict_types=1); namespace App\Security\Voter; use App\Entity\UserSystem\User; use App\Services\UserSystem\PermissionManager; use App\Services\UserSystem\VoterHelper; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authorization\Voter\Voter; /** * This voter implements a virtual role, which can be used if the user has any permission set to allowed. * We use this to restrict access to the homepage. */ final class HasAccessPermissionsVoter extends Voter { public const ROLE = "HAS_ACCESS_PERMISSIONS"; public function __construct(private readonly PermissionManager $permissionManager, private readonly VoterHelper $helper) { } protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool { $user = $this->helper->resolveUser($token); return $this->permissionManager->hasAnyPermissionSetToAllowInherited($user); } protected function supports(string $attribute, mixed $subject): bool { return $attribute === self::ROLE; } public function supportsAttribute(string $attribute): bool { return $attribute === self::ROLE; } }