36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Security\Voter;
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
|
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
|
use Symfony\Component\Security\Core\Authorization\Voter\Vote;
|
|
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
|
|
|
/**
|
|
* @extends Voter<string, mixed>
|
|
*/
|
|
class AdministrativeAccessVoter extends Voter
|
|
{
|
|
public const ADMINISTRATIVE_ACCESS = 'ADMINISTRATIVE_ACCESS';
|
|
|
|
public function __construct(
|
|
private readonly AccessDecisionManagerInterface $accessDecisionManager,
|
|
) {
|
|
}
|
|
|
|
protected function supports(string $attribute, mixed $subject): bool
|
|
{
|
|
return self::ADMINISTRATIVE_ACCESS === $attribute;
|
|
}
|
|
|
|
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token, ?Vote $vote = null): bool
|
|
{
|
|
return $this->accessDecisionManager->decide($token, ['ROLE_ADMIN'])
|
|
|| $this->accessDecisionManager->decide($token, ['ROLE_GROUPS_MANAGER'])
|
|
|| $this->accessDecisionManager->decide($token, ['ROLE_CUSTOMER_EXPERT']);
|
|
}
|
|
}
|