<?php
namespace App\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
class WebServicesVoter extends Voter
{
const CONTROL_LIST = "WEB_SERVICES_CONTROL_LIST";
const COSTA_DETAIL = "WEB_SERVICES_COSTA_DETAIL";
const MSC_DETAIL = "WEB_SERVICES_MSC_DETAIL";
const CNAS_DETAIL = "WEB_SERVICES_CNAS_DETAIL";
const FNAC_DARTY_DETAIL = "WEB_SERVICES_FNAC_DARTY_DETAIL";
const MACIF_DETAIL = "WEB_SERVICES_MACIF_DETAIL";
const UNEO_DETAIL = "WEB_SERVICES_UNEO_DETAIL";
const SOFINCO_DETAIL = "WEB_SERVICES_SOFINCO_DETAIL";
const DIRECT_ASSURANCE_DETAIL = "WEB_SERVICES_DIRECT_ASSURANCE_DETAIL";
const CONNECTION_INTERFACE_PICTURE_LIST = "WEB_SERVICES_CONNECTION_INTERFACE_PICTURE_LIST";
const CONNECTION_INTERFACE_PICTURE_CREATE = "WEB_SERVICES_CONNECTION_INTERFACE_PICTURE_CREATE";
const CONNECTION_INTERFACE_PICTURE_REMOVE = "WEB_SERVICES_CONNECTION_INTERFACE_PICTURE_REMOVE";
protected function supports($attribute, $subject): bool
{
return in_array($attribute, [
self::CONTROL_LIST,
self::COSTA_DETAIL,
self::MSC_DETAIL,
self::CNAS_DETAIL,
self::FNAC_DARTY_DETAIL,
self::MACIF_DETAIL,
self::UNEO_DETAIL,
self::SOFINCO_DETAIL,
self::DIRECT_ASSURANCE_DETAIL,
self::CONNECTION_INTERFACE_PICTURE_LIST,
self::CONNECTION_INTERFACE_PICTURE_CREATE,
self::CONNECTION_INTERFACE_PICTURE_REMOVE,
]);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$loggedUser = $token->getUser();
if (!$loggedUser instanceof UserInterface) {
return false;
}
return in_array($attribute, $loggedUser->getRoles());
}
}