<?php
namespace Eckinox\SecurityBundle\Security;
use App\Entity\Security\User;
use App\Entity\Security\AppUser;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class PrivilegeVoter extends Voter
{
protected function supports(string $attribute, $subject): bool {
return strpos($attribute, "ROLE_") !== 0 && $subject === null;
}
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof AppUser && !$user instanceof User) {
return false;
}
return $user->hasPrivilege($attribute);
}
}