<?php
namespace Bidcoz\Bundle\CoreBundle\Security\Authorization\Voter;
use RS\DiExtraBundle\Annotation as DI;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @DI\Service
* @DI\Tag("security.voter", attributes={"priority"=255})
*/
class SuperUserVoter extends Voter
{
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token)
{
return true;
}
public function vote(TokenInterface $token, $subject, array $attributes)
{
$user = $token->getUser();
if ($user instanceof UserInterface && $user->hasRole('ROLE_SUPER_ADMIN')) {
if (in_array('IS_IMPERSONATOR', $attributes, true)) {
return self::ACCESS_ABSTAIN;
}
return self::ACCESS_GRANTED;
}
return self::ACCESS_ABSTAIN;
}
protected function supports(string $attribute, $subject)
{
return true;
}
}