<?php
namespace Claromentis\Core\Security;

$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"] = (@$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] ?: array()) + array("_c70b7ae02702a5b8" . "6bdf89694a7ec9bf" => base64_decode("QXV0aGVudGljYXRpb24gZXhjZXB0aW9uIG9jY3VycmVkOyBy" . "ZWRpcmVjdGluZyB0byBhdXRoZW50aWNhdGlvbiBlbnRyeSBw" . "b2ludCAoJXMp"), "_76737d82e053b" . "39c897404b1adc" . "68b55" => base64_decode("RXhjZXB0aW9uIHRocm93biB3aGVuIGhhbmRsaW5nIGFuIGV4Y2" . "VwdGlvbi4="), "_04c851ced65682f1411090dee7a" . "da43b" => base64_decode("cmV" . "zdA" . "=="), "_caed8833a4abb44" . "d3f82bac3df3f49b" . "8" => base64_decode("QWNjZXNzIGlzIGRlbmllZCBieSAiJXMiIGF0IG" . "xpbmUgJXM6ICVz"), "_94f1908d914f8e" . "ae548214baa234d" . "5a3" => base64_decode("QWNjZXNzIGRlbmllZCBleGNlcHRpb24gYnV0IHVzZXIga" . "XMgYXV0aGVudGljYXRlZC4gTm90IGFjdGluZw=="), "_470f7a9" . "7e22ca60" . "92dfdf1f" . "9dc08f51" . "c" => base64_decode("QWNjZXNzIGRlbmllZCBleGNlcHRpb24gd2hlbiB1c2VyIGlzIG5vd" . "CBhdXRoZW50aWNhdGVkOyByZWRpcmVjdGluZyB0byBhdXRoZW50aW" . "NhdGlvbiBlbnRyeSBwb2ludC4g"), "_bc53ffb1ce4628ef3" . "de23f9817604535" => base64_decode("RXhjZXB0aW9uIHRocm93biB3aGVuIGhhbmRsaW5nIGFuIGV4Y2VwdGlvbiAoJXM6IC" . "VzKQ=="), "_fc9d7314" . "a9d9958d8" . "fa0a403ba" . "8ff197" => base64_decode("Z2V0X2NsYX" . "Nz"), "_6a4dbf1e0ef2b99791651cdd" . "961f59a2" => base64_decode("L2F" . "kbW" . "luL" . "w=="), "_7adf80c15f53" . "7637512f7766d" . "5fa0b2f" => base64_decode("c2VjdXJpdHku" . "bW9kZQ=="), "_9c5172dc3c35ecb76b94527" . "a44740d37" => base64_decode("RGVuaWVkIGF0dGVtcHQgdG8gYWNjZ" . "XNzIGFkbWluIHBhbmVsICIlcyIuIC" . "IlcyIgYXQgbGluZSAlcw=="), "_10d7309829f877b368bb80e2bfbf" . "fa1e" => base64_decode("b25LZXJuZWxFeGNlcHRpb2" . "4="), "_6596b8f6a4969f9a3f6a1b22b9" . "0e9331" => base64_decode("c3ByaW5" . "0Zg=="), "_1ec49529be83" . "02010e032a317" . "95bd234" => base64_decode("Q2FsbGluZyBBdXR" . "oZW50aWNhdGlvbi" . "BlbnRyeSBwb2lud" . "Dog"), "_b3a6bf004b61ac9" . "76b233eac28b2d62" . "3" => base64_decode("YWRtaW4uY2hlY2tfYWRtaW5z" . "Lm5vX3JpZ2h0cw=="), "_0c5123aa744f69bbc0" . "e8b3ea2f6e847d" => base64_decode("bG1zZw=" . "="), "_70979d287fa" . "2c98d21aa078" . "34c259a52" => base64_decode("c3Ryd" . "G9sb3" . "dlcg=" . "="));
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 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\ExceptionEvent;







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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_10d7309829f877b" . "368bb80e2bfbffa1" . "e"]));
    }
    
    
    
    
    
    
    public function unregister(EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $_b497ce6f2af10f67516aed0ecf34d8cf->removeListener(KernelEvents::EXCEPTION, array($this, $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_10d7309829f877" . "b368bb80e2bfbff" . "a1e"]));
    }
    
    
    
    
    
    
    public function onKernelException(ExceptionEvent $event)
    {
        $_c35473364fa7a050299058f332ec29c1 = $event->getThrowable();
        $request = $event->getRequest();
        $_601a171d59986f7c15972b586685671b = $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_70979d287fa2c" . "98d21aa07834c2" . "59a52"]($request->attributes->get($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_7adf80c15f537637512f" . "7766d5fa0b2f"]));
        if ($_601a171d59986f7c15972b586685671b === $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_04c851ced65682f14" . "11090dee7ada43b"]) {
            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(ExceptionEvent $event, AuthenticationException $_c35473364fa7a050299058f332ec29c1)
    {
        $this->logger->info($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_6596b8f6a" . "4969f9a3f6" . "a1b22b90e9" . "331"]($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_c70b7ae02702a5b86bd" . "f89694a7ec9bf"], $_c35473364fa7a050299058f332ec29c1->getMessage()));
        try {
            $event->setResponse($this->startAuthentication($event->getRequest(), $_c35473364fa7a050299058f332ec29c1));
        } catch (\Throwable $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $event->setThrowable($_fe441aa3ef350bfb1a1a1ad8520dd530);
        }
    }
    private function handleAccessDeniedException(ExceptionEvent $event, AccessDeniedException $_c35473364fa7a050299058f332ec29c1)
    {
        $event->setThrowable(new AccessDeniedHttpException($_c35473364fa7a050299058f332ec29c1->getMessage(), $_c35473364fa7a050299058f332ec29c1));
        $this->logger->debug($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_6596b8f6a4969f9a3f6a" . "1b22b90e9331"]($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_caed8833a4abb44d3f82" . "bac3df3f49b8"], $_c35473364fa7a050299058f332ec29c1->getFile(), $_c35473364fa7a050299058f332ec29c1->getLine(), $_c35473364fa7a050299058f332ec29c1->getMessage()));
        try {
            if (!$this->context->GetUserId()) {
                $this->logger->info($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_470f7a97e22ca6092dfdf1f9dc08f" . "51c"] . $_c35473364fa7a050299058f332ec29c1->getMessage());
                $_dc93498592b008412758f279bebcb950 = new AuthenticationException($_c35473364fa7a050299058f332ec29c1->getMessage(), $_c35473364fa7a050299058f332ec29c1->getCode(), $_c35473364fa7a050299058f332ec29c1);
                $event->setResponse($this->startAuthentication($event->getRequest(), $_dc93498592b008412758f279bebcb950));
            } else {
                $this->logger->info($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_94f1908d914f8" . "eae548214baa23" . "4d5a3"]);
            }
        } catch (\Throwable $_fe441aa3ef350bfb1a1a1ad8520dd530) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_6596b8f6a4969f9a3f6a1b22" . "b90e9331"]($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_bc53ffb1ce4628ef3d" . "e23f9817604535"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_fc9d731" . "4a9d9958" . "d8fa0a40" . "3ba8ff19" . "7"]($_fe441aa3ef350bfb1a1a1ad8520dd530), $_fe441aa3ef350bfb1a1a1ad8520dd530->getMessage()));
            $event->setThrowable(new \RuntimeException($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_76737d82e" . "053b39c897" . "404b1adc68" . "b55"], 0, $_fe441aa3ef350bfb1a1a1ad8520dd530));
        }
    }
    private function handleAdminDeniedException(ExceptionEvent $event, AdminAccessDeniedException $_c35473364fa7a050299058f332ec29c1)
    {
        $this->logger->warning($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_6596b8f6a4969f9a3f6a1b" . "22b90e9331"]($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_9c5172dc3c35ecb76b94527a4474" . "0d37"], $_c35473364fa7a050299058f332ec29c1->GetPanelCode(), $_c35473364fa7a050299058f332ec29c1->getFile(), $_c35473364fa7a050299058f332ec29c1->getLine()));
        $event->setResponse(RedirectResponse::httpRedirect($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_6a4dbf1e0ef2" . "b99791651cdd9" . "61f59a2"], $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0c5123aa744f69bbc0e8b" . "3ea2f6e847d"]($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_b3a6bf004b61a" . "c976b233eac28b" . "2d623"]), true));
    }
    
    
    
    
    
    
    
    
    
    private function startAuthentication(Request $request, AuthenticationException $authException)
    {
        if (null === $this->entry_point) {
            throw $authException;
        }
        $this->logger->debug($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_1ec49529be8302010e032a31" . "795bd234"] . $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_fc9d7314a9d9958d8fa0a403ba8ff" . "197"]($this->entry_point));
        
        
        return $this->entry_point->start($request, $authException);
    }
    
    
    
    
    
    
    
    
    
    
    
    
}