/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.rbac.OperationType
 *  com.l7tech.gateway.common.security.rbac.Role
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityHeader
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.objectmodel.SaveException
 *  com.l7tech.objectmodel.SecurityZone
 *  com.l7tech.objectmodel.UpdateException
 *  com.l7tech.objectmodel.folder.Folder
 *  com.l7tech.objectmodel.imp.NamedEntityImp
 *  com.l7tech.util.Config
 *  com.l7tech.util.TextUtils
 *  jakarta.inject.Inject
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.security.rbac;

import com.l7tech.gateway.common.security.rbac.OperationType;
import com.l7tech.gateway.common.security.rbac.Role;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityHeader;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.objectmodel.SaveException;
import com.l7tech.objectmodel.SecurityZone;
import com.l7tech.objectmodel.UpdateException;
import com.l7tech.objectmodel.folder.Folder;
import com.l7tech.objectmodel.imp.NamedEntityImp;
import com.l7tech.server.HibernateEntityManager;
import com.l7tech.server.folder.FolderManager;
import com.l7tech.server.security.rbac.RoleManager;
import com.l7tech.server.security.rbac.SecurityZoneManager;
import com.l7tech.util.Config;
import com.l7tech.util.TextUtils;
import jakarta.inject.Inject;
import java.text.MessageFormat;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.jetbrains.annotations.NotNull;

/*
 * Exception performing whole class analysis ignored.
 */
