<?php
namespace Harmonizely\Core\Security\Voter;
use Harmonizely\Core\Exception\RedirectToRoute;
use Harmonizely\Core\Security\Contract\ISecurityHelper;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class SecondAuthenticationVoter extends Voter
{
/**
* @var ISecurityHelper
*/
private ISecurityHelper $security;
/**
* SecondAuthenticationVoter constructor.
* @param ISecurityHelper $security
*/
public function __construct(ISecurityHelper $security)
{
$this->security = $security;
}
/**
* @param $attribute
* @param $subject
* @return bool
*/
protected function supports($attribute, $subject): bool
{
if (ISecurityHelper::IS_2FA_PASSED === $attribute) {
return true;
}
return false;
}
/**
* @param $attribute
* @param $subject
* @param TokenInterface $token
* @return bool
* @throws RedirectToRoute
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
if (!$this->security->isSecondFactorPassed()) {
throw new RedirectToRoute('fos_user_security_login');
}
return true;
}
}