src/AppBundle/Security/UserConfinedVoter.php line 13

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Security;
  3. use AppBundle\Entity\User;
  4. use CommonBundle\Model\UserConfinedInterface;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. /**
  8.  * Class UserConfinedVoter
  9.  */
  10. class UserConfinedVoter extends Voter
  11. {
  12.     /**
  13.      * {@inheritdoc}
  14.      */
  15.     protected function supports($attribute$subject)
  16.     {
  17.         return $subject instanceof UserConfinedInterface;
  18.     }
  19.     /**
  20.      * {@inheritdoc}
  21.      * @param UserConfinedInterface $subject
  22.      */
  23.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  24.     {
  25.         $user $token->getUser();
  26.         if (!$user instanceof User) {
  27.             return false;
  28.         }
  29.         return $user->getId() === $subject->getUserWithRights()->getId();
  30.     }
  31. }