public class SecurityZoneManagerImpl
extends HibernateEntityManager<SecurityZone, EntityHeader>
implements SecurityZoneManager {
    static final String m;
    static final String n;
    static final String o;
    static final String p;
    static final Pattern q;
    static final int r = 50;
    private static final Logger s;
    private static final String t;
    private static final String u;
    @Inject
    private RoleManager roleManager;
    @Inject
    private FolderManager folderManager;
    @Inject
    private Config config;
    private static final String[] v;

    public Class<? extends Entity> getImpClass() {
        return SecurityZone.class;
    }

    public void createRoles(SecurityZone securityZone) throws SaveException {
        Folder folder = this.a();
        try {
            if (this.config.getBooleanProperty(v[4], true)) {
                this.a(securityZone, folder);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
        try {
            if (this.config.getBooleanProperty(v[5], true)) {
                this.b(securityZone, folder);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
    }

    @Override
    public void addManageSecurityZoneRole(@NotNull SecurityZone securityZone) throws SaveException {
        try {
            if (securityZone == null) {
                SecurityZoneManagerImpl.b(0);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
        this.b(securityZone, this.a());
    }

    @Override
    public void addReadSecurityZoneRole(@NotNull SecurityZone securityZone) throws SaveException {
        try {
            if (securityZone == null) {
                SecurityZoneManagerImpl.b(1);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
        this.a(securityZone, this.a());
    }

    public void updateRoles(@NotNull SecurityZone securityZone) throws UpdateException {
        try {
            if (securityZone == null) {
                SecurityZoneManagerImpl.b(2);
            }
        }
        catch (FindException findException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)findException));
        }
        try {
            this.roleManager.renameEntitySpecificRoles(EntityType.SECURITY_ZONE, (NamedEntityImp)securityZone, q);
        }
        catch (FindException findException) {
            throw new UpdateException(v[15], (Throwable)findException);
        }
    }

    private Folder a() throws SaveException {
        Folder folder;
        try {
            folder = this.folderManager.findRootFolder();
        }
        catch (FindException findException) {
            throw new SaveException(v[26], (Throwable)findException);
        }
        return folder;
    }

    private Role a(@NotNull String string, @NotNull String string2, Goid goid) {
        try {
            if (string == null) {
                SecurityZoneManagerImpl.b(3);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw SecurityZoneManagerImpl.a(illegalArgumentException);
        }
        try {
            if (string2 == null) {
                SecurityZoneManagerImpl.b(4);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw SecurityZoneManagerImpl.a(illegalArgumentException);
        }
        s.info(v[0] + string);
        Role role = new Role();
        role.setName(string);
        role.setDescription(string2);
        role.setEntityType(EntityType.SECURITY_ZONE);
        role.setEntityGoid(goid);
        return role;
    }

    private void a(@NotNull SecurityZone securityZone, @NotNull Folder folder) throws SaveException {
        try {
            if (securityZone == null) {
                SecurityZoneManagerImpl.b(5);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
        try {
            if (folder == null) {
                SecurityZoneManagerImpl.b(6);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
        String[] stringArray = v;
        String string = MessageFormat.format(stringArray[16], TextUtils.truncStringMiddle((String)securityZone.getName(), (int)50), securityZone.getGoid().toHexString());
        Role role = this.a(string, stringArray[2], securityZone.getGoid());
        this.a(securityZone, role, folder);
        this.roleManager.save((PersistentEntity)role);
    }

    private void b(@NotNull SecurityZone securityZone, @NotNull Folder folder) throws SaveException {
        try {
            if (securityZone == null) {
                SecurityZoneManagerImpl.b(7);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
        try {
            if (folder == null) {
                SecurityZoneManagerImpl.b(8);
            }
        }
        catch (SaveException saveException) {
            throw SecurityZoneManagerImpl.a((Exception)((Object)saveException));
        }
        String[] stringArray = v;
        String string = MessageFormat.format(stringArray[8], TextUtils.truncStringMiddle((String)securityZone.getName(), (int)50), securityZone.getGoid().toHexString());
        Role role = this.a(string, stringArray[25], securityZone.getGoid());
        this.a(securityZone, role, folder);
        role.addSecurityZonePermission(OperationType.CREATE, EntityType.ANY, securityZone);
        role.addSecurityZonePermission(OperationType.UPDATE, EntityType.ANY, securityZone);
        role.addSecurityZonePermission(OperationType.DELETE, EntityType.ANY, securityZone);
        this.roleManager.save((PersistentEntity)role);
    }

    private void a(SecurityZone securityZone, Role role, Folder folder) throws SaveException {
        role.addEntityPermission(OperationType.READ, EntityType.FOLDER, folder.getId());
        role.addEntityPermission(OperationType.READ, EntityType.SECURITY_ZONE, securityZone.getId());
        role.addSecurityZonePermission(OperationType.READ, EntityType.ANY, securityZone);
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[27];
                var3_1 = 0;
                var2_2 = "`u\u000b\u0015%#ED'\u0000\u0011&jyLk\u000bNq>bu\t\u0001</EW'\b\u001b#jkmh\u001a:$&G\u0003w\u000f\u00060'NWb\u001cTvoX\u0004'\u0001\u0012qoX\r\"\u001dT<?XW'\u0000\u001b%jIF'\u0000\u0001=&^vt\u000b\u0006\"jJPt\u0007\u0013?/O\u0003s\u0001T%\"N\u0003|^\tq8DObN\u001c0<N\u0003s\u0006\u0011q+IJk\u0007\u0000(j_L'\u001c\u00110.\u000bFi\u001a\u001d%#NP'\u0019\u001d%\"BM'\u001a\u001c4jP\u0012zN\u00074)^Qn\u001a\rq0DMb@\u000bVw\n\u0015%/yLk\u000b\u0007!Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Un\u000b\u0003\u000b%EF)\u000f\u0001%%hQb\u000f\u00004#Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Nf\u0000\u00156/qLi\u000bZ0?_LD\u001c\u00110>N\u0004yh\u0000\u0011\nQh\u0001\u0000\u0017%GGb\u001c\u0016nf\u0000\u00156/\u000bX7\u0013T\u000b%EF'FW*{V\n\u0004Yh\u0000\u0011\u0017Bc\n&4+Opb\r\u0001##_Z]\u0001\u001a4\u0018DOb\u0014un\u000b\u0003q1\u001b^'4\u001b?/\u000b\u000b$\u0015E,c!Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Un\u000b\u0003\u000b%EF)\u000f\u0001%%hQb\u000f\u00004^vt\u000b\u0006\"jJPt\u0007\u0013?/O\u0003s\u0001T%\"N\u0003|^\tq8DObN\u001c0<N\u0003s\u0006\u0011q+IJk\u0007\u0000(j_L'\u001c\u00110.\u000bFi\u001a\u001d%#NP'\u0019\u001d%\"BM'\u001a\u001c4jP\u0012zN\u00074)^Qn\u001a\rq0DMb@\u0019Bc\n90$JDb=\u00112?YJs\u0017.>$Nqh\u0002\u0011\u001e`h\u001b\u00185jELsN\u00128$O\u0003u\u0001\u001849\u000bWhN\u0001!.JWb\u0014un\u000b\u0003q1\u001b^'4\u001b?/\u000b\u000b$\u0015E,c\u0004Mf\u0003\u0011yvt\u000b\u0006\"jJPt\u0007\u0013?/O\u0003s\u0001T%\"N\u0003|^\tq8DObN\u001c0<N\u0003s\u0006\u0011q+IJk\u0007\u0000(j_L'\r\u00064+_F+N\u00064+O\u000f'\u001b\u00045+_F'\u000f\u001a5jOFk\u000b\u00004jNMs\u0007\u00008/X\u0003p\u0007\u00009#E\u0003s\u0006\u0011q1\u001a^'\u001d\u00112?YJs\u0017T+%EF)\u001a@u\u000b\u0015%/iBt\u000b'4)^Qn\u001a\r\u000b%EFU\u0001\u001847@h\u0003[=}_Fd\u0006[\"/YUb\u001c[\"/HVu\u0007\u0000(eYAf\r[\u0002/HVu\u0007\u0000(\u0010DMb#\u0015?+LFu'\u0019!&\u000bGb\u001d\u0017##[Wn\u0001\u001a\u0016nf\u0000\u00156/\u000bX7\u0013T\u000b%EF'FW*{V\n=\u000b8RI\u000f\u0016\\\u0004|IE}{\u0019\u001b \u0013Sqc\u0005\t8FKljP\u0013zN(yip\u007fc5(5f\u000b~{55|\u0010J\u000e}^Yh\u0017v\t[GPx#Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Nf\u0000\u00156/qLi\u000bZ0?_LD\u001c\u00110>N";
                var4_3 = "`u\u000b\u0015%#ED'\u0000\u0011&jyLk\u000bNq>bu\t\u0001</EW'\b\u001b#jkmh\u001a:$&G\u0003w\u000f\u00060'NWb\u001cTvoX\u0004'\u0001\u0012qoX\r\"\u001dT<?XW'\u0000\u001b%jIF'\u0000\u0001=&^vt\u000b\u0006\"jJPt\u0007\u0013?/O\u0003s\u0001T%\"N\u0003|^\tq8DObN\u001c0<N\u0003s\u0006\u0011q+IJk\u0007\u0000(j_L'\u001c\u00110.\u000bFi\u001a\u001d%#NP'\u0019\u001d%\"BM'\u001a\u001c4jP\u0012zN\u00074)^Qn\u001a\rq0DMb@\u000bVw\n\u0015%/yLk\u000b\u0007!Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Un\u000b\u0003\u000b%EF)\u000f\u0001%%hQb\u000f\u00004#Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Nf\u0000\u00156/qLi\u000bZ0?_LD\u001c\u00110>N\u0004yh\u0000\u0011\nQh\u0001\u0000\u0017%GGb\u001c\u0016nf\u0000\u00156/\u000bX7\u0013T\u000b%EF'FW*{V\n\u0004Yh\u0000\u0011\u0017Bc\n&4+Opb\r\u0001##_Z]\u0001\u001a4\u0018DOb\u0014un\u000b\u0003q1\u001b^'4\u001b?/\u000b\u000b$\u0015E,c!Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Un\u000b\u0003\u000b%EF)\u000f\u0001%%hQb\u000f\u00004^vt\u000b\u0006\"jJPt\u0007\u0013?/O\u0003s\u0001T%\"N\u0003|^\tq8DObN\u001c0<N\u0003s\u0006\u0011q+IJk\u0007\u0000(j_L'\u001c\u00110.\u000bFi\u001a\u001d%#NP'\u0019\u001d%\"BM'\u001a\u001c4jP\u0012zN\u00074)^Qn\u001a\rq0DMb@\u0019Bc\n90$JDb=\u00112?YJs\u0017.>$Nqh\u0002\u0011\u001e`h\u001b\u00185jELsN\u00128$O\u0003u\u0001\u001849\u000bWhN\u0001!.JWb\u0014un\u000b\u0003q1\u001b^'4\u001b?/\u000b\u000b$\u0015E,c\u0004Mf\u0003\u0011yvt\u000b\u0006\"jJPt\u0007\u0013?/O\u0003s\u0001T%\"N\u0003|^\tq8DObN\u001c0<N\u0003s\u0006\u0011q+IJk\u0007\u0000(j_L'\r\u00064+_F+N\u00064+O\u000f'\u001b\u00045+_F'\u000f\u001a5jOFk\u000b\u00004jNMs\u0007\u00008/X\u0003p\u0007\u00009#E\u0003s\u0006\u0011q1\u001a^'\u001d\u00112?YJs\u0017T+%EF)\u001a@u\u000b\u0015%/iBt\u000b'4)^Qn\u001a\r\u000b%EFU\u0001\u001847@h\u0003[=}_Fd\u0006[\"/YUb\u001c[\"/HVu\u0007\u0000(eYAf\r[\u0002/HVu\u0007\u0000(\u0010DMb#\u0015?+LFu'\u0019!&\u000bGb\u001d\u0017##[Wn\u0001\u001a\u0016nf\u0000\u00156/\u000bX7\u0013T\u000b%EF'FW*{V\n=\u000b8RI\u000f\u0016\\\u0004|IE}{\u0019\u001b \u0013Sqc\u0005\t8FKljP\u0013zN(yip\u007fc5(5f\u000b~{55|\u0010J\u000e}^Yh\u0017v\t[GPx#Qe\u000f\u0017\u007f+^Wh<\u001b=/\u0005Nf\u0000\u00156/qLi\u000bZ0?_LD\u001c\u00110>N".length();
                var1_4 = 19;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = SecurityZoneManagerImpl.b(v0, SecurityZoneManagerImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "!#\\Qu=\u001d\u0007#PDhx\u0018T$V\u0003ru\u0019T+\t^&o\u0013\u00185\u0019Kgk\u0019T$QF&|\u001e\u001d<PW\u007f=\b\u001bpZQc|\b\u0011|\u0019Qc|\u0018XpLSb|\b\u0011pXMb=\u0018\u0011<\\Wc=\u0019\u001a$PWox\u000fT'PWnt\u0012T$QF&fM\tpJFeh\u000e\u001d$@\u0003|r\u0012\u0011~\u001a!>XAjx\\\u0000?\u0019Eos\u0018T\"VLr=\u001a\u001b<]Ft";
                    var4_3 = "!#\\Qu=\u001d\u0007#PDhx\u0018T$V\u0003ru\u0019T+\t^&o\u0013\u00185\u0019Kgk\u0019T$QF&|\u001e\u001d<PW\u007f=\b\u001bpZQc|\b\u0011|\u0019Qc|\u0018XpLSb|\b\u0011pXMb=\u0018\u0011<\\Wc=\u0019\u001a$PWox\u000fT'PWnt\u0012T$QF&fM\tpJFeh\u000e\u001d$@\u0003|r\u0012\u0011~\u001a!>XAjx\\\u0000?\u0019Eos\u0018T\"VLr=\u001a\u001b<]Ft".length();
                    var1_4 = 121;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 17;
                        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++] = SecurityZoneManagerImpl.b(v0, SecurityZoneManagerImpl.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;
            }
        }
        SecurityZoneManagerImpl.v = var5;
        SecurityZoneManagerImpl.o = SecurityZoneManagerImpl.v[13];
        SecurityZoneManagerImpl.p = SecurityZoneManagerImpl.v[18];
        SecurityZoneManagerImpl.u = SecurityZoneManagerImpl.v[11];
        SecurityZoneManagerImpl.n = SecurityZoneManagerImpl.v[24];
        SecurityZoneManagerImpl.m = SecurityZoneManagerImpl.v[12];
        SecurityZoneManagerImpl.t = SecurityZoneManagerImpl.v[22];
        var0_6 = SecurityZoneManagerImpl.v;
        SecurityZoneManagerImpl.q = Pattern.compile(MessageFormat.format(var0_6[23], new Object[]{var0_6[6]}));
        SecurityZoneManagerImpl.s = Logger.getLogger(SecurityZoneManagerImpl.class.getName());
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void b(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 2[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 Exception a(Exception exception) {
        return exception;
    }

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

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String b(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 -> 101;
                    case 1 -> 65;
                    case 2 -> 40;
                    case 3 -> 50;
                    case 4 -> 23;
                    case 5 -> 12;
                    default -> 109;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

