<?php
namespace Claromentis\Core\Security;

$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] = (@$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] ?: array()) + array("_9c5172dc3c35" . "ecb76b94527a4" . "4740d37" => base64_decode("RGVuaWVkIGF0dGVtcHQgdG8gYWNjZXNzIGFkbWluIHBhbmVsICIlcyI" . "uICIlcyIgYXQgbGluZSAlcw=="), "_1ec49529be8302010e032a31795" . "bd234" => base64_decode("Q2FsbGluZyBBdXRoZW50aWNhdGlvbiBlbnRyeSBw" . "b2ludDog"), "_caed8833a4abb44d3f82bac3df3f49b" . "8" => base64_decode("QWNjZXNzIGlzIGRlb" . "mllZCBieSAiJXMiIG" . "F0IGxpbmUgJXM6ICV" . "z"), "_b3a6bf004b61ac976b233eac28b2d6" . "23" => base64_decode("YWRtaW4uY2" . "hlY2tfYWRt" . "aW5zLm5vX3" . "JpZ2h0cw=="), "_10d7309829f87" . "7b368bb80e2bfb" . "ffa1e" => base64_decode("b25LZXJuZWxFeG" . "NlcHRpb24="), "_fc9d7314a9d9958d8fa0a403ba8f" . "f197" => base64_decode("Z2V" . "0X2" . "NsY" . "XNz"), "_76737d82e053b39c8" . "97404b1adc68b55" => base64_decode("RXhjZXB0aW9uIHRocm93biB3aGVuIGh" . "hbmRsaW5nIGFuIGV4Y2VwdGlvbi4="), "_6596b8f6a496" . "9f9a3f6a1b22b" . "90e9331" => base64_decode("c3B" . "yaW" . "50Z" . "g=="), "_bc53ffb1ce4628ef3de" . "23f9817604535" => base64_decode("RXhjZXB0aW9uIHRocm93biB3aG" . "VuIGhhbmRsaW5nIGFuIGV4Y2Vw" . "dGlvbiAoJXM6ICVzKQ=="), "_70979d28" . "7fa2c98d2" . "1aa07834c" . "259a52" => base64_decode("c3RydG9sb3dlc" . "g=="), "_6a4dbf1e0e" . "f2b99791651" . "cdd961f59a2" => base64_decode("L2FkbWluLw" . "=="), "_7adf80c15f537637512f7766d5fa" . "0b2f" => base64_decode("c2VjdXJpdHkubW9kZQ" . "=="), "_470f7a97e22ca6092dfdf" . "1f9dc08f51c" => base64_decode("QWNjZXNzIGRlbmllZCBleGNlcHRpb24gd2hl" . "biB1c2VyIGlzIG5vdCBhdXRoZW50aWNhdGVk" . "OyByZWRpcmVjdGluZyB0byBhdXRoZW50aWNh" . "dGlvbiBlbnRyeSBwb2ludC4g"), "_0c5123aa744f69bbc0e8b3ea2f6e8" . "47d" => base64_decode("bG1z" . "Zw=="), "_c70b7ae027" . "02a5b86bdf8" . "9694a7ec9bf" => base64_decode("QXV0aGVudGljYXRpb24gZXhjZXB0aW9uIG9jY3VycmVkOyByZWRpcmVjdGluZyB0byBhdXRoZW50aWNhdGlvbiBlbnRyeSBwb2ludCAoJXM" . "p"), "_94f1908d914f8eae5482" . "14baa234d5a3" => base64_decode("QWNjZXNzIGRlbmllZCBleGNlcHRpb24gYn" . "V0IHVzZXIgaXMgYXV0aGVudGljYXRlZC4g" . "Tm90IGFjdGluZw=="), "_04c851ce" . "d65682f14" . "11090dee7" . "ada43b" => base64_decode("cmVzdA=" . "="));
use Claromentis\Core\Http\RedirectResponse;
use Claromentis\Core\Security\EntryPoint\AuthenticationEntryPointInterface;
use Claromentis\Core\Security\Exception\AccessDeniedException;
use Claromentis\Core\Security\Exception\AdminAccessDeniedException;
use Claromentis\Core\Security\Exception\AuthenticationException;
use OpenCloud\LoadBalancer\Resource\Access;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;







