<?php
namespace App\Drive\Sharepoint\Security;
use App\Drive\Util\SharepointUtil;
use AppBundle\Entity\User;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* Class AuthVoter
*/
class SharepointVoter extends Voter
{
const SHAREPOINT_USER_MUST_CONSENT = 'sharepoint.user_must_consent';
/**
* @inheritDoc
*/
protected function supports($attribute, $subject)
{
return \in_array($attribute, [
self::SHAREPOINT_USER_MUST_CONSENT,
]);
}
/**
* @inheritDoc
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
{
$user = $token->getUser();
if (!$user instanceof User) {
return false;
}
if (!SharepointUtil::isSharepointLawfirm($user)) {
return false;
}
switch ($attribute) {
case self::SHAREPOINT_USER_MUST_CONSENT:
return null === $user->getSharepointRefreshToken();
default:
throw new \LogicException('This code should not be reached');
}
}
}