src/Security/Voter/MdpVoter.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (C) Office National de Publication et de Communication - All Rights Reserved
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited by law
  7.  * This file is proprietary and confidential
  8.  */
  9. namespace App\Security\Voter;
  10. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  11. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  12. use Symfony\Component\Security\Core\Security;
  13. final class MdpVoter extends Voter
  14. {
  15.     public const EDIT 'edit';
  16.     /**
  17.      * @var Security
  18.      */
  19.     private $security;
  20.     public function __construct(Security $security)
  21.     {
  22.         $this->security $security;
  23.     }
  24.     protected function supports($attribute$subject): bool
  25.     {
  26.         return
  27.             'mdp' === $subject &&
  28.             \in_array($attribute, [self::EDIT], true);
  29.     }
  30.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  31.     {
  32.         switch ($attribute) {
  33.             case self::EDIT:
  34.                 return
  35.                     $this->security->isGranted('ROLE_RESPONSABLE_ETABLISSEMENT') &&
  36.                     !$this->security->isGranted('ROLE_ADMIN') &&
  37.                     !$this->security->isGranted('ROLE_REDACTEUR') &&
  38.                     !$this->security->isGranted('ROLE_OPERATEUR_PAO') &&
  39.                     !$this->security->isGranted('ROLE_INVITE') &&
  40.                     !$this->security->isGranted('ROLE_DELEGUE');
  41.         }
  42.         return false;
  43.     }
  44. }