src/Drive/Sharepoint/Security/SharepointVoter.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Drive\Sharepoint\Security;
  3. use App\Drive\Util\SharepointUtil;
  4. use AppBundle\Entity\User;
  5. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  6. use Symfony\Component\Security\Core\Authorization\Voter\Voter;
  7. /**
  8.  * Class AuthVoter
  9.  */
  10. class SharepointVoter extends Voter
  11. {
  12.     const SHAREPOINT_USER_MUST_CONSENT 'sharepoint.user_must_consent';
  13.     /**
  14.      * @inheritDoc
  15.      */
  16.     protected function supports($attribute$subject)
  17.     {
  18.         return \in_array($attribute, [
  19.             self::SHAREPOINT_USER_MUST_CONSENT,
  20.         ]);
  21.     }
  22.     /**
  23.      * @inheritDoc
  24.      */
  25.     protected function voteOnAttribute($attribute$subjectTokenInterface $token)
  26.     {
  27.         $user $token->getUser();
  28.         if (!$user instanceof User) {
  29.             return false;
  30.         }
  31.         if (!SharepointUtil::isSharepointLawfirm($user)) {
  32.             return false;
  33.         }
  34.         switch ($attribute) {
  35.             case self::SHAREPOINT_USER_MUST_CONSENT:
  36.                 return null === $user->getSharepointRefreshToken();
  37.             default:
  38.                 throw new \LogicException('This code should not be reached');
  39.         }
  40.     }
  41. }