/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.rbac.EntityFolderAncestryPredicate
 *  com.l7tech.gateway.common.security.rbac.ScopeEvaluator
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.EntityTypeRegistry
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.folder.Folder
 *  com.l7tech.objectmodel.folder.HasFolder
 */
package com.l7tech.server.security.rbac;

import com.l7tech.gateway.common.security.rbac.EntityFolderAncestryPredicate;
import com.l7tech.gateway.common.security.rbac.ScopeEvaluator;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.EntityTypeRegistry;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.folder.Folder;
import com.l7tech.objectmodel.folder.HasFolder;
import com.l7tech.server.security.rbac.RbacServicesImpl;
import java.io.Serializable;
import java.util.logging.Level;

class b
implements ScopeEvaluator {
    private final EntityFolderAncestryPredicate a;
    final RbacServicesImpl this$0;
    private static final String[] b;

    public b(RbacServicesImpl rbacServicesImpl, EntityFolderAncestryPredicate entityFolderAncestryPredicate) {
        this.this$0 = rbacServicesImpl;
        this.a = entityFolderAncestryPredicate;
    }

    public boolean matches(Entity entity) {
        Object ET;
        try {
            if (!(entity instanceof Folder)) {
                return false;
            }
        }
        catch (FindException findException) {
            throw com.l7tech.server.security.rbac.b.a(findException);
        }
        EntityType entityType = this.a.getEntityType();
        String string = this.a.getEntityId();
        try {
            ET = this.this$0.e.find(EntityTypeRegistry.getEntityClass((EntityType)entityType), (Serializable)((Object)string));
        }
        catch (FindException findException) {
            String[] stringArray = b;
            RbacServicesImpl.a.log(Level.WARNING, String.format(stringArray[2], entityType, string), findException);
            return false;
        }
        try {
            if (ET == null) {
                RbacServicesImpl.a.log(Level.INFO, String.format(b[0], entityType, string));
                return false;
            }
        }
        catch (FindException findException) {
            throw com.l7tech.server.security.rbac.b.a(findException);
        }
        try {
            if (!(ET instanceof HasFolder)) {
                RbacServicesImpl.a.log(Level.INFO, String.format(b[1], entityType, string));
                return false;
            }
        }
        catch (FindException findException) {
            throw com.l7tech.server.security.rbac.b.a(findException);
        }
        Folder folder = (Folder)entity;
        Folder folder2 = ((HasFolder)ET).getFolder();
        while (true) {
            block16: {
                try {
                    try {
                        if (folder2 == null) break;
                        if (!Goid.equals((Goid)folder.getGoid(), (Goid)folder2.getGoid())) break block16;
                    }
                    catch (FindException findException) {
                        throw com.l7tech.server.security.rbac.b.a(findException);
                    }
                    return true;
                }
                catch (FindException findException) {
                    throw com.l7tech.server.security.rbac.b.a(findException);
                }
            }
            folder2 = folder2.getFolder();
        }
        return false;
    }

    private static FindException a(FindException findException) {
        return findException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "o\u00118\u0010q\nJ\u001e\u0003jT1\rJU\u001fj\u001b{\u0010\r^\u0002j\u0012l\u0017\u0019O\u0003\u001bo\u00118\u0010q\nJ\u001e\u0003jT1\rJS\u00119Wz\u0011J]\u001f&\u0013q\f\u001cn\u001e+\u0015x\u001bJO\u001fj\u0011}\u0010\u000e\u001b\u0004+\u0005s\u001b\u001e\u001bU9W7[\u0019";
        int n3 = "o\u00118\u0010q\nJ\u001e\u0003jT1\rJU\u001fj\u001b{\u0010\r^\u0002j\u0012l\u0017\u0019O\u0003\u001bo\u00118\u0010q\nJ\u001e\u0003jT1\rJS\u00119Wz\u0011J]\u001f&\u0013q\f\u001cn\u001e+\u0015x\u001bJO\u001fj\u0011}\u0010\u000e\u001b\u0004+\u0005s\u001b\u001e\u001bU9W7[\u0019".length();
        int n4 = 30;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = com.l7tech.server.security.rbac.b.a(116, com.l7tech.server.security.rbac.b.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                b = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

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

