/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.keystore.SsgKeyEntry
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.util.Functions$Nullary
 *  com.l7tech.util.Pair
 *  org.springframework.beans.factory.InitializingBean
 */
package com.l7tech.server;

import com.l7tech.gateway.common.security.keystore.SsgKeyEntry;
import com.l7tech.objectmodel.Goid;
import com.l7tech.server.DefaultKey;
import com.l7tech.server.ab;
import com.l7tech.server.bz;
import com.l7tech.server.security.keystore.KeyAccessFilter;
import com.l7tech.util.Functions;
import com.l7tech.util.Pair;
import java.util.concurrent.Callable;
import java.util.logging.Logger;
import org.springframework.beans.factory.InitializingBean;

public class GatewayKeyAccessFilter
implements KeyAccessFilter,
InitializingBean {
    private static final Logger a;
    private static final ThreadLocal<Boolean> b;
    private DefaultKey c;
    private static final String d;

    public void setDefaultKey(DefaultKey defaultKey) {
        this.c = defaultKey;
    }

    @Override
    public boolean isRestrictedAccessKeyEntry(SsgKeyEntry ssgKeyEntry) {
        boolean bl2;
        block8: {
            if (this.c == null) {
                String string = d;
                a.severe(string);
                throw new IllegalStateException(string);
            }
            bl2 = false;
            Pair<Goid, String> pair = this.c.getAuditViewerAlias();
            if (pair != null) {
                block9: {
                    Goid goid = (Goid)pair.left;
                    String string = (String)pair.right;
                    try {
                        try {
                            try {
                                if (string == null || !string.equalsIgnoreCase(ssgKeyEntry.getAlias())) break block8;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw GatewayKeyAccessFilter.a(illegalStateException);
                            }
                            if (Goid.isDefault((Goid)goid)) break block9;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw GatewayKeyAccessFilter.a(illegalStateException);
                        }
                        if (!Goid.equals((Goid)goid, (Goid)ssgKeyEntry.getKeystoreId())) break block8;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw GatewayKeyAccessFilter.a(illegalStateException);
                    }
                }
                bl2 = true;
            }
        }
        return bl2;
    }

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

    public void afterPropertiesSet() throws Exception {
        SsgKeyEntry.setRestrictedKeyAccessChecker((Functions.Nullary)new ab(this));
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        d = GatewayKeyAccessFilter.a(49, GatewayKeyAccessFilter.a("\u007fGHU\u0016#BPGW\u0014\r B;R\\[\u0015&R~F\u000eM\u0006;\u00166\u000f\u000e]\r,YiPKW\u0017o_uKZ]\u0002#_aCZ]\f!\u0016tPJQ\u0011"));
        a = Logger.getLogger(GatewayKeyAccessFilter.class.getName());
        b = new bz();
    }

    private static IllegalStateException a(IllegalStateException illegalStateException) {
        return illegalStateException;
    }

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

