/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.rbac.EntityProtectionInfo
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeaderRef
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.util.Config
 *  com.l7tech.util.Pair
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.security.rbac;

import com.l7tech.gateway.common.security.rbac.EntityProtectionInfo;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeaderRef;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.server.security.rbac.o;
import com.l7tech.util.Config;
import com.l7tech.util.Pair;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/*
 * Exception performing whole class analysis ignored.
 */
public class ProtectedEntityTracker {
    @NotNull
    protected final Config config;
    private static final Map<String, EntityProtectionInfo> a;
    private static final ThreadLocal<Boolean> b;
    private static final String[] c;

    public ProtectedEntityTracker(@NotNull Config config) {
        if (config == null) {
            ProtectedEntityTracker.a(0);
        }
        this.config = config;
    }

    public boolean isEnabled() {
        return this.config.getBooleanProperty(c[9], true);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void bulkUpdateReadOnlyEntitiesList(Collection<Pair<EntityType, String>> collection) {
        Map<String, EntityProtectionInfo> map = a;
        synchronized (map) {
            a.clear();
            for (Pair<EntityType, String> pair : collection) {
                a.put((String)pair.right, new EntityProtectionInfo((EntityType)pair.left, true));
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Nullable
    public EntityProtectionInfo getEntityProtection(@NotNull String string) {
        try {
            if (string == null) {
                ProtectedEntityTracker.a(1);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ProtectedEntityTracker.a(illegalArgumentException);
        }
        Map<String, EntityProtectionInfo> map = a;
        synchronized (map) {
            return a.get(string);
        }
    }

    public boolean isReadOnlyEntity(@NotNull Entity entity) {
        boolean bl2;
        block12: {
            block11: {
                EntityProtectionInfo entityProtectionInfo;
                try {
                    if (entity == null) {
                        ProtectedEntityTracker.a(2);
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ProtectedEntityTracker.a(illegalArgumentException);
                }
                String string = entity.getId();
                try {
                    entityProtectionInfo = string == null ? null : this.getEntityProtection(string);
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ProtectedEntityTracker.a(illegalArgumentException);
                }
                EntityProtectionInfo entityProtectionInfo2 = entityProtectionInfo;
                try {
                    try {
                        try {
                            if (entityProtectionInfo2 == null || !entityProtectionInfo2.matchesTypeOf(entity)) break block11;
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw ProtectedEntityTracker.a(illegalArgumentException);
                        }
                        if (!entityProtectionInfo2.isReadOnly()) break block11;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw ProtectedEntityTracker.a(illegalArgumentException);
                    }
                    bl2 = true;
                    break block12;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ProtectedEntityTracker.a(illegalArgumentException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    public boolean isReadOnlyEntity(@NotNull EntityHeaderRef entityHeaderRef) {
        boolean bl2;
        block12: {
            block11: {
                EntityProtectionInfo entityProtectionInfo;
                try {
                    if (entityHeaderRef == null) {
                        ProtectedEntityTracker.a(3);
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ProtectedEntityTracker.a(illegalArgumentException);
                }
                String string = entityHeaderRef.getStrId();
                try {
                    entityProtectionInfo = string == null ? null : this.getEntityProtection(string);
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ProtectedEntityTracker.a(illegalArgumentException);
                }
                EntityProtectionInfo entityProtectionInfo2 = entityProtectionInfo;
                try {
                    try {
                        try {
                            if (entityProtectionInfo2 == null || !entityProtectionInfo2.matchesTypeOf(entityHeaderRef)) break block11;
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw ProtectedEntityTracker.a(illegalArgumentException);
                        }
                        if (!entityProtectionInfo2.isReadOnly()) break block11;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw ProtectedEntityTracker.a(illegalArgumentException);
                    }
                    bl2 = true;
                    break block12;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ProtectedEntityTracker.a(illegalArgumentException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    public boolean isEntityProtectionEnabled() {
        boolean bl2;
        block5: {
            block4: {
                try {
                    try {
                        if (!this.isEnabled() || !b.get().booleanValue()) break block4;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw ProtectedEntityTracker.a(illegalArgumentException);
                    }
                    bl2 = true;
                    break block5;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw ProtectedEntityTracker.a(illegalArgumentException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public <T> T doWithEntityProtectionDisabled(Callable<T> callable) throws Exception {
        boolean bl2 = b.get();
        try {
            b.set(false);
            T t2 = callable.call();
            return t2;
        }
        finally {
            b.set(bl2);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    @NotNull
    public Map<String, EntityProtectionInfo> getProtectedEntities() {
        if (this.isEnabled()) {
            HashMap<String, EntityProtectionInfo> hashMap;
            Map<String, EntityProtectionInfo> map2 = a;
            synchronized (map2) {
                hashMap = new HashMap<String, EntityProtectionInfo>(a);
            }
            if (hashMap != null) return hashMap;
            ProtectedEntityTracker.a(4);
            return hashMap;
        }
        try {
            Map<String, EntityProtectionInfo> map = Collections.emptyMap();
            if (map != null) Map<String, EntityProtectionInfo> map2;
            return map2;
            ProtectedEntityTracker.a(5);
            return map;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ProtectedEntityTracker.a(illegalArgumentException);
        }
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[12];
                var3_1 = 0;
                var2_2 = "AC~\b5\u0013Ft\u0011\u007f\u0012*VhN^m3-\u001aD Ax\u000f9\u001bMtTk]\u007fS['\u0011v\u001bxS[.\u0014j]5\u0003[t\u0011w\u0012,VJe\u0011w\b4\u001a\u0010iBK\u00189\u0012gn]`86\u0002AtH\u0006c^w\u001b1\u0011\be_m\u0014,\u000fad\u0002eY\u0013gTm86\u0002AtHI\u000f7\u0002McEp\u00126\u0006<Xw\u0014,H6c^tR4A\\eRqR+\u0013ZvTkR+\u0013KuCp\t!YZbPzR\b\u0004GtTz\t=\u0012mnEp\t!\"ZaRr\u0018*\u0014gTm-*\u0019\\eRm\u0018<3FtXm\u0014=\u0005\u001dpCv\t=\u0015\\eU\\\u0013,\u001f\\yek\u001c;\u001dMr\u001f|\u00139\u0014De";
                var4_3 = "AC~\b5\u0013Ft\u0011\u007f\u0012*VhN^m3-\u001aD Ax\u000f9\u001bMtTk]\u007fS['\u0011v\u001bxS[.\u0014j]5\u0003[t\u0011w\u0012,VJe\u0011w\b4\u001a\u0010iBK\u00189\u0012gn]`86\u0002AtH\u0006c^w\u001b1\u0011\be_m\u0014,\u000fad\u0002eY\u0013gTm86\u0002AtHI\u000f7\u0002McEp\u00126\u0006<Xw\u0014,H6c^tR4A\\eRqR+\u0013ZvTkR+\u0013KuCp\t!YZbPzR\b\u0004GtTz\t=\u0012mnEp\t!\"ZaRr\u0018*\u0014gTm-*\u0019\\eRm\u0018<3FtXm\u0014=\u0005\u001dpCv\t=\u0015\\eU\\\u0013,\u001f\\yek\u001c;\u001dMr\u001f|\u00139\u0014De".length();
                var1_4 = 62;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ProtectedEntityTracker.a(v0, ProtectedEntityTracker.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u0011.'XGR\u0015=@%I}O\u00165@m_'\u0002\nq\r=_}\u0007\u0017>\u0014h^lS\f#\u000ehB|K\u001562\u000f%\u0003e\u0010\r4\u0003 \u0003zB\u000b'\u0005:\u0003zB\u001a$\u0012!Xp\b\u000b3\u0001+\u0003YU\u0016%\u0005+XlC<?\u0014!Xps\u000b0\u0003#I{";
                    var4_3 = "\u0011.'XGR\u0015=@%I}O\u00165@m_'\u0002\nq\r=_}\u0007\u0017>\u0014h^lS\f#\u000ehB|K\u001562\u000f%\u0003e\u0010\r4\u0003 \u0003zB\u000b'\u0005:\u0003zB\u001a$\u0012!Xp\b\u000b3\u0001+\u0003YU\u0016%\u0005+XlC<?\u0014!Xps\u000b0\u0003#I{".length();
                    var1_4 = 42;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 74;
                        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++] = ProtectedEntityTracker.a(v0, ProtectedEntityTracker.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;
            }
        }
        ProtectedEntityTracker.c = var5;
        ProtectedEntityTracker.a = new HashMap<String, EntityProtectionInfo>();
        ProtectedEntityTracker.b = new o();
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void a(int var0) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [0[TRYBLOCK]], but top level block is 6[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1050)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

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

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x33);
        }
        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 -> 27;
                    case 1 -> 42;
                    case 2 -> 2;
                    case 3 -> 102;
                    case 4 -> 67;
                    case 5 -> 109;
                    default -> 51;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

