<?php
declare(strict_types=1);
/*
* Copyright (C) Office National de Publication et de Communication - All Rights Reserved
*
* Unauthorized copying of this file, via any medium is strictly prohibited by law
* This file is proprietary and confidential
*/
namespace App\Security\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Security;
final class MdpVoter extends Voter
{
public const EDIT = 'edit';
/**
* @var Security
*/
private $security;
public function __construct(Security $security)
{
$this->security = $security;
}
protected function supports($attribute, $subject): bool
{
return
'mdp' === $subject &&
\in_array($attribute, [self::EDIT], true);
}
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
switch ($attribute) {
case self::EDIT:
return
$this->security->isGranted('ROLE_RESPONSABLE_ETABLISSEMENT') &&
!$this->security->isGranted('ROLE_ADMIN') &&
!$this->security->isGranted('ROLE_REDACTEUR') &&
!$this->security->isGranted('ROLE_OPERATEUR_PAO') &&
!$this->security->isGranted('ROLE_INVITE') &&
!$this->security->isGranted('ROLE_DELEGUE');
}
return false;
}
}