vendor/emprel/login-bundle/Security/Voter/OtpVoter.php line 19

Open in your IDE?
  1. <?php
  2. /*
  3.  * Este arquivo é parte do package Login Bundle.
  4.  *
  5.  * (c) Laino Santos <lainosantos@recife.pe.gov.br>
  6.  *
  7.  * Para informações completas sobre copyright e licença, por favor ver o
  8.  * arquivo LICENCE distribuído juntamente com este código.
  9.  */
  10. namespace Emprel\Login\Bundle\Security\Voter;
  11. use Emprel\OpenIdUmaClient\Connector;
  12. use Emprel\Login\Bundle\Security\User\LoginUser;
  13. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  14. use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
  15. class OtpVoter implements VoterInterface
  16. {
  17.     public function vote(TokenInterface $token$subject, array $attributes)
  18.     {
  19.         $user $token->getUser();
  20.         if (!$user instanceof LoginUser || !$subject instanceof OtpVoterSubject) {
  21.             return self::ACCESS_ABSTAIN;
  22.         }
  23.         foreach ($attributes as $attribute) {
  24.             $otpIsValid $subject->getUmaClient()->callRelativeEndpoint(
  25.                 "user/{$user->getUsername()}/otp/valid",
  26.                 $user->getTokenWrapper()->getAccessToken(),
  27.                 Connector::CONTENT_TYPE_APPLICATION_JSON,
  28.                 Connector::VERB_POST,
  29.                 [
  30.                     'otp' => $attribute,
  31.                 ]
  32.             );
  33.             if (!$otpIsValid) {
  34.                 return self::ACCESS_DENIED;
  35.             }
  36.         }
  37.         return self::ACCESS_GRANTED;
  38.     }
  39. }