/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.message.Message
 *  com.l7tech.policy.assertion.Assertion
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.policy.assertion.xmlsec.SecurityHeaderAddressableSupport
 *  com.l7tech.policy.assertion.xmlsec.XmlSecurityAssertionBase
 *  com.l7tech.security.token.ParsedElement
 *  com.l7tech.security.xml.SecurityTokenResolver
 *  com.l7tech.security.xml.processor.ProcessorResult
 *  com.l7tech.util.Config
 *  com.l7tech.xml.InvalidXpathException
 *  com.l7tech.xml.xpath.CompilableXpath
 *  com.l7tech.xml.xpath.DomCompiledXpath
 *  org.springframework.context.ApplicationContext
 */
package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.xmlsec.SecurityHeaderAddressableSupport;
import com.l7tech.policy.assertion.xmlsec.XmlSecurityAssertionBase;
import com.l7tech.security.token.ParsedElement;
import com.l7tech.security.xml.SecurityTokenResolver;
import com.l7tech.security.xml.processor.ProcessorResult;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractMessageTargetableServerAssertion;
import com.l7tech.server.policy.assertion.ServerAssertion;
import com.l7tech.util.Config;
import com.l7tech.xml.InvalidXpathException;
import com.l7tech.xml.xpath.CompilableXpath;
import com.l7tech.xml.xpath.DomCompiledXpath;
import java.io.IOException;
import org.springframework.context.ApplicationContext;

public abstract class ServerRequireWssOperation<AT extends XmlSecurityAssertionBase>
extends AbstractMessageTargetableServerAssertion<AT>
implements ServerAssertion<AT> {
    private final Config d;
    private final SecurityTokenResolver e;
    private final DomCompiledXpath f;
    private final InvalidXpathException g;
    private static final String[] i;

    protected ServerRequireWssOperation(AT AT, ApplicationContext applicationContext) {
        super(AT);
        InvalidXpathException invalidXpathException;
        DomCompiledXpath domCompiledXpath;
        String[] stringArray = i;
        this.d = (Config)applicationContext.getBean(stringArray[1], Config.class);
        this.e = (SecurityTokenResolver)applicationContext.getBean(stringArray[0], SecurityTokenResolver.class);
        try {
            domCompiledXpath = new DomCompiledXpath((CompilableXpath)AT.getXpathExpression());
            invalidXpathException = null;
        }
        catch (InvalidXpathException invalidXpathException2) {
            domCompiledXpath = null;
            invalidXpathException = invalidXpathException2;
        }
        this.f = domCompiledXpath;
        this.g = invalidXpathException;
    }

    protected DomCompiledXpath getCompiledXpath() throws PolicyAssertionException {
        try {
            if (this.g != null) {
                throw new PolicyAssertionException(this.assertion, (Throwable)this.g);
            }
        }
        catch (PolicyAssertionException policyAssertionException) {
            throw ServerRequireWssOperation.a((Exception)((Object)policyAssertionException));
        }
        try {
            if (this.f == null) {
                throw new PolicyAssertionException(this.assertion, i[4]);
            }
        }
        catch (PolicyAssertionException policyAssertionException) {
            throw ServerRequireWssOperation.a((Exception)((Object)policyAssertionException));
        }
        return this.f;
    }

    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws IOException, PolicyAssertionException {
        try {
            if (!SecurityHeaderAddressableSupport.isLocalRecipient((Assertion)this.assertion)) {
                this.logAndAudit((AuditDetailMessage)AssertionMessages.REQUESTWSS_NOT_FOR_US);
                return AssertionStatus.NONE;
            }
        }
        catch (IOException iOException) {
            throw ServerRequireWssOperation.a(iOException);
        }
        return super.checkRequest(policyEnforcementContext);
    }

    /*
     * Exception decompiling
     */
    @Override
    protected AssertionStatus doCheckRequest(PolicyEnforcementContext var1_1, Message var2_2, String var3_3, AuthenticationContext var4_4) throws IOException, PolicyAssertionException {
        /*
         * 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: Tried to end blocks [9[TRYBLOCK]], but top level block is 10[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     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");
    }

    protected boolean elementsFoundByProcessorAreValid(PolicyEnforcementContext policyEnforcementContext, Message message, ProcessorResult processorResult, ParsedElement[] parsedElementArray) {
        return true;
    }

    protected boolean elementsFoundForAssertionAreValid(PolicyEnforcementContext policyEnforcementContext, Message message, ProcessorResult processorResult, ParsedElement[] parsedElementArray) {
        return true;
    }

    protected abstract String getPastTenseOperationName();

    protected abstract boolean isAllowIfEmpty();

    protected AssertionStatus onCheckRequestSuccess(PolicyEnforcementContext policyEnforcementContext, Message message, String string) {
        return AssertionStatus.NONE;
    }

    protected abstract ParsedElement[] getElementsFoundByProcessor(ProcessorResult var1);

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[5];
                var3_1 = 0;
                var2_2 = "@AB1auBJpN/vrdVWN(eyD\f@AS2vnu\\JG-t-DWRjcnYPAR7|n\u0018VJ@&\u007fyrVBD6ayRaAP1voBcVN'voEZJF";
                var4_3 = "@AB1auBJpN/vrdVWN(eyD\f@AS2vnu\\JG-t-DWRjcnYPAR7|n\u0018VJ@&\u007fyrVBD6ayRaAP1voBcVN'voEZJF".length();
                var1_4 = 21;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerRequireWssOperation.c(v0, ServerRequireWssOperation.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = ".\u001b\u0011t\"6H\n\u001f\u000b:=#\u0011\u0001\u0015\u001e~m&\u0007\u000e\u000f\u0012\u007f#6F\u0010#\u0015_Y\"/\u0018\u0004\u0016\u001a~\u00152\t\u0019\u0012";
                    var4_3 = ".\u001b\u0011t\"6H\n\u001f\u000b:=#\u0011\u0001\u0015\u001e~m&\u0007\u000e\u000f\u0012\u007f#6F\u0010#\u0015_Y\"/\u0018\u0004\u0016\u001a~\u00152\t\u0019\u0012".length();
                    var1_4 = 28;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 14;
                        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++] = ServerRequireWssOperation.c(v0, ServerRequireWssOperation.b(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;
            }
        }
        ServerRequireWssOperation.i = var5;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String c(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 -> 99;
                    case 1 -> 116;
                    case 2 -> 113;
                    case 3 -> 20;
                    case 4 -> 67;
                    case 5 -> 76;
                    default -> 102;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

