/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.io.XmlUtil
 *  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.security.saml.SamlConstants
 *  com.l7tech.util.Pair
 *  com.l7tech.util.PoolByteArrayOutputStream
 *  org.apache.xmlbeans.XmlCursor
 *  org.apache.xmlbeans.XmlObject
 *  x0Assertion.oasisNamesTcSAML2.AttributeStatementType
 *  x0Assertion.oasisNamesTcSAML2.AttributeType
 */
package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.common.io.XmlUtil;
import com.l7tech.gateway.common.audit.Audit;
import com.l7tech.policy.assertion.xmlsec.RequireSaml;
import com.l7tech.policy.assertion.xmlsec.SamlAttributeStatement;
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.Pair;
import com.l7tech.util.PoolByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
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 org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import x0Assertion.oasisNamesTcSAML2.AttributeStatementType;
import x0Assertion.oasisNamesTcSAML2.AttributeType;

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

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

    @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[5] + String.valueOf(AttributeStatementType.class));
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw h.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 h.a(illegalArgumentException);
                }
                SamlAssertionValidate.Error error = new SamlAssertionValidate.Error(c[0], null, attribute);
                try {
                    if (this.logger.isLoggable(Level.FINER)) {
                        this.logger.finer(error.toString());
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw h.a(illegalArgumentException);
                }
                collection.add(error);
                return;
            }
            if (collection2 == null) continue;
            for (AttributeType attributeType : list) {
                String string = attributeType.getName();
                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()])));
            }
        }
    }

    private static String a(Node node) throws IOException {
        PoolByteArrayOutputStream poolByteArrayOutputStream = new PoolByteArrayOutputStream();
        XmlUtil.canonicalize((Node)node, (OutputStream)poolByteArrayOutputStream);
        return poolByteArrayOutputStream.toString();
    }

    static String a(XmlObject xmlObject) {
        try {
            Node node;
            block7: {
                block6: {
                    node = xmlObject.getDomNode();
                    try {
                        if (1 == node.getNodeType() && c[6].equals(node.getLocalName())) break block6;
                    }
                    catch (IOException iOException) {
                        throw h.a(iOException);
                    }
                    return h.a(node);
                }
                NodeList nodeList = node.getChildNodes();
                try {
                    if (nodeList.getLength() != 1 || nodeList.item(0).getNodeType() != 3) break block7;
                }
                catch (IOException iOException) {
                    throw h.a(iOException);
                }
                return XmlUtil.getTextValue((Element)((Element)node));
            }
            return h.a(node);
        }
        catch (IOException iOException) {
            throw new RuntimeException(iOException);
        }
    }

    /*
     * 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;
        String string;
        String string2;
        block30: {
            string2 = attribute.getName();
            string = attribute.getNameFormat();
            try {
                if (string != null && string.length() != 0) break block30;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw h.a(illegalArgumentException);
            }
            string = SamlConstants.ATTRIBUTE_NAME_FORMAT_UNSPECIFIED;
        }
        String string3 = attribute.getValue();
        boolean bl2 = attribute.isAnyValue();
        if (this.a(string2)) {
            String[] stringArray = c;
            SamlAssertionValidate.Error error = new SamlAssertionValidate.Error(stringArray[3], 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;
            block31: {
                block32: {
                    block36: {
                        if (!string2.equals(attributeType.getName())) continue;
                        String string4 = attributeType.getNameFormat();
                        if (string4 == null) {
                            string4 = SamlConstants.ATTRIBUTE_NAME_FORMAT_UNSPECIFIED;
                        }
                        try {
                            if (!string.equals(string4)) {
                                continue;
                            }
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw h.a(illegalArgumentException);
                        }
                        if (!this.a(string3)) break block31;
                        if (attributeType.getAttributeValueArray().length != 0) break block31;
                        break block36;
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw h.a(illegalArgumentException);
                        }
                    }
                    try {
                        block37: {
                            if (!this.logger.isLoggable(Level.FINER)) break block32;
                            break block37;
                            catch (IllegalArgumentException illegalArgumentException) {
                                throw h.a(illegalArgumentException);
                            }
                        }
                        this.logger.log(Level.FINER, c[1], new Object[]{string2});
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw h.a(illegalArgumentException);
                    }
                }
                arrayList2.add(attributeType);
            }
            for (XmlObject xmlObject : xmlObjectArray = attributeType.getAttributeValueArray()) {
                XmlCursor xmlCursor = xmlObject.newCursor();
                try {
                    block35: {
                        block33: {
                            block34: {
                                block38: {
                                    if (!bl2) break block33;
                                    if (this.a(xmlCursor.getTextValue())) break block33;
                                    break block38;
                                    catch (IllegalArgumentException illegalArgumentException) {
                                        throw h.a(illegalArgumentException);
                                    }
                                }
                                try {
                                    block39: {
                                        if (!this.logger.isLoggable(Level.FINER)) break block34;
                                        break block39;
                                        catch (IllegalArgumentException illegalArgumentException) {
                                            throw h.a(illegalArgumentException);
                                        }
                                    }
                                    this.logger.finer(MessageFormat.format(c[7], string2, string3));
                                }
                                catch (IllegalArgumentException illegalArgumentException) {
                                    throw h.a(illegalArgumentException);
                                }
                            }
                            arrayList2.add(attributeType);
                            continue;
                        }
                        if (!xmlCursor.getTextValue().equals(string3)) continue;
                        try {
                            block40: {
                                if (!this.logger.isLoggable(Level.FINER)) break block35;
                                break block40;
                                catch (IllegalArgumentException illegalArgumentException) {
                                    throw h.a(illegalArgumentException);
                                }
                            }
                            this.logger.finer(MessageFormat.format(c[2], string2, string3));
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw h.a(illegalArgumentException);
                        }
                    }
                    arrayList2.add(attributeType);
                }
                finally {
                    xmlCursor.dispose();
                }
            }
        }
        try {
            arrayList = arrayList2.isEmpty() ? null : arrayList2;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw h.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 h.a(illegalArgumentException);
                    }
                    bl2 = true;
                    break block5;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw h.a(illegalArgumentException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "\u001cDE?h\u001e(:B\u000b5)+?&Y\f0|\u001e.r[\u00177z\u000f%&N\u0001|)8.#^\f l\u000ek)\u001b\u0018*\u001fJ\u00111a\u000f/rE\u0004?lJ0bVE%`\u001e#rE\nr\u007f\u000b''N\u0016ry\u0018.!N\u000b&l\u000ee\u001c\u001fJ\u00111a\u000f/rE\u0004?lJ0bVIr\u007f\u000b''NE)8\u0017k+\u001bE\u00133e\u0003/rj\u0011&{\u0003)'_\u0000rj\u0005%!_\u00173`\u0004?r\u0003\u000b3d\u000fk;XE<|\u0006'{.\u0013_\u0011 `\b>&NE l\u001b>;Y\u0000?l\u0004?!\u000b\r3\u007f\u000fk<D\u0011rk\u000f.<\u000b\u0016\"l\t\"4B\u00006\t\u0017S\u00157j\u001e.6\u000b";
                var4_3 = "\u001cDE?h\u001e(:B\u000b5)+?&Y\f0|\u001e.r[\u00177z\u000f%&N\u0001|)8.#^\f l\u000ek)\u001b\u0018*\u001fJ\u00111a\u000f/rE\u0004?lJ0bVE%`\u001e#rE\nr\u007f\u000b''N\u0016ry\u0018.!N\u000b&l\u000ee\u001c\u001fJ\u00111a\u000f/rE\u0004?lJ0bVIr\u007f\u000b''NE)8\u0017k+\u001bE\u00133e\u0003/rj\u0011&{\u0003)'_\u0000rj\u0005%!_\u00173`\u0004?r\u0003\u000b3d\u000fk;XE<|\u0006'{.\u0013_\u0011 `\b>&NE l\u001b>;Y\u0000?l\u0004?!\u000b\r3\u007f\u000fk<D\u0011rk\u000f.<\u000b\u0016\"l\t\"4B\u00006\t\u0017S\u00157j\u001e.6\u000b".length();
                var1_4 = 45;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = h.b(v0, h.c(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "x4zK\u000bcUM%XX\u000etE\u001bt!zZ\ndD\u0019.oT\u0007![\t=\"\u0019\u0003oY\u00196oU\u0017d";
                    var4_3 = "x4zK\u000bcUM%XX\u000etE\u001bt!zZ\ndD\u0019.oT\u0007![\t=\"\u0019\u0003oY\u00196oU\u0017d".length();
                    var1_4 = 14;
                    var0_5 = -1;
lbl22:
                    // 2 sources

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

    private static char[] c(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x57);
        }
        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 -> 78;
                    case 1 -> 55;
                    case 2 -> 121;
                    case 3 -> 78;
                    case 4 -> 21;
                    case 5 -> 118;
                    default -> 87;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

