/*
 * 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.SamlAttributeStatement
 *  com.l7tech.policy.assertion.xmlsec.SamlAttributeStatement$Attribute
 *  com.l7tech.util.Pair
 *  org.apache.xmlbeans.XmlCursor
 *  org.apache.xmlbeans.XmlObject
 *  x0Assertion.oasisNamesTcSAML1.AttributeStatementType
 *  x0Assertion.oasisNamesTcSAML1.AttributeType
 */
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.SamlAttributeStatement;
import com.l7tech.server.policy.assertion.xmlsec.SamlAssertionValidate;
import com.l7tech.server.policy.assertion.xmlsec.SamlStatementValidate;
import com.l7tech.server.policy.assertion.xmlsec.h;
import com.l7tech.util.Pair;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlObject;
import x0Assertion.oasisNamesTcSAML1.AttributeStatementType;
import x0Assertion.oasisNamesTcSAML1.AttributeType;

class k
extends SamlStatementValidate {
    private SamlAttributeStatement a;
    private static final String[] c;

    k(RequireSaml requireSaml) {
        super(requireSaml);
        this.a = requireSaml.getAttributeStatement();
        if (this.a == null) {
            throw new IllegalArgumentException(c[0]);
        }
    }

    @Override
    protected void validate(XmlObject xmlObject, Collection<SamlAssertionValidate.Error> collection, Collection<Pair<String, String[]>> collection2, Map<String, Object> map, Audit audit) {
        SamlAttributeStatement.Attribute[] attributeArray;
        try {
            if (!(xmlObject instanceof AttributeStatementType)) {
                throw new IllegalArgumentException(c[4] + String.valueOf(AttributeStatementType.class));
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw k.a(illegalArgumentException);
        }
        AttributeStatementType attributeStatementType = (AttributeStatementType)xmlObject;
        AttributeType[] attributeTypeArray = attributeStatementType.getAttributeArray();
        for (SamlAttributeStatement.Attribute attribute : attributeArray = this.a.getAttributes()) {
            List<AttributeType> list;
            block11: {
                list = this.a(attribute, attributeTypeArray, collection);
                try {
                    if (list != null && !list.isEmpty()) break block11;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw k.a(illegalArgumentException);
                }
                SamlAssertionValidate.Error error = new SamlAssertionValidate.Error(c[1], null, attribute);
                try {
                    if (this.logger.isLoggable(Level.FINER)) {
                        this.logger.finer(error.toString());
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw k.a(illegalArgumentException);
                }
                collection.add(error);
                return;
            }
            if (collection2 == null) continue;
            for (AttributeType attributeType : list) {
                String string = attributeType.getAttributeName();
                ArrayList<String> arrayList = new ArrayList<String>();
                for (XmlObject xmlObject2 : attributeType.getAttributeValueArray()) {
                    String string2 = h.a(xmlObject2);
                    arrayList.add(string2);
                }
                collection2.add((Pair<String, String[]>)new Pair((Object)string, (Object)arrayList.toArray(new String[arrayList.size()])));
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Loose catch block
     */
    private List<AttributeType> a(SamlAttributeStatement.Attribute attribute, AttributeType[] attributeTypeArray, Collection collection) {
        ArrayList<AttributeType> arrayList;
        boolean bl2;
        String string;
        String string2;
        String string3;
        block28: {
            block33: {
                string3 = attribute.getName();
                string2 = attribute.getNamespace();
                string = attribute.getValue();
                bl2 = attribute.isAnyValue();
                if (this.a(string3)) break block33;
                try {
                    block34: {
                        if (bl2) break block28;
                        break block34;
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw k.a(illegalArgumentException);
                        }
                    }
                    if (!this.a(string)) break block28;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw k.a(illegalArgumentException);
                }
            }
            String[] stringArray = c;
            SamlAssertionValidate.Error error = new SamlAssertionValidate.Error(stringArray[5], null, new Object[0]);
            collection.add(error);
            this.logger.finer(error.toString());
            return null;
        }
        ArrayList<AttributeType> arrayList2 = new ArrayList<AttributeType>();
        for (AttributeType attributeType : attributeTypeArray) {
            XmlObject[] xmlObjectArray;
            block29: {
                block35: {
                    if (!string3.equals(attributeType.getAttributeName())) continue;
                    if (this.a(string2)) break block29;
                    break block35;
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw k.a(illegalArgumentException);
                    }
                }
                try {
                    if (!string2.equals(attributeType.getAttributeNamespace())) {
                        continue;
                    }
                    break block29;
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw k.a(illegalArgumentException);
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw k.a(illegalArgumentException);
                }
            }
            for (XmlObject xmlObject : xmlObjectArray = attributeType.getAttributeValueArray()) {
                XmlCursor xmlCursor = xmlObject.newCursor();
                try {
                    block32: {
                        block30: {
                            block31: {
                                block36: {
                                    if (!bl2) break block30;
                                    if (this.a(xmlCursor.getTextValue())) break block30;
                                    break block36;
                                    catch (IllegalArgumentException illegalArgumentException) {
                                        throw k.a(illegalArgumentException);
                                    }
                                }
                                try {
                                    block37: {
                                        if (!this.logger.isLoggable(Level.FINER)) break block31;
                                        break block37;
                                        catch (IllegalArgumentException illegalArgumentException) {
                                            throw k.a(illegalArgumentException);
                                        }
                                    }
                                    this.logger.finer(MessageFormat.format(c[2], string3, string));
                                }
                                catch (IllegalArgumentException illegalArgumentException) {
                                    throw k.a(illegalArgumentException);
                                }
                            }
                            arrayList2.add(attributeType);
                            continue;
                        }
                        if (!xmlCursor.getTextValue().equals(string)) continue;
                        try {
                            block38: {
                                if (!this.logger.isLoggable(Level.FINER)) break block32;
                                break block38;
                                catch (IllegalArgumentException illegalArgumentException) {
                                    throw k.a(illegalArgumentException);
                                }
                            }
                            this.logger.finer(MessageFormat.format(c[3], string3, string));
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw k.a(illegalArgumentException);
                        }
                    }
                    arrayList2.add(attributeType);
                }
                finally {
                    xmlCursor.dispose();
                }
            }
        }
        try {
            arrayList = arrayList2.isEmpty() ? null : arrayList2;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw k.a(illegalArgumentException);
        }
        return arrayList;
    }

    private boolean a(String string) {
        boolean bl2;
        block5: {
            block4: {
                try {
                    try {
                        if (string != null && !"".equals(string)) break block4;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw k.a(illegalArgumentException);
                    }
                    bl2 = true;
                    break block5;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw k.a(illegalArgumentException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[6];
                var3_1 = 0;
                var2_2 = "qaHZh2\u007fDp\u001cZd!\u007fYgYEd>~C5TIw5*^zH\bc5o^5OXd3cV|YL-~z\u001cE`$iX|RO!\u0011~DgUJt$o\u0010eNMr5dDpX\u0006!\u0002oA`UZd4*K%A\u001b}tHKi5n\u0010{]Edpq\u0000h\u0010\b`>s\u0010c]Dt5\u001c}tHKi5n\u0010{]Edpq\u0000h\u0010\bw1fEp\u001cS0-*";
                var4_3 = "qaHZh2\u007fDp\u001cZd!\u007fYgYEd>~C5TIw5*^zH\bc5o^5OXd3cV|YL-~z\u001cE`$iX|RO!\u0011~DgUJt$o\u0010eNMr5dDpX\u0006!\u0002oA`UZd4*K%A\u001b}tHKi5n\u0010{]Edpq\u0000h\u0010\b`>s\u0010c]Dt5\u001c}tHKi5n\u0010{]Edpq\u0000h\u0010\bw1fEp\u001cS0-*".length();
                var1_4 = 46;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = k.b(v0, k.c(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "owVWx>uN/4caPSw#t\nNRFi#r_{C\u0012x%~Y{TSr$d\n'HSv/0E}\u0006Dz&eO/OA;$eFc\u000f";
                    var4_3 = "owVWx>uN/4caPSw#t\nNRFi#r_{C\u0012x%~Y{TSr$d\n'HSv/0E}\u0006Dz&eO/OA;$eFc\u000f".length();
                    var1_4 = 9;
                    var0_5 = -1;
lbl22:
                    // 2 sources

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

    private static char[] c(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x46);
        }
        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 -> 124;
                    case 1 -> 89;
                    case 2 -> 112;
                    case 3 -> 100;
                    case 4 -> 77;
                    case 5 -> 28;
                    default -> 70;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

