/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.PrivateKeySecured
 *  com.l7tech.gateway.common.security.PrivateKeySecured$ReturnCheck
 *  com.l7tech.gateway.common.security.keystore.SsgKeyEntry
 *  com.l7tech.gateway.common.security.keystore.SsgKeyMetadata
 *  com.l7tech.gateway.common.security.rbac.OperationType
 *  com.l7tech.gateway.common.security.rbac.PermissionDeniedException
 *  com.l7tech.identity.User
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.ObjectNotFoundException
 *  jakarta.inject.Inject
 *  jakarta.inject.Named
 *  org.aopalliance.intercept.MethodInvocation
 *  org.jetbrains.annotations.NotNull
 *  org.jetbrains.annotations.Nullable
 */
package com.l7tech.server.admin;

import com.l7tech.gateway.common.security.PrivateKeySecured;
import com.l7tech.gateway.common.security.keystore.SsgKeyEntry;
import com.l7tech.gateway.common.security.keystore.SsgKeyMetadata;
import com.l7tech.gateway.common.security.rbac.OperationType;
import com.l7tech.gateway.common.security.rbac.PermissionDeniedException;
import com.l7tech.identity.User;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectNotFoundException;
import com.l7tech.server.security.keystore.SsgKeyFinder;
import com.l7tech.server.security.keystore.SsgKeyStoreManager;
import com.l7tech.server.security.rbac.CustomRbacInterceptor;
import com.l7tech.server.security.rbac.RbacServices;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.security.KeyStoreException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.aopalliance.intercept.MethodInvocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/*
 * Exception performing whole class analysis ignored.
 */
