/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.LicenseException
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.policy.assertion.Assertion
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.Include
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.util.ExceptionUtils
 *  com.l7tech.util.ResourceUtils
 *  org.springframework.beans.BeansException
 *  org.springframework.context.ApplicationContext
 */
package com.l7tech.server.policy.assertion;

import com.l7tech.gateway.common.LicenseException;
import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.policy.assertion.Assertion;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.Include;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.PolicyCache;
import com.l7tech.server.policy.ServerPolicyException;
import com.l7tech.server.policy.ServerPolicyHandle;
import com.l7tech.server.policy.assertion.AbstractServerAssertion;
import com.l7tech.util.ExceptionUtils;
import com.l7tech.util.ResourceUtils;
import java.io.Closeable;
import java.io.IOException;
import java.util.logging.Level;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;

public class ServerInclude
extends AbstractServerAssertion<Include> {
    private final ServerPolicyHandle d;
    private static final String[] e;

    public ServerInclude(Include include, ApplicationContext applicationContext) throws ServerPolicyException, LicenseException {
        super(include);
        try {
            ServerPolicyHandle serverPolicyHandle;
            String[] stringArray = e;
            PolicyCache policyCache = (PolicyCache)applicationContext.getBean(stringArray[0], PolicyCache.class);
            String string = include.getPolicyGuid();
            try {
                ServerInclude serverInclude = this;
                serverPolicyHandle = string == null ? null : policyCache.getServerPolicy(string);
            }
            catch (BeansException beansException) {
                throw ServerInclude.a(beansException);
            }
            serverInclude.d = serverPolicyHandle;
        }
        catch (BeansException beansException) {
            String[] stringArray = e;
            this.logger.log(Level.WARNING, stringArray[1], beansException);
            throw new ServerPolicyException((Assertion)include, stringArray[3], beansException);
        }
    }

    @Override
    public AssertionStatus checkRequest(PolicyEnforcementContext policyEnforcementContext) throws PolicyAssertionException, IOException {
        policyEnforcementContext.pushAssertionOrdinal(((Include)this.assertion).getOrdinal());
        try {
            if (this.d != null) {
                AssertionStatus assertionStatus = this.d.checkRequest(policyEnforcementContext);
                return assertionStatus;
            }
            try {
                String string = e[2] + ((Include)this.assertion).getPolicyGuid();
                this.logAndAudit((AuditDetailMessage)AssertionMessages.INCLUDE_POLICY_INVALID, string);
                throw new PolicyAssertionException(this.assertion, string);
            }
            catch (IOException iOException) {
                this.logAndAudit((AuditDetailMessage)AssertionMessages.INCLUDE_POLICY_FAILURE, ExceptionUtils.getMessage((Throwable)iOException));
                throw iOException;
            }
            catch (PolicyAssertionException policyAssertionException) {
                this.logAndAudit((AuditDetailMessage)AssertionMessages.INCLUDE_POLICY_FAILURE, ExceptionUtils.getMessage((Throwable)policyAssertionException));
                throw policyAssertionException;
            }
        }
        finally {
            policyEnforcementContext.popAssertionOrdinal();
        }
    }

    @Override
    public void close() {
        ResourceUtils.closeQuietly((Closeable)this.d);
    }

    private static BeansException a(BeansException beansException) {
        return beansException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[4];
                var3_1 = 0;
                var2_2 = "_t\u001a2Y$6Nx\u001e>\u001cji\u00044H}\u0014Lx\u0013(I4\u001bH;\u00064V4\u0016V;\u0015:Y5\u0010";
                var4_3 = "_t\u001a2Y$6Nx\u001e>\u001cji\u00044H}\u0014Lx\u0013(I4\u001bH;\u00064V4\u0016V;\u0015:Y5\u0010".length();
                var1_4 = 11;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerInclude.b(v0, ServerInclude.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u0000\u0010gJ1Qpm\u0010zZ4Js(\u001d4I7S~.\u00004\u001a\u001c\b\u000bfV*\u001fv.\u001aqJ+Vy*YdV4Vt4YwX;Wr";
                    var4_3 = "\u0000\u0010gJ1Qpm\u0010zZ4Js(\u001d4I7S~.\u00004\u001a\u001c\b\u000bfV*\u001fv.\u001aqJ+Vy*YdV4Vt4YwX;Wr".length();
                    var1_4 = 25;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 68;
                        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++] = ServerInclude.b(v0, ServerInclude.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;
            }
        }
        ServerInclude.e = var5;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 9;
                    case 1 -> 61;
                    case 2 -> 80;
                    case 3 -> 125;
                    case 4 -> 28;
                    case 5 -> 123;
                    default -> 83;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

