<?php
namespace Claromentis\Core\Security;

$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"] = (@$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"] ?: array()) + array("_5ce040ae4c223" . "29c2682c368b68" . "b3611" => base64_decode("UmVxdWVzdGV" . "kIGFjY2Vzcy" . "An"), "_965e72db2455ea911677" . "9414f062746a" => base64_decode("WW91IG5lZWQgdG8gY2hhbmdlIHlvdXIgcG" . "Fzc3dvcmQ="), "_7adf80c15f5" . "37637512f776" . "6d5fa0b2f" => base64_decode("c2VjdX" . "JpdHku" . "bW9kZQ" . "=="), "_d5e3acfe493" . "fa2111d22dfb" . "93da33d87" => base64_decode("X" . "1" . "8" . "="), "_14feb7309" . "9827a30c31" . "c0b996c13f" . "13c" => base64_decode("b25LZX" . "JuZWxS" . "ZXF1ZX" . "N0"), "_24e0e36600d6af77406a44bb618" . "a6253" => base64_decode("dXNl" . "cg=="), "_8059e2b" . "ace33111" . "90b0a85f" . "8709f7a6" . "a" => base64_decode("YWRta" . "W4="), "_0521fbd3" . "b745045e7" . "644213cbe" . "d21a21" => base64_decode("c2VjdXJpdHkuZXh" . "0cmE="), "_c7a35cdd863753e83240fbb3e732" . "a6b7" => base64_decode("bm9" . "uZQ" . "=="), "_77649368" . "bc532d9bc" . "06ddad8a5" . "0096a2" => base64_decode("QXBwbGljYXRpb24gcmVxdWlyZXMgYWRtaW4gYWNjZXNzLCBidXQgZG9lc24ndCBzcGVjaWZ5IHBhbmVsIGNvZ" . "GU="), "_cc6b63c64fd515a5b0110d3b97a81" . "4eb" => base64_decode("QXV0aGVudG" . "ljYXRpb24g" . "cmVxdWlyZW" . "Q="), "_4dc7dd1d92608d7c4ed" . "ca7dabd0206ce" => base64_decode("b25LZXJu" . "ZWxGaW5p" . "c2hSZXF1" . "ZXN0"), "_7f628626dd" . "1d55c71b1fc" . "0932ffd1d2c" => base64_decode("aXN" . "fYX" . "JyY" . "Xk="), "_6a11dd42" . "eb3818bd9" . "995b593e8" . "50c7ea" => base64_decode("Rm9yY2Vk" . "IHBhc3N3" . "b3JkIGNo" . "YW5nZQ=="), "_858e845b028b701406de2d127009c" . "941" => base64_decode("cGFuZW" . "xfY29k" . "ZQ=="), "_5269083028d2f37" . "d24843e7b56f8002" . "5" => base64_decode("c2VjdXJp" . "dHkucmVz" . "dHJpY3Rp" . "b24="), "_6f8bc3b" . "51b049d8" . "9dacde43" . "983139a5" . "6" => base64_decode("X3JvdXR" . "l"), "_fdd279667944aa31b47" . "cee7c4488495f" => base64_decode("JywgYnV0IGl0J3Mgbm90IGdp" . "dmVu"));
use Claromentis\Core\Admin\CurrentPanel;
use Claromentis\Core\Event\EventSubscriberInterface;
use Claromentis\Core\Security\Exception\AccessDeniedException;
use Claromentis\Core\Security\Exception\AdminAccessDeniedException;
use Claromentis\Core\Security\Exception\AuthenticationException;
use Claromentis\Core\Security\Exception\BadCredentialsException;
use Claromentis\Core\Security\Exception\ForcedPasswordChangeException;
use Claromentis\Core\Security\Exception\InvalidConfigException;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouteCollection;






