/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.rbac.OperationType
 *  com.l7tech.gateway.common.security.rbac.OtherOperationName
 *  com.l7tech.gateway.common.service.PublishedService
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.objectmodel.ObjectModelException
 *  com.l7tech.policy.PolicyType
 *  com.l7tech.util.Triple
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.upgrade;

import com.l7tech.gateway.common.security.rbac.OperationType;
import com.l7tech.gateway.common.security.rbac.OtherOperationName;
import com.l7tech.gateway.common.service.PublishedService;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.Goid;
import com.l7tech.objectmodel.ObjectModelException;
import com.l7tech.policy.PolicyType;
import com.l7tech.server.upgrade.AbstractDynamicRolePermissionsUpgradeTask;
import com.l7tech.util.Triple;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;

public class Upgrade8102To8200UpdateRoles
extends AbstractDynamicRolePermissionsUpgradeTask {
    private static final Logger c;
    private static final String[] e;

    @Override
    protected List<Triple<OperationType, String, EntityType>> permissionsToAdd() {
        return Arrays.asList(new Triple((Object)OperationType.OTHER, (Object)OtherOperationName.DEBUGGER.getOperationName(), (Object)EntityType.POLICY));
    }

    @Override
    protected String getScopeId(EntityType entityType, Goid goid) throws ObjectModelException {
        String string;
        block6: {
            string = null;
            if (EntityType.POLICY.equals((Object)entityType)) {
                string = goid.toString();
            } else {
                try {
                    if (!EntityType.SERVICE.equals((Object)entityType) || goid == null) break block6;
                }
                catch (ObjectModelException objectModelException) {
                    throw Upgrade8102To8200UpdateRoles.b((Exception)((Object)objectModelException));
                }
                PublishedService publishedService = (PublishedService)this.serviceManager.findByPrimaryKey(goid);
                if (publishedService != null) {
                    string = publishedService.getPolicy().getId();
                } else {
                    String[] stringArray = e;
                    c.warning(stringArray[3] + String.valueOf(goid) + stringArray[0]);
                }
            }
        }
        return string;
    }

    @Override
    protected boolean shouldCreateMissingRoles() {
        return false;
    }

    @Override
    protected boolean shouldIgnorePolicyType(PolicyType policyType) {
        boolean bl2;
        try {
            bl2 = !PolicyType.GLOBAL_FRAGMENT.equals((Object)policyType);
        }
        catch (IllegalStateException illegalStateException) {
            throw Upgrade8102To8200UpdateRoles.b(illegalStateException);
        }
        return bl2;
    }

    @Override
    @NotNull
    protected Collection<EntityType> getEntityTypesToUpgrade() {
        List<EntityType> list;
        try {
            list = Arrays.asList(EntityType.SERVICE, EntityType.POLICY);
            if (list == null) {
                Upgrade8102To8200UpdateRoles.a(0);
            }
        }
        catch (IllegalStateException illegalStateException) {
            throw Upgrade8102To8200UpdateRoles.b(illegalStateException);
        }
        return list;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[5];
                var3_1 = 0;
                var2_2 = ".\u0017`\">\u0001th_$%?\u0012tm^\"96\u00121{\u001b0)#\u0018=zH)#?[6jT-c=B lX(c\"\u0010&\u007f^2c$\u00053{Z$)~ $nI!(4Me9\t\u0014#iGd9n0(0\u00011[T,)\"\u0017n^4\t?\u0001=}B\u00145!\u0010']T\u0015<6\u00075m^";
                var4_3 = ".\u0017`\">\u0001th_$%?\u0012tm^\"96\u00121{\u001b0)#\u0018=zH)#?[6jT-c=B lX(c\"\u0010&\u007f^2c$\u00053{Z$)~ $nI!(4Me9\t\u0014#iGd9n0(0\u00011[T,)\"\u0017n^4\t?\u0001=}B\u00145!\u0010']T\u0015<6\u00075m^".length();
                var1_4 = 34;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = Upgrade8102To8200UpdateRoles.b(v0, Upgrade8102To8200UpdateRoles.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "W^*%6\u001b\u007fv_k&9\u001d:qCk4?\f)kS.g}*B~$3\u0014\u000b3n\u0010&\".\u00160f\u0010n4t[,\"]>4.^1mDk5?\n*p^k)/\u00123";
                    var4_3 = "W^*%6\u001b\u007fv_k&9\u001d:qCk4?\f)kS.g}*B~$3\u0014\u000b3n\u0010&\".\u00160f\u0010n4t[,\"]>4.^1mDk5?\n*p^k)/\u00123".length();
                    var1_4 = 26;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 124;
                        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++] = Upgrade8102To8200UpdateRoles.b(v0, Upgrade8102To8200UpdateRoles.b(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;
            }
        }
        Upgrade8102To8200UpdateRoles.e = var5;
        Upgrade8102To8200UpdateRoles.c = Logger.getLogger(Upgrade8102To8200UpdateRoles.class.getName());
    }

    private static /* synthetic */ void a(int n2) {
        String[] stringArray = e;
        throw new IllegalStateException(String.format(stringArray[4], stringArray[1], stringArray[2]));
    }

    private static Exception b(Exception exception) {
        return exception;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x23);
        }
        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 -> 126;
                    case 1 -> 76;
                    case 2 -> 55;
                    case 3 -> 59;
                    case 4 -> 38;
                    case 5 -> 2;
                    default -> 35;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

