/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.security.keystore.SsgKeyEntry
 *  com.l7tech.objectmodel.DeleteException
 *  com.l7tech.objectmodel.Entity
 *  com.l7tech.objectmodel.EntityType
 *  com.l7tech.objectmodel.PersistentEntity
 *  com.l7tech.util.ExceptionUtils
 *  org.springframework.context.ApplicationEvent
 *  org.springframework.context.ApplicationListener
 */
package com.l7tech.server.security.rbac;

import com.l7tech.gateway.common.security.keystore.SsgKeyEntry;
import com.l7tech.objectmodel.DeleteException;
import com.l7tech.objectmodel.Entity;
import com.l7tech.objectmodel.EntityType;
import com.l7tech.objectmodel.PersistentEntity;
import com.l7tech.server.event.RoleAwareEntityDeletionEvent;
import com.l7tech.server.security.rbac.RoleManagerImpl;
import com.l7tech.util.ExceptionUtils;
import java.util.logging.Level;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

class g
implements ApplicationListener {
    final RoleManagerImpl this$0;
    private static final String[] a;

    g(RoleManagerImpl roleManagerImpl) {
        this.this$0 = roleManagerImpl;
    }

    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        block10: {
            if (applicationEvent instanceof RoleAwareEntityDeletionEvent) {
                Entity entity = ((RoleAwareEntityDeletionEvent)applicationEvent).getEntity();
                EntityType entityType = EntityType.findTypeByEntity((Class)entity.getClass());
                try {
                    if (entityType == null || entityType == EntityType.ANY) break block10;
                }
                catch (DeleteException deleteException) {
                    throw g.a(deleteException);
                }
                try {
                    block11: {
                        try {
                            if (!(entity instanceof PersistentEntity)) break block11;
                            this.this$0.deleteEntitySpecificRoles(entityType, ((PersistentEntity)entity).getGoid());
                            break block10;
                        }
                        catch (DeleteException deleteException) {
                            throw g.a(deleteException);
                        }
                    }
                    try {
                        if (entity instanceof SsgKeyEntry) {
                            this.this$0.deleteEntitySpecificPermissions(entityType, entity.getId());
                        }
                    }
                    catch (DeleteException deleteException) {
                        throw g.a(deleteException);
                    }
                }
                catch (DeleteException deleteException) {
                    String[] stringArray = a;
                    RoleManagerImpl.m.log(Level.WARNING, stringArray[0] + String.valueOf(entity) + stringArray[1] + ExceptionUtils.getMessage((Throwable)deleteException), ExceptionUtils.getDebugException((Throwable)deleteException));
                }
            }
        }
    }

    private static DeleteException a(DeleteException deleteException) {
        return deleteException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "3\u0014VQ2m$\u0013\nAJ)#'V\u0014KR%>`\u0010\tV\u001e%#4\u001f\u0012]\u001e\u0002LF";
        int n3 = "3\u0014VQ2m$\u0013\nAJ)#'V\u0014KR%>`\u0010\tV\u001e%#4\u001f\u0012]\u001e\u0002LF".length();
        int n4 = 32;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = g.a(38, g.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                a = 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] ^ 0x66);
        }
        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 -> 80;
                    case 1 -> 64;
                    case 2 -> 2;
                    case 3 -> 24;
                    case 4 -> 102;
                    case 5 -> 107;
                    default -> 102;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