class ExceptionListener
{
    private AuthenticationEntryPointInterface $entry_point;
    private SecurityContext $context;
    private LoggerInterface $logger;
    public function __construct(AuthenticationEntryPointInterface $_7a289b617eb0efa8a6e18e1310d35187 = null, SecurityContext $context, LoggerInterface $logger = null)
    {
        $this->entry_point = $_7a289b617eb0efa8a6e18e1310d35187;
        $this->context = $context;
        $this->logger = $logger ?? new NullLogger();
    }
    
    
    
    
    
    
    public function register(EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $_b497ce6f2af10f67516aed0ecf34d8cf->addListener(KernelEvents::EXCEPTION, array($this, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_10d7309829f877b368bb80e2bfbffa" . "1e"]));
    }
    
    
    
    
    
    
    public function unregister(EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $_b497ce6f2af10f67516aed0ecf34d8cf->removeListener(KernelEvents::EXCEPTION, array($this, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_10d7309829" . "f877b368bb8" . "0e2bfbffa1e"]));
    }
    
    
    
    
    
    
    public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $_c35473364fa7a050299058f332ec29c1 = $event->getException();
        $request = $event->getRequest();
        $_601a171d59986f7c15972b586685671b = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_70979d287fa2c98d21aa07834c259" . "a52"]($request->attributes->get($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_7adf80c15f537637512f7766d5fa" . "0b2f"]));
        if ($_601a171d59986f7c15972b586685671b === $GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_04c851ce" . "d65682f14" . "11090dee7" . "ada43b"]) {
            return;
        }
        do {
            if ($_c35473364fa7a050299058f332ec29c1 instanceof AuthenticationException) {
                $this->handleAuthenticationException($event, $_c35473364fa7a050299058f332ec29c1);
                return;
            } elseif ($_c35473364fa7a050299058f332ec29c1 instanceof AdminAccessDeniedException) {
                $this->handleAdminDeniedException($event, $_c35473364fa7a050299058f332ec29c1);
                return;
            } elseif ($_c35473364fa7a050299058f332ec29c1 instanceof AccessDeniedException) {
                $this->handleAccessDeniedException($event, $_c35473364fa7a050299058f332ec29c1);
                return;
            }
        } while (null !== ($_c35473364fa7a050299058f332ec29c1 = $_c35473364fa7a050299058f332ec29c1->getPrevious()));
    }
    private function handleAuthenticationException(GetResponseForExceptionEvent $event, AuthenticationException $_c35473364fa7a050299058f332ec29c1)
    {
        $this->logger->info($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_6596b8f6a496" . "9f9a3f6a1b22b" . "90e9331"]($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_c70b7ae" . "02702a5b" . "86bdf896" . "94a7ec9b" . "f"], $_c35473364fa7a050299058f332ec29c1->getMessage()));
        try {
            $event->setResponse($this->startAuthentication($event->getRequest(), $_c35473364fa7a050299058f332ec29c1));
        } catch (\Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $event->setException($_fe441aa3ef350bfb1a1a1ad8520dd530);
        }
    }
    private function handleAccessDeniedException(GetResponseForExceptionEvent $event, AccessDeniedException $_c35473364fa7a050299058f332ec29c1)
    {
        $event->setException(new AccessDeniedHttpException($_c35473364fa7a050299058f332ec29c1->getMessage(), $_c35473364fa7a050299058f332ec29c1));
        $this->logger->debug($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_6596b8f6a4969f9a3f6a1b22" . "b90e9331"]($GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_caed8833a4abb44d3f82bac3d" . "f3f49b8"], $_c35473364fa7a050299058f332ec29c1->getFile(), $_c35473364fa7a050299058f332ec29c1->getLine(), $_c35473364fa7a050299058f332ec29c1->getMessage()));
        try {
            if (!$this->context->GetUserId()) {
                $this->logger->info($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_470f7a97e22ca6092dfdf1f9dc08f5" . "1c"] . $_c35473364fa7a050299058f332ec29c1->getMessage());
                $_dc93498592b008412758f279bebcb950 = new AuthenticationException($_c35473364fa7a050299058f332ec29c1->getMessage(), $_c35473364fa7a050299058f332ec29c1->getCode(), $_c35473364fa7a050299058f332ec29c1);
                $event->setResponse($this->startAuthentication($event->getRequest(), $_dc93498592b008412758f279bebcb950));
            } else {
                $this->logger->info($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_94f1908d914f8eae548214" . "baa234d5a3"]);
            }
        } catch (\Exception $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_6596b8f6a49" . "69f9a3f6a1b2" . "2b90e9331"]($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_bc53ffb1ce4628ef" . "3de23f9817604535"], $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_fc9d7314a9d9958d8fa0a403ba8" . "ff197"]($_fe441aa3ef350bfb1a1a1ad8520dd530), $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage()));
            $event->setException(new \RuntimeException($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_76737d82e053b39c89" . "7404b1adc68b55"], 0, $_fe441aa3ef350bfb1a1a1ad8520dd530));
        }
    }
    private function handleAdminDeniedException(GetResponseForExceptionEvent $event, AdminAccessDeniedException $_c35473364fa7a050299058f332ec29c1)
    {
        $this->logger->warning($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_6596b8f6a4969" . "f9a3f6a1b22b90" . "e9331"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_9c5172dc3c35ecb76b94527a44740d" . "37"], $_c35473364fa7a050299058f332ec29c1->GetPanelCode(), $_c35473364fa7a050299058f332ec29c1->getFile(), $_c35473364fa7a050299058f332ec29c1->getLine()));
        $event->setResponse(RedirectResponse::httpRedirect($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_6a4dbf1e0ef2b99" . "791651cdd961f59a" . "2"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0c5123aa744f69bbc0e8b3" . "ea2f6e847d"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_b3a6bf004b61ac976b233eac28b2d6" . "23"]), true));
    }
    
    
    
    
    
    
    
    
    
    private function startAuthentication(Request $request, AuthenticationException $authException)
    {
        if (null === $this->entry_point) {
            throw $authException;
        }
        $this->logger->debug($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_1ec49529be830" . "2010e032a31795" . "bd234"] . $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_fc9d7314a9d9958d8fa0a403ba" . "8ff197"]($this->entry_point));
        
        
        return $this->entry_point->start($request, $authException);
    }
    
    
    
    
    
    
    
    
    
    
    
    
}