/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.siteminder.SiteMinderContext
 *  com.l7tech.gateway.common.siteminder.SiteMinderContext$Attribute
 *  com.l7tech.gateway.common.siteminder.SiteMinderContext$AuthenticationScheme
 *  com.l7tech.gateway.common.siteminder.SiteMinderContext$SessionDef
 *  com.l7tech.policy.variable.Syntax$SyntaxErrorHandler
 *  com.l7tech.util.Functions$Unary
 *  com.l7tech.util.HexUtils
 *  org.apache.commons.lang3.StringUtils
 */
package com.l7tech.server.policy.variable;

import com.l7tech.gateway.common.siteminder.SiteMinderContext;
import com.l7tech.policy.variable.Syntax;
import com.l7tech.server.policy.variable.ExpandVariables;
import com.l7tech.server.policy.variable.fs;
import com.l7tech.server.policy.variable.ft;
import com.l7tech.server.policy.variable.fu;
import com.l7tech.util.Functions;
import com.l7tech.util.HexUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

public class SiteMinderContextSelector
implements ExpandVariables.Selector<SiteMinderContext> {
    protected static final Pattern ATTRUBUTES_PATTERN;
    protected static final Pattern AUTHSCHEME_PATTERN;
    protected static final Pattern REALMDEF_PATTERN;
    protected static final Pattern RESDEF_PATTERN;
    protected static final Pattern SESSDEF_PATTERN;
    private static final String[] a;

    @Override
    public ExpandVariables.Selector.Selection select(String string, SiteMinderContext siteMinderContext, String string2, Syntax.SyntaxErrorHandler syntaxErrorHandler, boolean bl2) {
        block59: {
            String string3 = string2.toLowerCase();
            try {
                if (null == siteMinderContext) {
                    return null;
                }
            }
            catch (NumberFormatException numberFormatException) {
                throw SiteMinderContextSelector.a(numberFormatException);
            }
            SiteMinderContext siteMinderContext2 = siteMinderContext;
            String[] stringArray = a;
            if (string3.startsWith(stringArray[7])) {
                List<SiteMinderContext.Attribute> list;
                block60: {
                    list = this.a(siteMinderContext2);
                    Matcher matcher = ATTRUBUTES_PATTERN.matcher(string3);
                    try {
                        try {
                            if (!matcher.find()) break block59;
                            if (!StringUtils.isNotEmpty((CharSequence)matcher.group(1))) break block60;
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw SiteMinderContextSelector.a(numberFormatException);
                        }
                        if (!StringUtils.isNotEmpty((CharSequence)matcher.group(3))) break block59;
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SiteMinderContextSelector.a(numberFormatException);
                    }
                    SiteMinderContext.Attribute attribute = SiteMinderContextSelector.a(list, matcher, syntaxErrorHandler);
                    String string4 = matcher.group(3).substring(1);
                    try {
                        if (string4.equals(a[23])) {
                            return new ExpandVariables.Selector.Selection(attribute.getName());
                        }
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SiteMinderContextSelector.a(numberFormatException);
                    }
                    try {
                        if (string4.equals(a[2])) {
                            return new ExpandVariables.Selector.Selection(attribute.getValue());
                        }
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SiteMinderContextSelector.a(numberFormatException);
                    }
                    try {
                        if (string4.equalsIgnoreCase(a[22])) {
                            return new ExpandVariables.Selector.Selection(this.a(attribute.getValue()));
                        }
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SiteMinderContextSelector.a(numberFormatException);
                    }
                    return null;
                }
                try {
                    if (string3.equals(a[6])) {
                        return new ExpandVariables.Selector.Selection(Integer.toString(list.size()));
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
                try {
                    if (string3.equals(a[19])) {
                        return new ExpandVariables.Selector.Selection(list, string2.substring(a[19].length()));
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
                stringArray = a;
                if (string3.length() > stringArray[19].length() + 1) {
                    String string5 = string3.substring(stringArray[19].length() + 1);
                    for (SiteMinderContext.Attribute attribute : list) {
                        try {
                            if (string5.equalsIgnoreCase(attribute.getName() + a[11])) {
                                return new ExpandVariables.Selector.Selection(this.a(attribute.getValue()));
                            }
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw SiteMinderContextSelector.a(numberFormatException);
                        }
                        try {
                            if (!string5.equalsIgnoreCase(attribute.getName())) continue;
                            return new ExpandVariables.Selector.Selection(attribute.getValue());
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw SiteMinderContextSelector.a(numberFormatException);
                        }
                    }
                }
            } else {
                try {
                    if (string3.equals(a[25])) {
                        return new ExpandVariables.Selector.Selection(siteMinderContext2.getSsoToken());
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
                try {
                    if (string3.equals(a[21])) {
                        return new ExpandVariables.Selector.Selection(siteMinderContext2.getTransactionId());
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
                try {
                    if (string3.equals(a[3])) {
                        return new ExpandVariables.Selector.Selection(siteMinderContext2.getSourceIpAddress());
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
                stringArray = a;
                if (string3.startsWith(stringArray[4])) {
                    Matcher matcher;
                    List list;
                    block61: {
                        list = siteMinderContext2.getAuthSchemes();
                        try {
                            if (string3.equals(stringArray[0])) {
                                return new ExpandVariables.Selector.Selection(Integer.toString(list.size()));
                            }
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw SiteMinderContextSelector.a(numberFormatException);
                        }
                        matcher = AUTHSCHEME_PATTERN.matcher(string3);
                        try {
                            if (!matcher.find()) break block59;
                            if (!StringUtils.isNotEmpty((CharSequence)matcher.group(2))) break block61;
                        }
                        catch (NumberFormatException numberFormatException) {
                            throw SiteMinderContextSelector.a(numberFormatException);
                        }
                        SiteMinderContext.AuthenticationScheme authenticationScheme = (SiteMinderContext.AuthenticationScheme)SiteMinderContextSelector.a(list, matcher, syntaxErrorHandler);
                        return new ExpandVariables.Selector.Selection(authenticationScheme.toString());
                    }
                    try {
                        if (StringUtils.isEmpty((CharSequence)matcher.group(1))) {
                            return this.a(string3, list);
                        }
                        break block59;
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SiteMinderContextSelector.a(numberFormatException);
                    }
                }
                try {
                    if (string3.startsWith(a[1])) {
                        return this.a(REALMDEF_PATTERN, string3, new fs(this, siteMinderContext2));
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
                try {
                    if (string3.startsWith(a[13])) {
                        return this.a(RESDEF_PATTERN, string3, new ft(this, siteMinderContext2));
                    }
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
                if (string3.startsWith(a[17])) {
                    SiteMinderContext.SessionDef sessionDef = siteMinderContext2.getSessionDef();
                    try {
                        if (null == sessionDef) {
                            return null;
                        }
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SiteMinderContextSelector.a(numberFormatException);
                    }
                    return this.a(SESSDEF_PATTERN, string3, new fu(this, sessionDef));
                }
            }
        }
        return null;
    }

    private List<SiteMinderContext.Attribute> a(SiteMinderContext siteMinderContext) {
        List list;
        try {
            list = null != siteMinderContext.getAttrList() ? new ArrayList(siteMinderContext.getAttrList()) : Collections.EMPTY_LIST;
        }
        catch (NumberFormatException numberFormatException) {
            throw SiteMinderContextSelector.a(numberFormatException);
        }
        List list2 = list;
        try {
            if (null != siteMinderContext.getSessionDef()) {
                list2.add(new SiteMinderContext.Attribute(a[9], (Object)siteMinderContext.getSessionDef().getId()));
                list2.add(new SiteMinderContext.Attribute(a[10], (Object)siteMinderContext.getSessionDef().getSpec()));
                list2.add(new SiteMinderContext.Attribute(a[26], (Object)siteMinderContext.getSessionDef().getSessionStartTime()));
                list2.add(new SiteMinderContext.Attribute(a[24], (Object)siteMinderContext.getSessionDef().getSessionLastTime()));
                list2.add(new SiteMinderContext.Attribute(a[20], (Object)siteMinderContext.getSessionDef().getMaxTimeout()));
                list2.add(new SiteMinderContext.Attribute(a[15], (Object)siteMinderContext.getSessionDef().getIdleTimeout()));
                list2.add(new SiteMinderContext.Attribute(a[8], (Object)siteMinderContext.getSessionDef().getCurrentServerTime()));
            }
        }
        catch (NumberFormatException numberFormatException) {
            throw SiteMinderContextSelector.a(numberFormatException);
        }
        return list2;
    }

    private ExpandVariables.Selector.Selection a(Pattern pattern, String string, Functions.Unary<ExpandVariables.Selector.Selection, String> unary) {
        Matcher matcher = pattern.matcher(string);
        if (matcher.find()) {
            String string2 = matcher.group(1);
            try {
                if (StringUtils.isNotEmpty((CharSequence)string2)) {
                    return (ExpandVariables.Selector.Selection)unary.call((Object)string2);
                }
            }
            catch (NumberFormatException numberFormatException) {
                throw SiteMinderContextSelector.a(numberFormatException);
            }
        }
        return null;
    }

    private ExpandVariables.Selector.Selection a(String string, List<SiteMinderContext.AuthenticationScheme> list) {
        ArrayList<String> arrayList = new ArrayList<String>(list.size());
        for (SiteMinderContext.AuthenticationScheme authenticationScheme : list) {
            arrayList.add(authenticationScheme.toString());
        }
        return new ExpandVariables.Selector.Selection(arrayList, string.substring(a[5].length()));
    }

    private static <T> T a(List<T> list, Matcher matcher, Syntax.SyntaxErrorHandler syntaxErrorHandler) {
        T t2;
        block6: {
            int n2;
            block7: {
                t2 = null;
                try {
                    n2 = Integer.parseInt(matcher.group(2));
                }
                catch (NumberFormatException numberFormatException) {
                    throw new RuntimeException(syntaxErrorHandler.handleBadVariable(matcher.group(), (Throwable)numberFormatException));
                }
                try {
                    try {
                        if (null == list) break block6;
                        if (n2 < list.size()) break block7;
                    }
                    catch (NumberFormatException numberFormatException) {
                        throw SiteMinderContextSelector.a(numberFormatException);
                    }
                    throw new RuntimeException(syntaxErrorHandler.handleSubscriptOutOfRange(n2, matcher.group(), list.size()));
                }
                catch (NumberFormatException numberFormatException) {
                    throw SiteMinderContextSelector.a(numberFormatException);
                }
            }
            t2 = list.get(n2);
        }
        return t2;
    }

    private String a(Object object) {
        try {
            if (object.getClass().isAssignableFrom(byte[].class)) {
                return HexUtils.hexDump((byte[])((byte[])object));
            }
        }
        catch (NumberFormatException numberFormatException) {
            throw SiteMinderContextSelector.a(numberFormatException);
        }
        try {
            if (object.getClass().isAssignableFrom(Integer.TYPE)) {
                return Integer.toString((Integer)object);
            }
        }
        catch (NumberFormatException numberFormatException) {
            throw SiteMinderContextSelector.a(numberFormatException);
        }
        try {
            if (object.getClass().isAssignableFrom(String.class)) {
                return (String)object;
            }
        }
        catch (NumberFormatException numberFormatException) {
            throw SiteMinderContextSelector.a(numberFormatException);
        }
        return object.toString();
    }

    @Override
    public Class<SiteMinderContext> getContextObjectClass() {
        return SiteMinderContext.class;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[28];
                var3_1 = 0;
                var2_2 = "'\u0007z\u001e#c4#\u001fk\u0005~l9(\u0015z\u001e\b4\u0017o\u001a=d9 \u00050\u0013b\u00035\u000f5\u001d{\u00043e56\u0013j\u0012\"e/5\u000b'\u0007z\u001e#c4#\u001fk\u0005\u000b'\u0007z\u001e#c4#\u001fk\u0005\u0011'\u0006z\u00049b)2\u0017}X<e2!\u0006f\n'\u0006z\u00049b)2\u0017}\u0016\u0007&Z$\u000fC\t\u0014 K8\u0004S\u0019\u0014$K$\u0004I\u0011\u0003\u000e\u0007&Z$\u000fS\u0019\u0015!G9\u001eI\u0018\u0010\u0007&Z$\u000fS\u0019\u0015!G9\u001eS\f\u00031\th\u0006a%$r5(\u0015\u000e5\u0017}\u00054e:\u001a\\&*'+u\u000b4\u0017}\u0019%r?#\u0016k\u0010!'\u0006z\u00049b)2\u0017}^\f.t\u001a\u0016%_x(\u0000h.y\ra,!oX'_o\u0017\u0007&Z$\u000fI\u0018\n7]3\u0003S\u0015\t<Z?\u001dE\u0013\u0013&\u000f4\u0017o\u001a=d9 . ^\fwwo\u00075\u0017}\u00054e:\u0017'\u0007z\u001e#c4#\u001fk\u0005x\\\u0007n.j]y\\\u0001oM\n'\u0006z\u00049b)2\u0017}\u0016\u0007&Z$\u000fM\u001d\u001e!K%\u0003I\u0013\b&G;\u0015O\t\u0012\r2\u0000o\u0018#a?2\u001ba\u00189d\u000e0\u0013b\u00035.()\u0001z\u00049n;\u0004(\u0013c\u0013\u0014\u0007&Z$\u000fL\u001d\u0015&]3\u0003S\u0015\t<Z?\u001dE\b5\u0001a\u0002?k9(";
                var4_3 = "'\u0007z\u001e#c4#\u001fk\u0005~l9(\u0015z\u001e\b4\u0017o\u001a=d9 \u00050\u0013b\u00035\u000f5\u001d{\u00043e56\u0013j\u0012\"e/5\u000b'\u0007z\u001e#c4#\u001fk\u0005\u000b'\u0007z\u001e#c4#\u001fk\u0005\u0011'\u0006z\u00049b)2\u0017}X<e2!\u0006f\n'\u0006z\u00049b)2\u0017}\u0016\u0007&Z$\u000fC\t\u0014 K8\u0004S\u0019\u0014$K$\u0004I\u0011\u0003\u000e\u0007&Z$\u000fS\u0019\u0015!G9\u001eI\u0018\u0010\u0007&Z$\u000fS\u0019\u0015!G9\u001eS\f\u00031\th\u0006a%$r5(\u0015\u000e5\u0017}\u00054e:\u001a\\&*'+u\u000b4\u0017}\u0019%r?#\u0016k\u0010!'\u0006z\u00049b)2\u0017}^\f.t\u001a\u0016%_x(\u0000h.y\ra,!oX'_o\u0017\u0007&Z$\u000fI\u0018\n7]3\u0003S\u0015\t<Z?\u001dE\u0013\u0013&\u000f4\u0017o\u001a=d9 . ^\fwwo\u00075\u0017}\u00054e:\u0017'\u0007z\u001e#c4#\u001fk\u0005x\\\u0007n.j]y\\\u0001oM\n'\u0006z\u00049b)2\u0017}\u0016\u0007&Z$\u000fM\u001d\u001e!K%\u0003I\u0013\b&G;\u0015O\t\u0012\r2\u0000o\u0018#a?2\u001ba\u00189d\u000e0\u0013b\u00035.()\u0001z\u00049n;\u0004(\u0013c\u0013\u0014\u0007&Z$\u000fL\u001d\u0015&]3\u0003S\u0015\t<Z?\u001dE\b5\u0001a\u0002?k9(".length();
                var1_4 = 18;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = SiteMinderContextSelector.a(v0, SiteMinderContextSelector.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "_~\u0002|W\u000bP_x\u0002}M\u000bWWe\u0018zA\u0015A\u0012lO%A}*g{N3HTv,B]}\u0007";
                    var4_3 = "_~\u0002|W\u000bP_x\u0002}M\u000bWWe\u0018zA\u0015A\u0012lO%A}*g{N3HTv,B]}\u0007".length();
                    var1_4 = 21;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 19;
                        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++] = SiteMinderContextSelector.a(v0, SiteMinderContextSelector.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;
            }
        }
        SiteMinderContextSelector.a = var5;
        var0_6 = SiteMinderContextSelector.a;
        SiteMinderContextSelector.ATTRUBUTES_PATTERN = Pattern.compile(var0_6[14]);
        SiteMinderContextSelector.AUTHSCHEME_PATTERN = Pattern.compile(var0_6[18]);
        SiteMinderContextSelector.REALMDEF_PATTERN = Pattern.compile(var0_6[16]);
        SiteMinderContextSelector.RESDEF_PATTERN = Pattern.compile(var0_6[27]);
        SiteMinderContextSelector.SESSDEF_PATTERN = Pattern.compile(var0_6[12]);
    }

    private static NumberFormatException a(NumberFormatException numberFormatException) {
        return numberFormatException;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(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 -> 13;
                    case 1 -> 57;
                    case 2 -> 69;
                    case 3 -> 61;
                    case 4 -> 27;
                    case 5 -> 75;
                    default -> 23;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

