/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.Audit
 *  com.l7tech.policy.assertion.xmlsec.RequireSaml
 *  com.l7tech.policy.assertion.xmlsec.SamlAuthenticationStatement
 *  com.l7tech.security.saml.SamlConstants
 *  com.l7tech.util.ArrayUtils
 *  com.l7tech.util.Pair
 *  org.apache.xmlbeans.XmlObject
 *  x0Assertion.oasisNamesTcSAML2.AuthnContextType
 *  x0Assertion.oasisNamesTcSAML2.AuthnStatementType
 */
package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.policy.assertion.xmlsec.RequireSaml;
import com.l7tech.policy.assertion.xmlsec.SamlAuthenticationStatement;
import com.l7tech.security.saml.SamlConstants;
import com.l7tech.server.policy.assertion.xmlsec.SamlAssertionValidate;
import com.l7tech.server.policy.assertion.xmlsec.SamlStatementValidate;
import com.l7tech.util.ArrayUtils;
import com.l7tech.util.Pair;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import org.apache.xmlbeans.XmlObject;
import x0Assertion.oasisNamesTcSAML2.AuthnContextType;
import x0Assertion.oasisNamesTcSAML2.AuthnStatementType;

class i
extends SamlStatementValidate {
    private SamlAuthenticationStatement a;
    private static final String[] c;

    i(RequireSaml requireSaml) {
        super(requireSaml);
        this.a = requireSaml.getAuthenticationStatement();
        if (this.a == null) {
            throw new IllegalArgumentException(c[1]);
        }
    }

    @Override
    protected void validate(XmlObject xmlObject, Collection<SamlAssertionValidate.Error> collection, Collection<Pair<String, String[]>> collection2, Map<String, Object> map, Audit audit) {
        try {
            if (!(xmlObject instanceof AuthnStatementType)) {
                throw new IllegalArgumentException(c[0] + String.valueOf(AuthnStatementType.class));
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw i.a(illegalArgumentException);
        }
        AuthnStatementType authnStatementType = (AuthnStatementType)xmlObject;
        AuthnContextType authnContextType = authnStatementType.getAuthnContext();
        String string = null;
        if (authnContextType != null) {
            string = authnContextType.getAuthnContextClassRef();
        }
        if (string == null) {
            SamlAssertionValidate.Error error = new SamlAssertionValidate.Error(c[2], null, new Object[0]);
            collection.add(error);
            this.logger.finer(error.toString());
            return;
        }
        String[] stringArray = (String[])ArrayUtils.copy((Object[])this.a.getAuthenticationMethods());
        for (int i2 = 0; i2 < stringArray.length; ++i2) {
            String string2 = stringArray[i2];
            String string3 = (String)SamlConstants.AUTH_MAP_SAML_1TO2.get(string2);
            try {
                if (string3 == null) continue;
                stringArray[i2] = string3;
                continue;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw i.a(illegalArgumentException);
            }
        }
        String string4 = this.a.getCustomAuthenticationMethods();
        this.validateAuthenticationMethods(string, Arrays.asList(stringArray), string4, collection, map, audit);
    }

    private static IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "\u001fP*b6Qh>\b3\u001b].o0Ky3K;s<JczZ?v L\u007f?E?i!V-2I,buKb.\b8b0K-)X?d<Cd?L\"\u0014GzF Qe?F.n6Dy3G4'\u0018@y2G>'&Uh9A<n0A";
        int n3 = "\u001fP*b6Qh>\b3\u001b].o0Ky3K;s<JczZ?v L\u007f?E?i!V-2I,buKb.\b8b0K-)X?d<Cd?L\"\u0014GzF Qe?F.n6Dy3G4'\u0018@y2G>'&Uh9A<n0A".length();
        int n4 = 9;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = i.b(6, i.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                c = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0xB);
        }
        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 -> 92;
                    case 1 -> 46;
                    case 2 -> 92;
                    case 3 -> 1;
                    case 4 -> 83;
                    case 5 -> 35;
                    default -> 11;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