class Firewall implements EventSubscriberInterface
{
    protected $routes;
    protected $auth_mode_manager;
    protected $context;
    protected $dispatcher;
    protected $logger;
    protected $exception_listeners;
    public function __construct(RouteCollection $_6c20f4873f12c6bcced6c1dda9a06b86, AuthenticationModeManager $_f6b575597c272e12f16dc922e604c11d, SessionSecurityContext $context, EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf, LoggerInterface $logger = null, CurrentPanel $_777fee2a9f69c8905bdc4ffffa7d93cf = null)
    {
        $this->routes = $_6c20f4873f12c6bcced6c1dda9a06b86;
        $this->auth_mode_manager = $_f6b575597c272e12f16dc922e604c11d;
        $this->context = $context;
        $this->dispatcher = $_b497ce6f2af10f67516aed0ecf34d8cf;
        $this->logger = $logger;
        $this->current_panel = $_777fee2a9f69c8905bdc4ffffa7d93cf;
        $this->exception_listeners = new \SplObjectStorage();
    }
    
    
    
    
    public static function getSubscribedEvents()
    {
        return array(KernelEvents::REQUEST => array($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_14feb73099827a30c31c0b996c1" . "3f13c"], 8), KernelEvents::FINISH_REQUEST => $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_4dc7dd1d92608d7c4edca" . "7dabd0206ce"]);
    }
    public function onKernelFinishRequest(FinishRequestEvent $event)
    {
        $request = $event->getRequest();
        
        
        if (isset($this->exception_listeners[$request])) {
            
            
            $_ee62014f4ef50dbe8eb79b2406d87bc7 = $this->exception_listeners[$request];
            $_ee62014f4ef50dbe8eb79b2406d87bc7->unregister($this->dispatcher);
            unset($this->exception_listeners[$request]);
        }
    }
    
    
    
    
    
    
    
    
    
