/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.XmlUtil
 *  com.l7tech.gateway.common.transport.SsgConnector
 *  com.l7tech.gateway.common.transport.SsgConnector$Endpoint
 *  com.l7tech.util.Config
 *  com.l7tech.xml.SoapFaultLevel
 *  jakarta.servlet.ServletConfig
 *  jakarta.servlet.ServletContext
 *  jakarta.servlet.ServletException
 *  jakarta.servlet.ServletOutputStream
 *  jakarta.servlet.ServletRequest
 *  jakarta.servlet.http.HttpServlet
 *  jakarta.servlet.http.HttpServletRequest
 *  jakarta.servlet.http.HttpServletResponse
 *  org.springframework.beans.BeansException
 *  org.springframework.web.context.WebApplicationContext
 *  org.springframework.web.context.support.WebApplicationContextUtils
 */
package com.l7tech.server;

import com.l7tech.common.io.XmlUtil;
import com.l7tech.gateway.common.transport.SsgConnector;
import com.l7tech.server.StashManagerFactory;
import com.l7tech.server.TokenService;
import com.l7tech.server.a_;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.transport.ListenerException;
import com.l7tech.server.transport.http.HttpTransportModule;
import com.l7tech.server.util.SoapFaultManager;
import com.l7tech.util.Config;
import com.l7tech.xml.SoapFaultLevel;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.BeansException;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class TokenServiceServlet
extends HttpServlet {
    private WebApplicationContext applicationContext;
    private TokenService tokenService;
    private SoapFaultManager soapFaultManager;
    private StashManagerFactory stashManagerFactory;
    private Config serverConfig;
    private final Logger logger = Logger.getLogger(((Object)((Object)this)).getClass().getName());
    public static final String DEFAULT_CONTENT_TYPE;
    static final long serialVersionUID = -7592091795540573125L;
    private static final String[] a;

    public void init(ServletConfig servletConfig) throws ServletException {
        try {
            super.init(servletConfig);
            this.applicationContext = WebApplicationContextUtils.getWebApplicationContext((ServletContext)this.getServletContext());
            if (this.applicationContext == null) {
                throw new ServletException(a[13]);
            }
        }
        catch (BeansException beansException) {
            throw TokenServiceServlet.a((Exception)((Object)beansException));
        }
        try {
            String[] stringArray = a;
            this.tokenService = (TokenService)this.applicationContext.getBean(stringArray[10], TokenService.class);
            this.soapFaultManager = (SoapFaultManager)this.applicationContext.getBean(stringArray[9], SoapFaultManager.class);
            this.stashManagerFactory = (StashManagerFactory)this.applicationContext.getBean(stringArray[6], StashManagerFactory.class);
            this.serverConfig = (Config)this.applicationContext.getBean(stringArray[11], Config.class);
        }
        catch (BeansException beansException) {
            throw new ServletException(a[1], (Throwable)beansException);
        }
    }

    protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        try {
            SsgConnector ssgConnector = HttpTransportModule.getConnector((ServletRequest)httpServletRequest);
            HttpTransportModule.addHstsResponseHeaderIfRequired(httpServletRequest, httpServletResponse, ssgConnector, this.serverConfig);
            HttpTransportModule.requireEndpoint(ssgConnector, SsgConnector.Endpoint.STS);
            super.service(httpServletRequest, httpServletResponse);
        }
        catch (ListenerException listenerException) {
            String[] stringArray = a;
            this.logger.log(Level.INFO, stringArray[15]);
            httpServletResponse.sendError(404, stringArray[16]);
        }
    }

    public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        throw new ServletException(a[14]);
    }

    /*
     * Exception decompiling
     */
    public void doPost(HttpServletRequest var1_1, HttpServletResponse var2_2) throws ServletException, IOException {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Started 2 blocks at once
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.getStartingBlocks(Op04StructuredStatement.java:412)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:487)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1055)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

    private TokenService.CredentialsAuthenticator authenticator(PolicyEnforcementContext policyEnforcementContext) {
        return new a_(this, policyEnforcementContext);
    }

    private void outputRequestSecurityTokenResponse(Document document, HttpServletResponse httpServletResponse) throws IOException {
        httpServletResponse.setContentType(a[12]);
        ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
        XmlUtil.nodeToOutputStream((Node)document, (OutputStream)servletOutputStream);
        servletOutputStream.close();
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private void sendBackNonSoapError(HttpServletResponse httpServletResponse, int n2, String string) throws IOException {
        ServletOutputStream servletOutputStream = null;
        try {
            servletOutputStream = httpServletResponse.getOutputStream();
            try {
                httpServletResponse.setStatus(n2);
                if (string != null) {
                    servletOutputStream.write(string.getBytes());
                }
            }
            catch (IOException iOException) {
                throw TokenServiceServlet.a(iOException);
            }
        }
        catch (Throwable throwable) {
            try {
                if (servletOutputStream == null) throw throwable;
                servletOutputStream.close();
                throw throwable;
            }
            catch (IOException iOException) {
                throw TokenServiceServlet.a(iOException);
            }
        }
        try {
            if (servletOutputStream == null) return;
            servletOutputStream.close();
            return;
        }
        catch (IOException iOException) {
            throw TokenServiceServlet.a(iOException);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private void returnFault(PolicyEnforcementContext policyEnforcementContext, HttpServletResponse httpServletResponse) throws IOException {
        ServletOutputStream servletOutputStream = null;
        try {
            servletOutputStream = httpServletResponse.getOutputStream();
            httpServletResponse.setStatus(500);
            SoapFaultLevel soapFaultLevel = policyEnforcementContext.getFaultlevel();
            SoapFaultManager.FaultResponse faultResponse = this.soapFaultManager.constructReturningFault(soapFaultLevel, policyEnforcementContext);
            this.soapFaultManager.sendExtraHeaders(faultResponse, httpServletResponse);
            httpServletResponse.setContentType(faultResponse.getContentType().getFullValue());
            servletOutputStream.write(faultResponse.getContentBytes());
            if (servletOutputStream == null) return;
        }
        catch (Throwable throwable) {
            try {
                if (servletOutputStream == null) throw throwable;
                servletOutputStream.close();
                throw throwable;
            }
            catch (IOException iOException) {
                throw TokenServiceServlet.a(iOException);
            }
        }
        servletOutputStream.close();
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private void sendExceptionFault(PolicyEnforcementContext policyEnforcementContext, Throwable throwable, HttpServletResponse httpServletResponse) throws IOException {
        OutputStream outputStream = null;
        try {
            SoapFaultManager.FaultResponse faultResponse = this.soapFaultManager.constructExceptionFault(throwable, null, policyEnforcementContext);
            outputStream = httpServletResponse.getOutputStream();
            this.soapFaultManager.sendExtraHeaders(faultResponse, httpServletResponse);
            httpServletResponse.setContentType(faultResponse.getContentType().getFullValue());
            httpServletResponse.setStatus(500);
            outputStream.write(faultResponse.getContentBytes());
            if (outputStream == null) return;
        }
        catch (Throwable throwable2) {
            try {
                if (outputStream == null) throw throwable2;
                outputStream.close();
                throw throwable2;
            }
            catch (IOException iOException) {
                throw TokenServiceServlet.a(iOException);
            }
        }
        outputStream.close();
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[17];
                var3_1 = 0;
                var2_2 = "y\u0016\u0007|#s'H\u0012\u001d`%bq_W\u001bw?whT\u0004\f2(hdO\u001a\f|8)'2y\u0018\u0007t%`rH\u0016\u001d{#i'_\u0005\u001b}><'Y\u0018\u001c~('iU\u0003Iu)s'H\u0012\u0018g%ub^W\u000bw-it\u0014\u0015o9!S\u0002CK\u007f3IW\u0014DBj# ]\u0002='&h\u0012\u0018g)ts\u001a\u001e\u001a2\"hs\u001a\u0011\u0006`!fsN\u0012\r2-t'_\u000f\u0019w/sb^YI\u0018i\u0012\u0007flefY\u001cIA)drH\u001e\u001dk\u0018hl_\u0019S\u0017\u007f\u0005\u001b}>'wH\u001e\u0007f%i`\u001a\u0005\fa9ks\u0014W\u0013I\u0003\ba$JfT\u0016\u000ew>AfY\u0003\u0006`5+y\u0018\u001c~('iU\u0003I`)twU\u0019\r28h'h\u0012\u0018g)tsi\u0012\ng>nsC#\u0006y)i)\u001a\u000f\u0001W\nz-ut_\u0003Tg8a*\u0002\u0010I\u0018\bb\nfrV\u0003$s\"f`_\u0005\fN\u0018\u0002w\"TbH\u0001\u0000q)\fI\u0012\u001bd)uDU\u0019\u000f{+\u0017N\u0012\u0011fc\u007fjVLIq$fuI\u0012\u001d/9sa\u0017O6y\u0018\u0007t%`rH\u0016\u001d{#i'_\u0005\u001b}><'Y\u0018\u001c~('iU\u0003Iu)s'[\u0007\u0019~%dfN\u001e\u0006|ldhT\u0003\fj84w\u0012\u001dz#c'T\u0018\u001d2?rwJ\u0018\u001bf)c<\u001a\u0014\u0006|8b\u007fNW\u001bw=rbI\u0003\u001a2!rtNW\u001ca)'Wu$=";
                var4_3 = "y\u0016\u0007|#s'H\u0012\u001d`%bq_W\u001bw?whT\u0004\f2(hdO\u001a\f|8)'2y\u0018\u0007t%`rH\u0016\u001d{#i'_\u0005\u001b}><'Y\u0018\u001c~('iU\u0003Iu)s'H\u0012\u0018g%ub^W\u000bw-it\u0014\u0015o9!S\u0002CK\u007f3IW\u0014DBj# ]\u0002='&h\u0012\u0018g)ts\u001a\u001e\u001a2\"hs\u001a\u0011\u0006`!fsN\u0012\r2-t'_\u000f\u0019w/sb^YI\u0018i\u0012\u0007flefY\u001cIA)drH\u001e\u001dk\u0018hl_\u0019S\u0017\u007f\u0005\u001b}>'wH\u001e\u0007f%i`\u001a\u0005\fa9ks\u0014W\u0013I\u0003\ba$JfT\u0016\u000ew>AfY\u0003\u0006`5+y\u0018\u001c~('iU\u0003I`)twU\u0019\r28h'h\u0012\u0018g)tsi\u0012\ng>nsC#\u0006y)i)\u001a\u000f\u0001W\nz-ut_\u0003Tg8a*\u0002\u0010I\u0018\bb\nfrV\u0003$s\"f`_\u0005\fN\u0018\u0002w\"TbH\u0001\u0000q)\fI\u0012\u001bd)uDU\u0019\u000f{+\u0017N\u0012\u0011fc\u007fjVLIq$fuI\u0012\u001d/9sa\u0017O6y\u0018\u0007t%`rH\u0016\u001d{#i'_\u0005\u001b}><'Y\u0018\u001c~('iU\u0003Iu)s'[\u0007\u0019~%dfN\u001e\u0006|ldhT\u0003\fj84w\u0012\u001dz#c'T\u0018\u001d2?rwJ\u0018\u001bf)c<\u001a\u0014\u0006|8b\u007fNW\u001bw=rbI\u0003\u001a2!rtNW\u001ca)'Wu$=".length();
                var1_4 = 35;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 48;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = TokenServiceServlet.a(v0, TokenServiceServlet.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u000b}g\u0012GB\u0011:`z\u001eJ\u0007B1}xWL\f\u0003=~i\u0013\t\r\f\u007ffd\u001eZB\u00010|b\u0012J\u0016\r-(\u000b}g\u0012GB\u0011:`z\u001eJ\u0007B1}xWH\u0014\u00036~m\u0015E\u0007B0|,\u0003A\u000b\u0011\u007fbc\u0005]";
                    var4_3 = "\u000b}g\u0012GB\u0011:`z\u001eJ\u0007B1}xWL\f\u0003=~i\u0013\t\r\f\u007ffd\u001eZB\u00010|b\u0012J\u0016\r-(\u000b}g\u0012GB\u0011:`z\u001eJ\u0007B1}xWH\u0014\u00036~m\u0015E\u0007B0|,\u0003A\u000b\u0011\u007fbc\u0005]".length();
                    var1_4 = 43;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 85;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = TokenServiceServlet.a(v0, TokenServiceServlet.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        TokenServiceServlet.a = var5;
        TokenServiceServlet.DEFAULT_CONTENT_TYPE = XmlUtil.TEXT_XML + TokenServiceServlet.a[8];
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x37);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 10;
                    case 1 -> 71;
                    case 2 -> 89;
                    case 3 -> 34;
                    case 4 -> 124;
                    case 5 -> 55;
                    default -> 55;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