public class PrivateKeyRbacInterceptor
implements CustomRbacInterceptor {
    User a;
    @Inject
    @Named(value="rbacServices")
    RbacServices rbacServices;
    @Inject
    @Named(value="ssgKeyStoreManager")
    SsgKeyStoreManager ssgKeyStoreManager;
    private Map<Goid, SsgKeyFinder> b = new HashMap<Goid, SsgKeyFinder>();
    private static final String[] c;

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    public Object invoke(@NotNull MethodInvocation methodInvocation) throws Throwable {
        try {
            if (methodInvocation == null) {
                PrivateKeyRbacInterceptor.a(0);
            }
        }
        catch (Throwable throwable) {
            throw PrivateKeyRbacInterceptor.a(throwable);
        }
        try {
            if (null == this.a) {
                throw new IllegalStateException(c[15]);
            }
        }
        catch (Throwable throwable) {
            throw PrivateKeyRbacInterceptor.a(throwable);
        }
        try {
            if (this.rbacServices == null) {
                throw new IllegalStateException(c[11]);
            }
        }
        catch (Throwable throwable) {
            throw PrivateKeyRbacInterceptor.a(throwable);
        }
        try {
            if (this.ssgKeyStoreManager == null) {
                throw new IllegalStateException(c[4]);
            }
        }
        catch (Throwable throwable) {
            throw PrivateKeyRbacInterceptor.a(throwable);
        }
        String string = methodInvocation.getMethod().getName();
        PrivateKeySecured privateKeySecured = methodInvocation.getMethod().getAnnotation(PrivateKeySecured.class);
        try {
            if (null == privateKeySecured) {
                throw new IllegalStateException(c[2]);
            }
        }
        catch (Throwable throwable) {
            throw PrivateKeyRbacInterceptor.a(throwable);
        }
        try {
            this.b.clear();
            if (!this.a(methodInvocation, privateKeySecured)) {
                Boolean bl2 = Boolean.FALSE;
                return bl2;
            }
            Object object = methodInvocation.proceed();
            Object object2 = object = this.a(methodInvocation, privateKeySecured, object);
            return object2;
        }
        finally {
            this.b.clear();
        }
    }

    private Object a(MethodInvocation methodInvocation, PrivateKeySecured privateKeySecured, Object ssgKeyEntry) throws FindException, KeyStoreException {
        block10: {
            boolean bl2;
            Class<?> clazz;
            block12: {
                boolean bl3;
                block11: {
                    clazz = methodInvocation.getMethod().getReturnType();
                    try {
                        try {
                            try {
                                if (PrivateKeyRbacInterceptor.a(clazz) || PrivateKeySecured.ReturnCheck.NO_RETURN_CHECK == privateKeySecured.returnCheck()) break block10;
                            }
                            catch (FindException findException) {
                                throw PrivateKeyRbacInterceptor.a(findException);
                            }
                            if (PrivateKeySecured.ReturnCheck.CHECK_RETURN != privateKeySecured.returnCheck()) break block11;
                        }
                        catch (FindException findException) {
                            throw PrivateKeyRbacInterceptor.a(findException);
                        }
                        bl3 = true;
                        break block12;
                    }
                    catch (FindException findException) {
                        throw PrivateKeyRbacInterceptor.a(findException);
                    }
                }
                bl3 = bl2 = false;
            }
            if (PrivateKeyRbacInterceptor.a(SsgKeyEntry.class, clazz, ssgKeyEntry)) {
                ssgKeyEntry = this.a((Collection)ssgKeyEntry, bl2);
            } else if (SsgKeyEntry.class.isAssignableFrom(clazz)) {
                ssgKeyEntry = this.a(ssgKeyEntry, bl2);
            } else {
                String[] stringArray = c;
                throw new IllegalStateException(stringArray[9] + methodInvocation.getMethod().getName() + stringArray[17] + clazz.getSimpleName());
            }
        }
        return ssgKeyEntry;
    }

    /*
     * Exception decompiling
     */
    private boolean a(MethodInvocation var1_1, PrivateKeySecured var2_2) throws FindException, KeyStoreException {
        /*
         * 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 [2[TRYBLOCK]], but top level block is 5[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:1055)
         *     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 SsgKeyEntry a(MethodInvocation methodInvocation) {
        block4: {
            Object[] objectArray = methodInvocation.getArguments();
            try {
                try {
                    if (objectArray.length <= 0 || !(objectArray[0] instanceof SsgKeyEntry)) break block4;
                }
                catch (IllegalStateException illegalStateException) {
                    throw PrivateKeyRbacInterceptor.a(illegalStateException);
                }
                return (SsgKeyEntry)objectArray[0];
            }
            catch (IllegalStateException illegalStateException) {
                throw PrivateKeyRbacInterceptor.a(illegalStateException);
            }
        }
        throw new IllegalArgumentException(c[13]);
    }

    @Nullable
    private SsgKeyEntry b(MethodInvocation methodInvocation, PrivateKeySecured privateKeySecured) {
        SsgKeyEntry ssgKeyEntry;
        block4: {
            ssgKeyEntry = null;
            if (privateKeySecured.keyEntryArg() != -1) {
                block3: {
                    Object[] objectArray = methodInvocation.getArguments();
                    try {
                        if (objectArray.length <= privateKeySecured.keyEntryArg() || !(objectArray[privateKeySecured.keyEntryArg()] instanceof SsgKeyEntry)) break block3;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw PrivateKeyRbacInterceptor.a(illegalStateException);
                    }
                    ssgKeyEntry = (SsgKeyEntry)objectArray[privateKeySecured.keyEntryArg()];
                    break block4;
                }
                throw new IllegalArgumentException(c[32] + privateKeySecured.keyEntryArg());
            }
        }
        return ssgKeyEntry;
    }

    private static String c(MethodInvocation methodInvocation, PrivateKeySecured privateKeySecured) {
        return (String)methodInvocation.getArguments()[privateKeySecured.keyAliasArg()];
    }

    private static Goid d(MethodInvocation methodInvocation, PrivateKeySecured privateKeySecured) {
        return (Goid)methodInvocation.getArguments()[privateKeySecured.keystoreGoidArg()];
    }

    private static SsgKeyMetadata e(MethodInvocation methodInvocation, PrivateKeySecured privateKeySecured) {
        SsgKeyMetadata ssgKeyMetadata;
        try {
            ssgKeyMetadata = privateKeySecured.metadataArg() == -1 ? null : (SsgKeyMetadata)methodInvocation.getArguments()[privateKeySecured.metadataArg()];
        }
        catch (IllegalStateException illegalStateException) {
            throw PrivateKeyRbacInterceptor.a(illegalStateException);
        }
        return ssgKeyMetadata;
    }

    private void a(SsgKeyEntry ssgKeyEntry, OperationType operationType) throws FindException, KeyStoreException {
        OperationType operationType2;
        SsgKeyEntry ssgKeyEntry2;
        if (operationType == OperationType.UPDATE) {
            ssgKeyEntry2 = this.a(ssgKeyEntry.getKeystoreId(), ssgKeyEntry.getAlias());
            this.b((Entity)ssgKeyEntry2, OperationType.UPDATE);
            this.b((Entity)ssgKeyEntry, OperationType.UPDATE);
        } else {
            this.b((Entity)ssgKeyEntry, operationType);
        }
        try {
            operationType2 = OperationType.READ == operationType ? OperationType.READ : OperationType.UPDATE;
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
        ssgKeyEntry2 = operationType2;
        this.b(ssgKeyEntry.getKeystoreId(), (OperationType)ssgKeyEntry2);
    }

    private void a(Goid goid, String string, SsgKeyMetadata ssgKeyMetadata, OperationType operationType) throws FindException, KeyStoreException {
        SsgKeyEntry ssgKeyEntry;
        block3: {
            block2: {
                try {
                    if (operationType != OperationType.CREATE && operationType != OperationType.UPDATE) break block2;
                }
                catch (FindException findException) {
                    throw PrivateKeyRbacInterceptor.a(findException);
                }
                ssgKeyEntry = this.a(goid, string, ssgKeyMetadata);
                break block3;
            }
            ssgKeyEntry = this.a(goid, string);
        }
        this.a(ssgKeyEntry, operationType);
    }

    private boolean a(PrivateKeySecured privateKeySecured) throws FindException {
        block4: {
            block5: {
                try {
                    try {
                        if (this.rbacServices.isPermittedForAnyEntityOfType(this.a, OperationType.UPDATE, EntityType.SSG_KEYSTORE)) break block4;
                        if (!privateKeySecured.allowNonFatalPreChecks()) break block5;
                    }
                    catch (FindException findException) {
                        throw PrivateKeyRbacInterceptor.a(findException);
                    }
                    return false;
                }
                catch (FindException findException) {
                    throw PrivateKeyRbacInterceptor.a(findException);
                }
            }
            throw new PermissionDeniedException(OperationType.UPDATE, EntityType.SSG_KEYSTORE, c[10]);
        }
        return true;
    }

    private void a() throws FindException {
        try {
            if (!this.rbacServices.isPermittedForAnyEntityOfType(this.a, OperationType.DELETE, EntityType.SSG_KEY_ENTRY)) {
                throw new PermissionDeniedException(OperationType.DELETE, EntityType.SSG_KEY_ENTRY, c[3]);
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
    }

    private void b(SsgKeyEntry ssgKeyEntry, OperationType operationType) throws FindException, KeyStoreException {
        if (operationType != OperationType.UPDATE) {
            String[] stringArray = c;
            throw new IllegalArgumentException(stringArray[23] + String.valueOf(operationType) + stringArray[0]);
        }
        this.b((Entity)ssgKeyEntry, OperationType.UPDATE);
        this.b(ssgKeyEntry.getKeystoreId(), OperationType.UPDATE);
        SsgKeyEntry ssgKeyEntry2 = this.a(ssgKeyEntry.getKeystoreId(), ssgKeyEntry.getAlias());
        this.b((Entity)ssgKeyEntry2, OperationType.UPDATE);
    }

    private static boolean a(@NotNull Class<?> clazz) {
        boolean bl2;
        block13: {
            block12: {
                try {
                    if (clazz == null) {
                        PrivateKeyRbacInterceptor.a(1);
                    }
                }
                catch (IllegalStateException illegalStateException) {
                    throw PrivateKeyRbacInterceptor.a(illegalStateException);
                }
                try {
                    block11: {
                        try {
                            try {
                                try {
                                    if (clazz.isPrimitive() || Void.TYPE == clazz) break block11;
                                }
                                catch (IllegalStateException illegalStateException) {
                                    throw PrivateKeyRbacInterceptor.a(illegalStateException);
                                }
                                if (!clazz.isArray()) break block12;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw PrivateKeyRbacInterceptor.a(illegalStateException);
                            }
                            if (!clazz.getComponentType().isPrimitive()) break block12;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw PrivateKeyRbacInterceptor.a(illegalStateException);
                        }
                    }
                    bl2 = true;
                    break block13;
                }
                catch (IllegalStateException illegalStateException) {
                    throw PrivateKeyRbacInterceptor.a(illegalStateException);
                }
            }
            bl2 = false;
        }
        return bl2;
    }

    private static boolean a(@NotNull Class clazz, @NotNull Class clazz2, @Nullable Object object) {
        boolean bl2;
        block14: {
            try {
                if (clazz == null) {
                    PrivateKeyRbacInterceptor.a(2);
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw PrivateKeyRbacInterceptor.a(illegalStateException);
            }
            try {
                if (clazz2 == null) {
                    PrivateKeyRbacInterceptor.a(3);
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw PrivateKeyRbacInterceptor.a(illegalStateException);
            }
            bl2 = false;
            try {
                try {
                    if (object == null || !List.class.isAssignableFrom(clazz2)) break block14;
                }
                catch (IllegalStateException illegalStateException) {
                    throw PrivateKeyRbacInterceptor.a(illegalStateException);
                }
                if (!List.class.isInstance(object)) break block14;
            }
            catch (IllegalStateException illegalStateException) {
                throw PrivateKeyRbacInterceptor.a(illegalStateException);
            }
            List list = (List)object;
            boolean bl3 = false;
            for (Object e10 : list) {
                if (clazz.isInstance(e10)) continue;
                bl3 = true;
                break;
            }
            try {
                if (!bl3) {
                    return true;
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw PrivateKeyRbacInterceptor.a(illegalStateException);
            }
        }
        return bl2;
    }

    @Override
    public void setUser(@NotNull User user) {
        try {
            if (user == null) {
                PrivateKeyRbacInterceptor.a(4);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw PrivateKeyRbacInterceptor.a(illegalStateException);
        }
        this.a = user;
    }

    @NotNull
    public SsgKeyFinder findKeystore(Goid goid) throws FindException, KeyStoreException {
        SsgKeyFinder ssgKeyFinder;
        SsgKeyFinder ssgKeyFinder2;
        block13: {
            SsgKeyFinder ssgKeyFinder3;
            block14: {
                try {
                    if (Goid.isDefault((Goid)goid)) {
                        throw new IllegalArgumentException(c[22]);
                    }
                }
                catch (FindException findException) {
                    throw PrivateKeyRbacInterceptor.a(findException);
                }
                ssgKeyFinder2 = this.b.get(goid);
                try {
                    try {
                        if (ssgKeyFinder2 == null) break block13;
                        ssgKeyFinder3 = ssgKeyFinder2;
                        if (ssgKeyFinder3 != null) break block14;
                    }
                    catch (FindException findException) {
                        throw PrivateKeyRbacInterceptor.a(findException);
                    }
                    PrivateKeyRbacInterceptor.a(5);
                }
                catch (FindException findException) {
                    throw PrivateKeyRbacInterceptor.a(findException);
                }
            }
            return ssgKeyFinder3;
        }
        ssgKeyFinder2 = this.ssgKeyStoreManager.findByPrimaryKey(goid);
        try {
            if (ssgKeyFinder2 == null) {
                throw new ObjectNotFoundException(c[26] + String.valueOf(goid));
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
        try {
            this.b.put(goid, ssgKeyFinder2);
            ssgKeyFinder = ssgKeyFinder2;
            if (ssgKeyFinder == null) {
                PrivateKeyRbacInterceptor.a(6);
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
        return ssgKeyFinder;
    }

    @NotNull
    private SsgKeyEntry a(Goid goid, String string, SsgKeyMetadata ssgKeyMetadata) {
        SsgKeyEntry ssgKeyEntry;
        SsgKeyEntry ssgKeyEntry2 = SsgKeyEntry.createDummyEntityForAuditing((Goid)goid, (String)string);
        try {
            ssgKeyEntry2.attachMetadata(ssgKeyMetadata);
            ssgKeyEntry = ssgKeyEntry2;
            if (ssgKeyEntry == null) {
                PrivateKeyRbacInterceptor.a(7);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw PrivateKeyRbacInterceptor.a(illegalStateException);
        }
        return ssgKeyEntry;
    }

    @NotNull
    SsgKeyEntry a(@NotNull SsgKeyFinder ssgKeyFinder, @NotNull String string) throws ObjectNotFoundException, KeyStoreException {
        SsgKeyEntry ssgKeyEntry;
        try {
            if (ssgKeyFinder == null) {
                PrivateKeyRbacInterceptor.a(8);
            }
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            throw PrivateKeyRbacInterceptor.a(objectNotFoundException);
        }
        try {
            if (string == null) {
                PrivateKeyRbacInterceptor.a(9);
            }
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            throw PrivateKeyRbacInterceptor.a(objectNotFoundException);
        }
        try {
            ssgKeyEntry = ssgKeyFinder.getCertificateChain(string);
            if (ssgKeyEntry == null) {
                PrivateKeyRbacInterceptor.a(10);
            }
        }
        catch (ObjectNotFoundException objectNotFoundException) {
            throw PrivateKeyRbacInterceptor.a(objectNotFoundException);
        }
        return ssgKeyEntry;
    }

    @NotNull
    SsgKeyEntry a(Goid goid, @NotNull String string) throws FindException, KeyStoreException {
        SsgKeyEntry ssgKeyEntry;
        try {
            if (string == null) {
                PrivateKeyRbacInterceptor.a(11);
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
        try {
            ssgKeyEntry = this.a(this.findKeystore(goid), string);
            if (ssgKeyEntry == null) {
                PrivateKeyRbacInterceptor.a(12);
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
        return ssgKeyEntry;
    }

    @Nullable
    private Collection<SsgKeyEntry> a(@Nullable Collection<?> collection, boolean bl2) throws FindException, KeyStoreException {
        try {
            if (collection == null) {
                return null;
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
        ArrayList<SsgKeyEntry> arrayList = new ArrayList<SsgKeyEntry>();
        for (Object obj : collection) {
            if (!(obj instanceof SsgKeyEntry)) continue;
            SsgKeyEntry ssgKeyEntry = (SsgKeyEntry)obj;
            SsgKeyEntry ssgKeyEntry2 = this.b(ssgKeyEntry, bl2);
            try {
                if (ssgKeyEntry2 == null) continue;
                arrayList.add(ssgKeyEntry2);
            }
            catch (FindException findException) {
                throw PrivateKeyRbacInterceptor.a(findException);
            }
        }
        return arrayList;
    }

    @Nullable
    private SsgKeyEntry a(SsgKeyEntry ssgKeyEntry, boolean bl2) throws FindException, KeyStoreException {
        return this.b(ssgKeyEntry, bl2);
    }

    @Nullable
    private SsgKeyEntry b(SsgKeyEntry ssgKeyEntry, boolean bl2) throws FindException, KeyStoreException {
        block15: {
            if (ssgKeyEntry != null) {
                boolean bl3;
                boolean bl4;
                block14: {
                    block13: {
                        bl4 = this.rbacServices.isPermittedForEntity(this.a, (Entity)ssgKeyEntry, OperationType.READ, null);
                        try {
                            try {
                                if (bl4 || !bl2) break block13;
                            }
                            catch (FindException findException) {
                                throw PrivateKeyRbacInterceptor.a(findException);
                            }
                            throw new PermissionDeniedException(OperationType.READ, EntityType.SSG_KEY_ENTRY);
                        }
                        catch (FindException findException) {
                            throw PrivateKeyRbacInterceptor.a(findException);
                        }
                    }
                    bl3 = this.a(ssgKeyEntry.getKeystoreId(), OperationType.READ);
                    try {
                        try {
                            if (bl3 || !bl2) break block14;
                        }
                        catch (FindException findException) {
                            throw PrivateKeyRbacInterceptor.a(findException);
                        }
                        throw new PermissionDeniedException(OperationType.READ, EntityType.SSG_KEYSTORE);
                    }
                    catch (FindException findException) {
                        throw PrivateKeyRbacInterceptor.a(findException);
                    }
                }
                try {
                    try {
                        if (!bl4 || !bl3) break block15;
                    }
                    catch (FindException findException) {
                        throw PrivateKeyRbacInterceptor.a(findException);
                    }
                    return ssgKeyEntry;
                }
                catch (FindException findException) {
                    throw PrivateKeyRbacInterceptor.a(findException);
                }
            }
        }
        return null;
    }

    private boolean a(Goid goid, OperationType operationType) throws FindException, KeyStoreException {
        try {
            if (Goid.isDefault((Goid)goid)) {
                return this.rbacServices.isPermittedForAnyEntityOfType(this.a, operationType, EntityType.SSG_KEYSTORE);
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
        SsgKeyFinder ssgKeyFinder = this.findKeystore(goid);
        return this.rbacServices.isPermittedForEntity(this.a, (Entity)ssgKeyFinder, operationType, null);
    }

    private boolean a(Entity entity, OperationType operationType) throws FindException {
        return this.rbacServices.isPermittedForEntity(this.a, entity, operationType, null);
    }

    private void b(Entity entity, OperationType operationType) throws FindException {
        try {
            if (!this.a(entity, operationType)) {
                PrivateKeyRbacInterceptor.a(operationType, entity, null);
            }
        }
        catch (FindException findException) {
            throw PrivateKeyRbacInterceptor.a(findException);
        }
    }

    private static void a(OperationType operationType, Entity entity, @Nullable String string) {
        try {
            if (entity instanceof SsgKeyFinder) {
                throw new PermissionDeniedException(operationType, EntityType.SSG_KEYSTORE, string);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw PrivateKeyRbacInterceptor.a(illegalStateException);
        }
        throw new PermissionDeniedException(operationType, entity, string);
    }

    private void b(Goid goid, OperationType operationType) throws FindException, KeyStoreException {
        block7: {
            if (!Goid.isDefault((Goid)goid)) {
                SsgKeyFinder ssgKeyFinder = this.findKeystore(goid);
                try {
                    if (!this.rbacServices.isPermittedForEntity(this.a, (Entity)ssgKeyFinder, operationType, null)) {
                        throw new PermissionDeniedException(operationType, EntityType.SSG_KEYSTORE);
                    }
                    break block7;
                }
                catch (FindException findException) {
                    throw PrivateKeyRbacInterceptor.a(findException);
                }
            }
            try {
                if (!this.rbacServices.isPermittedForAnyEntityOfType(this.a, operationType, EntityType.SSG_KEYSTORE)) {
                    throw new PermissionDeniedException(operationType, EntityType.SSG_KEYSTORE);
                }
            }
            catch (FindException findException) {
                throw PrivateKeyRbacInterceptor.a(findException);
            }
        }
    }

    /*
     * 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 Throwable a(Throwable throwable) {
        return throwable;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[34];
                var3_1 = 0;
                var2_2 = "\u0019O\u000ejH]]\u0019U\b:V][MC\u00191ZI\u0010eJ\u0005]\\E\u0015eUW[OC\u000feGVDPHR\u001aT[_XR\u0018\u0001CK{[G\u001e\u0003HFLKE\u0018:R][Hyu\u0018)S@L]\u0006\u0010/RZF]\u0006\b9O\\N\u0019v\u000f#PS]\\m\u00183tPHZo\u0013>C@J\\V\t%T\u0012EXE\u00169\u0006ryKO\u000b+RWb\\_./EG[\\B\u001f\\^\r%TF\tIT\u0014<GFL\u0019M\u00183\u0006iM\\J\u0018>C\u0012HUJ \u001aIM\u000f#\u000bABJK]+SFFNO\u000f/\u0006THPJ\b8C\u000eTG\u0004(C~@JR>&GAZ\f_O\u0013.mWP|H\t8_\u0006_O\u0013.C@\f\\J\u0018'C\\]zJ\u001c9U(lH\u001c(JW\tMI],O^]\\T]8CF\\KH]>_BL\u0019@\u00128\u0006_LMN\u0012.\u0006'XU\u000e#A\\\tJV\u0018)OSE\u0019M\u00183\u0006B\\KV\u00129C\u0012rLV\u0019+RW\tXJ\u0011\u0017\u0018IM\u000f#\u000b@Z\u0019G\b>IE@KC],G[ELT\u0018\u0007JC\t\u001fUW[,\u007fO\u000f9R\u0012D\\R\u0015%B\u0012HKA\b'C\\]\u0019K\b9R\u0012K\\\u0006\u001c$\u0006aZ^m\u00183c\\]K_\u0012ZT\u0018+RWoXM\u0018\u0001CKlWR\u000f32zS\u000f8C\\]\u0019S\u000e/T\u0012GVR]9CF\t_I\u000fjv@@OG\t/mWPkD\u001c)o\\]\\T\u001e/VFFKFxR]&CSZM\u0006\u0012$C\u0012yKC>\"CQB\u0019K\b9R\u0012K\\\u0006\u0019/E^HKC\u0019j\u000eQHW\u0006\b9C\u0012gvy-\u0018cmjqc>\u0001\u0006SZ\u0019H\u0012gIB\u0000\u0002\u0003\u0006\u0006PH\u000b%MW\bPU1#UFf_\f_O\u0013.mWP|H\t8_1ZI\u0010eJ\u0005]\\E\u0015eUW[OC\u000feGVDPHR\u001aT[_XR\u0018\u0001CK{[G\u001e\u0003HFLKE\u0018:R][\u001bOG\u0011#B\u0012B\\_\u000e>I@L~I\u0014.\u0006@LHS\u00148CV\tvV\u00188GF@VH\f_O\u0013.mWPJR\u00128C\u0004LU\u00188\u001bwI]!CKZMI\u000f/\u0006TFLH\u0019j@][\u0019A\u0012#B\u0012\u0017lH\u000f/E]NWO\u0007/B\u0012yKC>\"CQB\u0003\u0006\nPH\u000b%ES]PI\u0013\u0018PU($@[EMC\u000f+D^LkC\t?T\\}@V\u0018*yh\u0012>hGEU\u0006\u0010/RZF]\u0006X9\b\u0017Z\u0019K\b9R\u0012GVR]8CF\\KH]$S^E\bRC\u0004\u000bJ[HJ";
                var4_3 = "\u0019O\u000ejH]]\u0019U\b:V][MC\u00191ZI\u0010eJ\u0005]\\E\u0015eUW[OC\u000feGVDPHR\u001aT[_XR\u0018\u0001CK{[G\u001e\u0003HFLKE\u0018:R][Hyu\u0018)S@L]\u0006\u0010/RZF]\u0006\b9O\\N\u0019v\u000f#PS]\\m\u00183tPHZo\u0013>C@J\\V\t%T\u0012EXE\u00169\u0006ryKO\u000b+RWb\\_./EG[\\B\u001f\\^\r%TF\tIT\u0014<GFL\u0019M\u00183\u0006iM\\J\u0018>C\u0012HUJ \u001aIM\u000f#\u000bABJK]+SFFNO\u000f/\u0006THPJ\b8C\u000eTG\u0004(C~@JR>&GAZ\f_O\u0013.mWP|H\t8_\u0006_O\u0013.C@\f\\J\u0018'C\\]zJ\u001c9U(lH\u001c(JW\tMI],O^]\\T]8CF\\KH]>_BL\u0019@\u00128\u0006_LMN\u0012.\u0006'XU\u000e#A\\\tJV\u0018)OSE\u0019M\u00183\u0006B\\KV\u00129C\u0012rLV\u0019+RW\tXJ\u0011\u0017\u0018IM\u000f#\u000b@Z\u0019G\b>IE@KC],G[ELT\u0018\u0007JC\t\u001fUW[,\u007fO\u000f9R\u0012D\\R\u0015%B\u0012HKA\b'C\\]\u0019K\b9R\u0012K\\\u0006\u001c$\u0006aZ^m\u00183c\\]K_\u0012ZT\u0018+RWoXM\u0018\u0001CKlWR\u000f32zS\u000f8C\\]\u0019S\u000e/T\u0012GVR]9CF\t_I\u000fjv@@OG\t/mWPkD\u001c)o\\]\\T\u001e/VFFKFxR]&CSZM\u0006\u0012$C\u0012yKC>\"CQB\u0019K\b9R\u0012K\\\u0006\u0019/E^HKC\u0019j\u000eQHW\u0006\b9C\u0012gvy-\u0018cmjqc>\u0001\u0006SZ\u0019H\u0012gIB\u0000\u0002\u0003\u0006\u0006PH\u000b%MW\bPU1#UFf_\f_O\u0013.mWP|H\t8_1ZI\u0010eJ\u0005]\\E\u0015eUW[OC\u000feGVDPHR\u001aT[_XR\u0018\u0001CK{[G\u001e\u0003HFLKE\u0018:R][\u001bOG\u0011#B\u0012B\\_\u000e>I@L~I\u0014.\u0006@LHS\u00148CV\tvV\u00188GF@VH\f_O\u0013.mWPJR\u00128C\u0004LU\u00188\u001bwI]!CKZMI\u000f/\u0006TFLH\u0019j@][\u0019A\u0012#B\u0012\u0017lH\u000f/E]NWO\u0007/B\u0012yKC>\"CQB\u0003\u0006\nPH\u000b%ES]PI\u0013\u0018PU($@[EMC\u000f+D^LkC\t?T\\}@V\u0018*yh\u0012>hGEU\u0006\u0010/RZF]\u0006X9\b\u0017Z\u0019K\b9R\u0012GVR]8CF\\KH]$S^E\bRC\u0004\u000bJ[HJ".length();
                var1_4 = 17;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = PrivateKeyRbacInterceptor.a(v0, PrivateKeyRbacInterceptor.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "Sq\"\u0000jicr)\u0001\u0016nVcoL<\u0011{d&w{5\u0010dxhb)%\f}u&\u007fg6\u0000q=>W{5\u0010dxhb)4\n{=FXf&+|qj6y3\u0017hpcbl E.8u1)=\u0003)8u8,!Edhub)<\n}=ds)<\u0010eq";
                    var4_3 = "Sq\"\u0000jicr)\u0001\u0016nVcoL<\u0011{d&w{5\u0010dxhb)%\f}u&\u007fg6\u0000q=>W{5\u0010dxhb)4\n{=FXf&+|qj6y3\u0017hpcbl E.8u1)=\u0003)8u8,!Edhub)<\n}=ds)<\u0010eq".length();
                    var1_4 = 41;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 26;
                        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++] = PrivateKeyRbacInterceptor.a(v0, PrivateKeyRbacInterceptor.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;
            }
        }
        PrivateKeyRbacInterceptor.c = var5;
    }

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