    protected function VerifyAccess(RequestEvent $event, $_601a171d59986f7c15972b586685671b, $_3de589dc8908aa0acc1d667051a758f3, $_4a033bdf0ce701c6255d5238633ab2d0)
    {
        $request = $event->getRequest();
        $_76b40b4ffb78489ccdf0fef0a81963f5 = $this->auth_mode_manager->GetExceptionListener($_601a171d59986f7c15972b586685671b);
        
        
        if (null !== $_76b40b4ffb78489ccdf0fef0a81963f5) {
            $this->exception_listeners[$request] = $_76b40b4ffb78489ccdf0fef0a81963f5;
            $_76b40b4ffb78489ccdf0fef0a81963f5->register($this->dispatcher);
        }
        if ($_3de589dc8908aa0acc1d667051a758f3 !== $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_c7a35cdd863753e83240fbb3e732a6" . "b7"]) {
            $_b911cc8a777886afea194de4534beffa = $this->auth_mode_manager->GetAuthenticators($_601a171d59986f7c15972b586685671b);
            foreach ($_b911cc8a777886afea194de4534beffa as $_bcd36e5a5ed036659bc02cdfe807a094) {
                $_bcd36e5a5ed036659bc02cdfe807a094->Handle($event, $this->context);
                if ($event->hasResponse()) {
                    return;
                }
            }
        }
        $_34142f0805685e788bb54a01fb3e222c = null;
        if ($_3de589dc8908aa0acc1d667051a758f3 === $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_8059e2bace33111" . "90b0a85f8709f7a6" . "a"]) {
            if (!$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_7f628626dd1d55c71b1fc0932f" . "fd1d2c"]($_4a033bdf0ce701c6255d5238633ab2d0) || empty($_4a033bdf0ce701c6255d5238633ab2d0[$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_858e845b028b701406de2d12700" . "9c941"]])) {
                throw new InvalidConfigException($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_77649368bc532d9bc06d" . "dad8a50096a2"]);
            }
            $_34142f0805685e788bb54a01fb3e222c = $_4a033bdf0ce701c6255d5238633ab2d0[$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_858e845b0" . "28b701406d" . "e2d127009c" . "941"]];
            $_3de589dc8908aa0acc1d667051a758f3 = $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_24e0e36600d6af77406a44bb618" . "a6253"];
        }
        if (!$this->context->IsGranted($_3de589dc8908aa0acc1d667051a758f3)) {
            if (null !== $this->logger) {
                $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_5ce040ae4c22329c2682c368b6" . "8b3611"] . $_3de589dc8908aa0acc1d667051a758f3 . $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_fdd279667944aa31b47" . "cee7c4488495f"], [$this->context]);
            }
            if (!$this->context->GetUserId()) {
                throw new AccessDeniedException($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_cc6b63c64fd515a5b011" . "0d3b97a814eb"], 401);
            }
            throw new AccessDeniedException();
        }
        if ($_34142f0805685e788bb54a01fb3e222c !== null) {
            if (!$this->context->GetUserId()) {
                throw new AccessDeniedException($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_cc6b63c64fd515a5b01" . "10d3b97a814eb"], 401);
            }
            if (!\AdminPanel::UserHasAccess($_34142f0805685e788bb54a01fb3e222c, $this->context->GetId())) {
                throw new AdminAccessDeniedException($_34142f0805685e788bb54a01fb3e222c);
            }
            if ($this->current_panel !== null) {
                $this->current_panel->Set($_34142f0805685e788bb54a01fb3e222c);
            }
        }
        $this->CheckPasswordPolicy();
    }
    
    
    
    
    
    
    
    
    public function onKernelRequest(RequestEvent $event)
    {
        $request = $event->getRequest();
        $_d7cd24af9c1ec9e84b034650f4556bdc = $request->attributes->get($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_6f8bc3b51b049" . "d89dacde439831" . "39a56"]);
        if (!($_4c24595e81e7e67a084f4708169b7ec6 = $this->routes->get($_d7cd24af9c1ec9e84b034650f4556bdc))) {
            return;
        }
        
        
        $_601a171d59986f7c15972b586685671b = $_4c24595e81e7e67a084f4708169b7ec6->getOption($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_7adf80c15f537637512f7766d" . "5fa0b2f"]);
        $_3de589dc8908aa0acc1d667051a758f3 = $_4c24595e81e7e67a084f4708169b7ec6->getOption($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_5269083028d2f37d24843e7" . "b56f80025"]);
        $_4a033bdf0ce701c6255d5238633ab2d0 = $_4c24595e81e7e67a084f4708169b7ec6->getOption($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_0521fbd3b7450" . "45e7644213cbed" . "21a21"]);
        $request->attributes->set($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_7adf80c15f537637512f7766d5fa0b" . "2f"], $_601a171d59986f7c15972b586685671b);
        $request->attributes->set($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_5269083028d2f37d2" . "4843e7b56f80025"], $_3de589dc8908aa0acc1d667051a758f3);
        $request->attributes->set($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0521fbd3b745045e7644213cbed21" . "a21"], $_4a033bdf0ce701c6255d5238633ab2d0);
        $this->VerifyAccess($event, $_601a171d59986f7c15972b586685671b, $_3de589dc8908aa0acc1d667051a758f3, $_4a033bdf0ce701c6255d5238633ab2d0);
    }
    
    
    
    
    protected function CheckPasswordPolicy()
    {
        
        
        
        try {
            StdAuthenticator::MODE_AJAX;
            
            
            AuthUserPasswordPolicy::Run();
        } catch (PageLoadHookRedirectException $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->notice($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_6a11dd42e" . "b3818bd999" . "5b593e850c" . "7ea"], [$_fe441aa3ef350bfb1a1a1ad8520dd530]);
            throw new ForcedPasswordChangeException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_d5e3acfe493fa2111d22dfb9" . "3da33d87"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_965e72db2455ea911677941" . "4f062746a"]));
        }
    }
}