vendor/emprel/ambiente-bundle/Event/DominioRestrictListener.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3.  * Este arquivo é parte do package Ambiente 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\Ambiente\Bundle\Event;
  11. use Emprel\Ambiente\Bundle\Utils\Rede;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  14. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  15. /**
  16.  * Seta os atributos de ambiente na request.
  17.  *
  18.  * @package Emprel\Ambiente\Bundle\Event
  19.  * @author Laino Santos <lainosantos@recife.pe.gov.br>
  20.  */
  21. class DominioRestrictListener
  22. {
  23.     /**
  24.      * @var ContainerInterface Container do Symfony.
  25.      */
  26.     protected $container;
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public function onKernelRequest(GetResponseEvent $event)
  31.     {
  32.         $request $event->getRequest();
  33.         $restringirAcessoInternoVhostExterno = !$this->container->getParameter('emprel_ambiente.acesso_interno_host_externo');
  34.         if ($request->attributes->has('_acesso_interno_host_externo')) {
  35.             $restringirAcessoInternoVhostExterno = !$request->attributes->get('_acesso_interno_host_externo'true);
  36.         }
  37.         if ((Rede::isVhostInterno() && !Rede::isRedeInterna($request)) ||
  38.             (!Rede::isVhostInterno() && Rede::isRedeInterna($request) && $restringirAcessoInternoVhostExterno)) {
  39.             throw new AccessDeniedHttpException('Requisição não permitida para o host.');
  40.         }
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function setContainer(ContainerInterface $container null)
  46.     {
  47.         $this->container $container;
  48.     }
  49. }