<?php
/*
* This file is part of the nellapp-core package.
*
* (c) Benjamin Georgeault
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nellapp\Bundle\SDKBundle\Permission\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* GRANT access to everything for Super Admin only.
*
* @author Benjamin Georgeault
*/
class SuperAdminVoter implements VoterInterface
{
public function vote(TokenInterface $token, $subject, array $attributes): int
{
if (null === $subject) {
return VoterInterface::ACCESS_ABSTAIN;
}
$user = $token->getUser();
if ($user instanceof UserInterface) {
if (in_array('ROLE_SUPER_ADMIN', $user->getRoles())) {
return VoterInterface::ACCESS_GRANTED;
}
}
return VoterInterface::ACCESS_ABSTAIN;
}
}