<?php
declare(strict_types=1);
/**
* AccessTokenVoter.php File.
* This file is part of the Payment.net Project.
*
* PHP version 5
*
* @category Application
* @package Bdm\BackofficeBundle\Security\Authorization\Voter
* @author Alexandr Bakurin <abakurin@bdmultimedia.fr>
* @link http://www.payment.net/
*
* FEATURES :
* ==========
*
* TODO-LIST :
* ===========
*
* HISTORY :
* =========
* 20151021 - Alexandr Bakurin
*/
namespace Bdm\OAuth2Bundle\Security\Authorization\Voter;
use Bdm\OAuth2Bundle\Entity\AccessToken;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* AccessTokenVoter
*/
class AccessTokenVoter extends Voter
{
const DELETE = 'DELETE';
/**
* @param string $sAttribute attribute
* @param mixed $oSubject subject
* @return bool
*/
public function supports($sAttribute, $oSubject)
{
if ($sAttribute !== self::DELETE) {
return false;
}
if ($oSubject instanceof AccessToken) {
return true;
}
return false;
}
/**
* Check if has access
*
* @param string $aAttr attr
* @param object $mEntity entity
* @param null $oUser user
*
* @return bool
*/
/**
* @param string $sAttribute attribute
* @param object $mEntity application
* @param TokenInterface $oToken token
* @return bool
*/
protected function voteOnAttribute($sAttribute, $mEntity, TokenInterface $oToken)
{
$oUser = $oToken->getUser();
if (!$oUser instanceof UserInterface) {
return false;
}
if ($mEntity->getClient()->getMerchant() === $oUser) {
return true;
}
return false;
}
}