/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.password.IncorrectPasswordException
 *  com.l7tech.common.password.PasswordHasher
 *  com.l7tech.gateway.common.Component
 *  com.l7tech.gateway.common.security.rbac.Role
 *  com.l7tech.gateway.common.security.rbac.Role$Tag
 *  com.l7tech.identity.IdentityProviderConfigManager
 *  com.l7tech.identity.IdentityProviderPasswordPolicy
 *  com.l7tech.identity.IdentityProviderPasswordPolicyManager
 *  com.l7tech.identity.User
 *  com.l7tech.identity.internal.InternalUser
 *  com.l7tech.identity.internal.PasswordChangeRecord
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.objectmodel.InvalidPasswordException
 *  com.l7tech.util.Charsets
 *  com.l7tech.util.Config
 *  com.l7tech.util.HexUtils
 *  org.springframework.beans.BeansException
 *  org.springframework.context.ApplicationContext
 *  org.springframework.context.ApplicationContextAware
 *  org.springframework.context.ApplicationEvent
 *  org.springframework.core.Ordered
 */
package com.l7tech.server.security;

import com.l7tech.common.password.IncorrectPasswordException;
import com.l7tech.common.password.PasswordHasher;
import com.l7tech.gateway.common.Component;
import com.l7tech.gateway.common.security.rbac.Role;
import com.l7tech.identity.IdentityProviderConfigManager;
import com.l7tech.identity.IdentityProviderPasswordPolicy;
import com.l7tech.identity.IdentityProviderPasswordPolicyManager;
import com.l7tech.identity.User;
import com.l7tech.identity.internal.InternalUser;
import com.l7tech.identity.internal.PasswordChangeRecord;
import com.l7tech.objectmodel.FindException;
import com.l7tech.objectmodel.InvalidPasswordException;
import com.l7tech.server.event.EntityClassEvent;
import com.l7tech.server.event.system.ReadyForMessages;
import com.l7tech.server.event.system.SystemEvent;
import com.l7tech.server.security.rbac.RoleManager;
import com.l7tech.server.util.PostStartupApplicationListener;
import com.l7tech.util.Charsets;
import com.l7tech.util.Config;
import com.l7tech.util.HexUtils;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.Ordered;

public class PasswordEnforcerManager
implements PropertyChangeListener,
ApplicationContextAware,
PostStartupApplicationListener,
Ordered {
    private static final Logger a;
    private final IdentityProviderPasswordPolicyManager b;
    private final Config c;
    private ApplicationContext d;
    private final RoleManager e;
    private final PasswordHasher f;
    private IdentityProviderPasswordPolicy g;
    private final IdentityProviderPasswordPolicy h;
    private final IdentityProviderPasswordPolicy i;
    private static final String[] j;

    public PasswordEnforcerManager(Config config, IdentityProviderPasswordPolicyManager identityProviderPasswordPolicyManager, RoleManager roleManager, PasswordHasher passwordHasher, IdentityProviderPasswordPolicy identityProviderPasswordPolicy, IdentityProviderPasswordPolicy identityProviderPasswordPolicy2) {
        this.b = identityProviderPasswordPolicyManager;
        this.c = config;
        this.e = roleManager;
        this.f = passwordHasher;
        this.h = identityProviderPasswordPolicy;
        this.i = identityProviderPasswordPolicy2;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        try {
            if (this.d != null) {
                throw new IllegalStateException(j[15]);
            }
        }
        catch (BeansException beansException) {
            throw PasswordEnforcerManager.a((Exception)((Object)beansException));
        }
        this.d = applicationContext;
        this.g = this.a();
    }

    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        block12: {
            block9: {
                boolean bl2;
                PasswordEnforcerManager passwordEnforcerManager;
                block11: {
                    block10: {
                        try {
                            try {
                                if (!(applicationEvent instanceof ReadyForMessages)) break block9;
                                passwordEnforcerManager = this;
                                if (this.c.getBooleanProperty(j[18], false)) break block10;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw PasswordEnforcerManager.a(illegalStateException);
                            }
                            bl2 = true;
                            break block11;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw PasswordEnforcerManager.a(illegalStateException);
                        }
                    }
                    bl2 = false;
                }
                passwordEnforcerManager.a(bl2, this.g);
                break block12;
            }
            if (applicationEvent instanceof EntityClassEvent) {
                boolean bl3;
                PasswordEnforcerManager passwordEnforcerManager;
                block14: {
                    block13: {
                        EntityClassEvent entityClassEvent = (EntityClassEvent)applicationEvent;
                        try {
                            try {
                                if (!IdentityProviderPasswordPolicy.class.equals(entityClassEvent.getEntityClass())) break block12;
                                this.g = this.a();
                                passwordEnforcerManager = this;
                                if (this.c.getBooleanProperty(j[18], false)) break block13;
                            }
                            catch (IllegalStateException illegalStateException) {
                                throw PasswordEnforcerManager.a(illegalStateException);
                            }
                            bl3 = true;
                            break block14;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw PasswordEnforcerManager.a(illegalStateException);
                        }
                    }
                    bl3 = false;
                }
                passwordEnforcerManager.a(bl3, this.g);
            }
        }
    }

    public int getOrder() {
        return 50000;
    }

    @Override
    public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
        block4: {
            boolean bl2;
            PasswordEnforcerManager passwordEnforcerManager;
            String string = propertyChangeEvent.getPropertyName();
            String string2 = (String)propertyChangeEvent.getNewValue();
            try {
                if (string == null || !j[3].equals(string)) break block4;
            }
            catch (IllegalStateException illegalStateException) {
                throw PasswordEnforcerManager.a(illegalStateException);
            }
            boolean bl3 = Boolean.valueOf(string2);
            try {
                passwordEnforcerManager = this;
                bl2 = !bl3;
            }
            catch (IllegalStateException illegalStateException) {
                throw PasswordEnforcerManager.a(illegalStateException);
            }
            passwordEnforcerManager.a(bl2, this.g);
        }
    }

    public IdentityProviderPasswordPolicy getPasswordPolicy() {
        return this.g;
    }

    private void a(boolean bl2, IdentityProviderPasswordPolicy identityProviderPasswordPolicy) {
        block6: {
            String string;
            Object[] objectArray;
            String string2;
            block8: {
                block7: {
                    IdentityProviderPasswordPolicy identityProviderPasswordPolicy2;
                    try {
                        identityProviderPasswordPolicy2 = bl2 ? this.h : this.i;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw PasswordEnforcerManager.a(illegalStateException);
                    }
                    IdentityProviderPasswordPolicy identityProviderPasswordPolicy3 = identityProviderPasswordPolicy2;
                    try {
                        try {
                            if (identityProviderPasswordPolicy.hasStrengthOf(identityProviderPasswordPolicy3)) break block6;
                            string2 = j[10];
                            Object[] objectArray2 = new Object[2];
                            Object[] objectArray3 = objectArray2;
                            objectArray = objectArray2;
                            int n2 = 0;
                            if (!bl2) break block7;
                        }
                        catch (IllegalStateException illegalStateException) {
                            throw PasswordEnforcerManager.a(illegalStateException);
                        }
                        string = j[12];
                        break block8;
                    }
                    catch (IllegalStateException illegalStateException) {
                        throw PasswordEnforcerManager.a(illegalStateException);
                    }
                }
                String[] stringArray = j;
                string = stringArray[20];
            }
            objectArray3[n2] = string;
            objectArray[1] = j[14];
            String string3 = MessageFormat.format(string2, objectArray);
            this.d.publishEvent((ApplicationEvent)new SystemEvent(this, Component.GW_PASSWD_POLICY_MGR, null, Level.WARNING, string3){
                static final long serialVersionUID = 3227859774827359757L;
                private static final String b = 1.b(109, 1.b("\u0011%wZ\u000bKo%dTF\u0010M~8dRH\u0010My 0mF\u0012"));

                @Override
                public String getAction() {
                    return b;
                }

                private static char[] b(String string) {
                    char[] cArray = string.toCharArray();
                    if (cArray.length < 2) {
                        cArray = cArray;
                        cArray[0] = (char)(cArray[0] ^ 0x70);
                    }
                    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 -> 44;
                                case 1 -> 41;
                                case 2 -> 105;
                                case 3 -> 68;
                                case 4 -> 17;
                                case 5 -> 73;
                                default -> 112;
                            })));
                            ++n3;
                            n4 = n4;
                        } while (n4 > n3);
                    }
                    return new String(cArray2).intern();
                }
            });
        }
    }

    public void isPasswordPolicyCompliant(User user, String string, String string2) throws InvalidPasswordException {
        try {
            if (user instanceof InternalUser) {
                this.validatePasswordChangesAllowable(user);
                this.a(string);
                this.a(string, string2);
                this.a(user, string);
            }
        }
        catch (InvalidPasswordException invalidPasswordException) {
            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
        }
    }

    public void isPasswordPolicyCompliant(String string) throws InvalidPasswordException {
        this.a(string);
    }

    private void a(String string) throws InvalidPasswordException {
        PasswordEnforcerManager.a(string, this.g);
    }

    static void a(String string, IdentityProviderPasswordPolicy identityProviderPasswordPolicy) throws InvalidPasswordException {
        ArrayList<String> arrayList;
        block51: {
            boolean bl2;
            int n2;
            int n3;
            int n4;
            int n5;
            int n6;
            block50: {
                char[] cArray = string.toCharArray();
                n6 = 0;
                n5 = 0;
                n4 = 0;
                n3 = 0;
                n2 = 0;
                bl2 = false;
                char c10 = '0';
                int n7 = 0;
                while (true) {
                    block49: {
                        block45: {
                            block48: {
                                block47: {
                                    block46: {
                                        block44: {
                                            try {
                                                try {
                                                    if (n7 >= string.length()) break;
                                                    if (!Character.isUpperCase(cArray[n7])) break block44;
                                                }
                                                catch (InvalidPasswordException invalidPasswordException) {
                                                    throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                                                }
                                                ++n6;
                                                break block45;
                                            }
                                            catch (InvalidPasswordException invalidPasswordException) {
                                                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                                            }
                                        }
                                        try {
                                            if (!Character.isLowerCase(cArray[n7])) break block46;
                                            ++n5;
                                            break block45;
                                        }
                                        catch (InvalidPasswordException invalidPasswordException) {
                                            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                                        }
                                    }
                                    try {
                                        if (!Character.isDigit(cArray[n7])) break block47;
                                        ++n4;
                                        break block45;
                                    }
                                    catch (InvalidPasswordException invalidPasswordException) {
                                        throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                                    }
                                }
                                try {
                                    try {
                                        if (Character.isLetterOrDigit(cArray[n7]) || Character.isWhitespace(cArray[n7])) break block48;
                                    }
                                    catch (InvalidPasswordException invalidPasswordException) {
                                        throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                                    }
                                    ++n2;
                                    break block45;
                                }
                                catch (InvalidPasswordException invalidPasswordException) {
                                    throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                                }
                            }
                            ++n3;
                        }
                        try {
                            if (n7 == 0 || cArray[n7] != c10) break block49;
                        }
                        catch (InvalidPasswordException invalidPasswordException) {
                            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                        }
                        bl2 = true;
                    }
                    c10 = cArray[n7];
                    ++n7;
                }
                arrayList = new ArrayList<String>();
                int n8 = identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.MIN_PASSWORD_LENGTH);
                try {
                    if (string.length() < n8) {
                        PasswordEnforcerManager.a(arrayList, j[6], n8);
                    }
                }
                catch (InvalidPasswordException invalidPasswordException) {
                    throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                }
                int n9 = identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.MAX_PASSWORD_LENGTH);
                try {
                    try {
                        if (n9 <= 0 || string.length() <= n9) break block50;
                    }
                    catch (InvalidPasswordException invalidPasswordException) {
                        throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                    }
                    PasswordEnforcerManager.a(arrayList, j[17], n9);
                }
                catch (InvalidPasswordException invalidPasswordException) {
                    throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                }
            }
            try {
                if (identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.UPPER_MIN) > n6) {
                    PasswordEnforcerManager.a(arrayList, j[13], identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.UPPER_MIN));
                }
            }
            catch (InvalidPasswordException invalidPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
            }
            try {
                if (identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.LOWER_MIN) > n5) {
                    PasswordEnforcerManager.a(arrayList, j[1], identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.LOWER_MIN));
                }
            }
            catch (InvalidPasswordException invalidPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
            }
            try {
                if (identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.NUMBER_MIN) > n4) {
                    PasswordEnforcerManager.a(arrayList, j[4], identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.NUMBER_MIN));
                }
            }
            catch (InvalidPasswordException invalidPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
            }
            try {
                if (identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.SYMBOL_MIN) > n2) {
                    PasswordEnforcerManager.a(arrayList, j[0], identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.SYMBOL_MIN));
                }
            }
            catch (InvalidPasswordException invalidPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
            }
            try {
                if (identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.NON_NUMERIC_MIN) > n6 + n5 + n2 + n3) {
                    PasswordEnforcerManager.a(arrayList, j[2], identityProviderPasswordPolicy.getIntegerProperty(IdentityProviderPasswordPolicy.NON_NUMERIC_MIN));
                }
            }
            catch (InvalidPasswordException invalidPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
            }
            try {
                try {
                    if (!identityProviderPasswordPolicy.getBooleanProperty(IdentityProviderPasswordPolicy.NO_REPEAT_CHARS).booleanValue() || !bl2) break block51;
                }
                catch (InvalidPasswordException invalidPasswordException) {
                    throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                }
                PasswordEnforcerManager.a(arrayList, j[16], new Object[0]);
            }
            catch (InvalidPasswordException invalidPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
            }
        }
        try {
            if (!arrayList.isEmpty()) {
                throw new InvalidPasswordException((String)arrayList.get(0), identityProviderPasswordPolicy.getDescription(), arrayList);
            }
        }
        catch (InvalidPasswordException invalidPasswordException) {
            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
        }
    }

    private static void a(Collection<String> collection, String string, Object ... objectArray) {
        collection.add(MessageFormat.format(string, objectArray));
    }

    private void a(String string, String string2) throws InvalidPasswordException {
        int n2;
        try {
            if (string.equals(string2)) {
                throw new InvalidPasswordException(j[19]);
            }
        }
        catch (InvalidPasswordException invalidPasswordException) {
            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
        }
        HashSet<String> hashSet = new HashSet<String>();
        try {
            for (n2 = 0; n2 < string2.length(); ++n2) {
                hashSet.add(string2.substring(n2, n2 + 1));
            }
        }
        catch (InvalidPasswordException invalidPasswordException) {
            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
        }
        n2 = this.g.getIntegerProperty(IdentityProviderPasswordPolicy.CHARACTER_DIFF_MIN);
        try {
            if (n2 < 0) {
                return;
            }
        }
        catch (InvalidPasswordException invalidPasswordException) {
            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
        }
        int n3 = 0;
        int n4 = 0;
        while (true) {
            block16: {
                try {
                    try {
                        try {
                            if (n4 >= string.length()) break;
                            if (hashSet.contains(string.substring(n4, n4 + 1))) break block16;
                        }
                        catch (InvalidPasswordException invalidPasswordException) {
                            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                        }
                        if (++n3 < n2) break block16;
                    }
                    catch (InvalidPasswordException invalidPasswordException) {
                        throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                    }
                    return;
                }
                catch (InvalidPasswordException invalidPasswordException) {
                    throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                }
            }
            ++n4;
        }
        throw new InvalidPasswordException(MessageFormat.format(j[11], n2), this.g.getDescription());
    }

    private void a(User user, String string) throws InvalidPasswordException {
        List list = ((InternalUser)user).getPasswordChangesHistory();
        int n2 = this.g.getIntegerProperty(IdentityProviderPasswordPolicy.REPEAT_FREQUENCY);
        try {
            if (n2 < 0) {
                return;
            }
        }
        catch (IncorrectPasswordException incorrectPasswordException) {
            throw PasswordEnforcerManager.a((Exception)((Object)incorrectPasswordException));
        }
        ListIterator listIterator = list.listIterator(Math.max(0, list.size() - n2 + 1));
        byte[] byArray = string.getBytes(Charsets.UTF8);
        while (listIterator.hasNext()) {
            String string2;
            PasswordChangeRecord passwordChangeRecord = (PasswordChangeRecord)listIterator.next();
            if (passwordChangeRecord == null) continue;
            String string3 = passwordChangeRecord.getPrevHashedPassword();
            boolean bl2 = false;
            try {
                if (this.f.isVerifierRecognized(string3)) {
                    this.f.verifyPassword(byArray, string3);
                    bl2 = true;
                }
            }
            catch (IncorrectPasswordException incorrectPasswordException) {
                // empty catch block
            }
            if (!bl2 && string3.equals(string2 = HexUtils.encodePasswd((String)user.getLogin(), (String)string, (String)HexUtils.REALM))) {
                bl2 = true;
            }
            try {
                if (!bl2) continue;
                throw new InvalidPasswordException(MessageFormat.format(j[21], n2), this.g.getDescription());
            }
            catch (IncorrectPasswordException incorrectPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)incorrectPasswordException));
            }
        }
    }

    public void validatePasswordChangesAllowable(User user) throws InvalidPasswordException {
        block14: {
            boolean bl2 = this.g.getBooleanProperty(IdentityProviderPasswordPolicy.ALLOWABLE_CHANGES);
            try {
                if (!bl2) {
                    return;
                }
            }
            catch (InvalidPasswordException invalidPasswordException) {
                throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
            }
            long l2 = System.currentTimeMillis();
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(l2);
            calendar.add(6, -1);
            Calendar calendar2 = Calendar.getInstance();
            if (user instanceof InternalUser) {
                InternalUser internalUser;
                block13: {
                    internalUser = (InternalUser)user;
                    try {
                        try {
                            if (!this.hasAdminRole(internalUser) && !internalUser.isChangePassword()) break block13;
                        }
                        catch (InvalidPasswordException invalidPasswordException) {
                            throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                        }
                        return;
                    }
                    catch (InvalidPasswordException invalidPasswordException) {
                        throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                    }
                }
                List list = internalUser.getPasswordChangesHistory();
                try {
                    if (list == null || list.isEmpty()) break block14;
                }
                catch (InvalidPasswordException invalidPasswordException) {
                    throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException));
                }
                PasswordChangeRecord passwordChangeRecord = (PasswordChangeRecord)list.get(list.size() - 1);
                long l3 = passwordChangeRecord.getLastChanged();
                calendar2.setTimeInMillis(l3);
                if (calendar2.after(calendar)) {
                    Object object;
                    Object[] objectArray;
                    String string;
                    InvalidPasswordException invalidPasswordException;
                    InvalidPasswordException invalidPasswordException2;
                    long l4 = 1440L - (l2 - l3) / 60000L;
                    try {
                        InvalidPasswordException invalidPasswordException3;
                        invalidPasswordException2 = invalidPasswordException3;
                        invalidPasswordException = invalidPasswordException3;
                        string = j[8];
                        Object[] objectArray2 = new Object[1];
                        Object[] objectArray3 = objectArray2;
                        objectArray = objectArray2;
                        int n2 = 0;
                        object = l4 >= 60L ? l4 / 60L + j[5] : "";
                    }
                    catch (InvalidPasswordException invalidPasswordException4) {
                        throw PasswordEnforcerManager.a((Exception)((Object)invalidPasswordException4));
                    }
                    objectArray3[n2] = (String)object + l4 % 60L;
                    invalidPasswordException2(MessageFormat.format(string, objectArray), this.g.getDescription());
                    throw invalidPasswordException;
                }
            }
        }
    }

    public void setUserPasswordPolicyAttributes(InternalUser internalUser, boolean bl2) {
        internalUser.setPasswordExpiry(this.a(System.currentTimeMillis()));
        if (bl2) {
            boolean bl3 = this.g.getBooleanProperty(IdentityProviderPasswordPolicy.FORCE_PWD_CHANGE);
            internalUser.setChangePassword(bl3);
        }
    }

    public boolean hasAdminRole(InternalUser internalUser) {
        try {
            Collection<Role> collection = this.e.getAssignedRoles((User)internalUser);
            if (collection == null) {
                return false;
            }
            for (Role role : collection) {
                if (role.getTag() != Role.Tag.ADMIN) continue;
                return true;
            }
            return false;
        }
        catch (FindException findException) {
            return false;
        }
    }

    private long a(long l2) {
        try {
            long l3;
            int n2 = (Integer)this.g.getPropertyValue(IdentityProviderPasswordPolicy.PASSWORD_EXPIRY);
            try {
                l3 = n2 < 0 ? -1L : PasswordEnforcerManager.a(l2, n2);
            }
            catch (NullPointerException nullPointerException) {
                throw PasswordEnforcerManager.a(nullPointerException);
            }
            return l3;
        }
        catch (NullPointerException nullPointerException) {
            return -1L;
        }
    }

    public boolean isPasswordExpired(User user) {
        if (user instanceof InternalUser) {
            InternalUser internalUser = (InternalUser)user;
            try {
                if (internalUser.isChangePassword()) {
                    return true;
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw PasswordEnforcerManager.a(illegalStateException);
            }
            try {
                if (internalUser.getPasswordExpiry() < 0L) {
                    return false;
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw PasswordEnforcerManager.a(illegalStateException);
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(internalUser.getPasswordExpiry());
            Calendar calendar2 = Calendar.getInstance();
            try {
                calendar2.setTimeInMillis(System.currentTimeMillis());
                if (calendar2.after(calendar)) {
                    return true;
                }
            }
            catch (IllegalStateException illegalStateException) {
                throw PasswordEnforcerManager.a(illegalStateException);
            }
        }
        return false;
    }

    private static long a(long l2, int n2) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(l2);
        calendar.add(6, n2);
        return calendar.getTimeInMillis();
    }

    private IdentityProviderPasswordPolicy a() {
        IdentityProviderPasswordPolicy identityProviderPasswordPolicy = null;
        String[] stringArray = j;
        String string = stringArray[7];
        try {
            identityProviderPasswordPolicy = this.b.findByInternalIdentityProviderOid(IdentityProviderConfigManager.INTERNALPROVIDER_SPECIAL_GOID);
        }
        catch (FindException findException) {
            stringArray = j;
            a.log(Level.WARNING, stringArray[9]);
        }
        try {
            if (identityProviderPasswordPolicy == null) {
                throw new IllegalStateException(j[9]);
            }
        }
        catch (FindException findException) {
            throw PasswordEnforcerManager.a((Exception)((Object)findException));
        }
        return identityProviderPasswordPolicy;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[22];
                var3_1 = 0;
                var2_2 = "!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u0002\r-d;\u000e\u000fQ\u001e f \u000e\u0000\u0005\u0018:/!F:!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u001d\u0012?b O\u0000\u0010\u000e-'1\u0007\u0002\u0003\u001c+s7\u001dK\u0002T;!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u001f\u0012&*<\u001a\u000e\u0014\u000f!dr\f\u000b\u0010\u000f)d&\n\u0011Y\u000ea\u0017\u0002\u0018+r \u0006\u0017\bS8d;\u000b\u0010\u0002S-i3\r\u000f\u0014\u0019,!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u001f\b%e7\u001dK\u0002T\u000bQ\u0015'r \u001cC\u0010\u0013,'2!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0013\u0018hf&O\u000f\u0014\u001c;sr\u0014S\f]+o3\u001d\u0002\u0012\t-u!O\n\u001f]$b<\b\u0017\u0019>2\u0012=k6O\r\u001e\tha;\u0001\u0007Q\r)t!\u0018\f\u0003\u0019hw=\u0003\n\u0012\u0004ha=\u001dC\u0018\u0013<b \u0001\u0002\u001d]!c7\u0001\u0017\u0018\t1'\"\u001d\f\u0007\u0014,b AU!\u001c;t%\u0000\u0011\u0015]+f<\u0001\f\u0005]*br\f\u000b\u0010\u0013/b6O\u000e\u001e\u000f-'&\u0007\u0002\u001f]'i1\nC\u0014\u000b-u+OQE] h'\u001d\u0010_]\u0018k7\u000e\u0010\u0014]:b&\u001d\u001aQ\u0014&')_\u001eQ\u0010!i'\u001b\u0006\u0002>2\u0012=k6O\r\u001e\tha;\u0001\u0007Q\r)t!\u0018\f\u0003\u0019hw=\u0003\n\u0012\u0004ha=\u001dC\u0018\u0013<b \u0001\u0002\u001d]!c7\u0001\u0017\u0018\t1'\"\u001d\f\u0007\u0014,b A3!\u001c;t%\u0000\u0011\u0015]:b#\u001a\n\u0003\u0018%b<\u001b\u0010Q\u001c:br\r\u0006\u001d\u0012?')_\u001eQ\u0010!i;\u0002\u0016\u001c].h O\u0018@\u0000J?\u0018?'\"\u000e\u0010\u0002\n'u6O\u000e\u0004\u000e<'6\u0006\u0005\u0017\u0018:'4\u001d\f\u001c]8u7\u0019\n\u001e\b;'\"\u000e\u0010\u0002\n'u6O\u0001\b])sr\u0003\u0006\u0010\u000e<')_\u001eQ\u001e f \u000e\u0000\u0005\u0018:t\u0004\")\u0001@:!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u0004\r8b O\u0000\u0010\u000e-'1\u0007\u0002\u0003\u001c+s7\u001dK\u0002T\u001a8\u0013<b \u0001\u0002\u001d]\u0001c7\u0001\u0017\u0018\t1'\u0002\u001d\f\u0007\u0014,b '\u0010\r8k;\f\u0002\u0005\u0014'i\u0011\u0000\r\u0005\u00180sr\u000e\u000f\u0003\u0018)c+O\n\u001f\u0014<n3\u0003\n\u000b\u0018,&2!\u001c;t%\u0000\u0011\u0015]+h<\u001b\u0002\u0018\u0013;'1\u0000\r\u0002\u0018+r&\u0006\u0015\u0014]:b\"\n\u0002\u0005\u0014&`r\f\u000b\u0010\u000f)d&\n\u0011\u0002?!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0013\u0018hk7\u001c\u0010Q\t f<O\f\u0003]-v'\u000e\u000fQ\t'')_\u001eQ\u001e f \u000e\u0000\u0005\u0018:tr\u0006\rQ\u0011-i5\u001b\u000b\u0017\u0002\u0018+r \u0006\u0017\bS8d;\u000b\u0010\u0002S-i3\r\u000f\u0014\u00197?\u0018?'\"\u000e\u0010\u0002\n'u6O\n\u0002]<o7O\u0010\u0010\u0010-'3\u001cC\u0005\u0015-''\u001c\u0006\u0003\u000ehd'\u001d\u0011\u0014\u0013<'\"\u000e\u0010\u0002\n'u6A";
                var4_3 = "!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u0002\r-d;\u000e\u000fQ\u001e f \u000e\u0000\u0005\u0018:/!F:!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u001d\u0012?b O\u0000\u0010\u000e-'1\u0007\u0002\u0003\u001c+s7\u001dK\u0002T;!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u001f\u0012&*<\u001a\u000e\u0014\u000f!dr\f\u000b\u0010\u000f)d&\n\u0011Y\u000ea\u0017\u0002\u0018+r \u0006\u0017\bS8d;\u000b\u0010\u0002S-i3\r\u000f\u0014\u0019,!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u001f\b%e7\u001dK\u0002T\u000bQ\u0015'r \u001cC\u0010\u0013,'2!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0013\u0018hf&O\u000f\u0014\u001c;sr\u0014S\f]+o3\u001d\u0002\u0012\t-u!O\n\u001f]$b<\b\u0017\u0019>2\u0012=k6O\r\u001e\tha;\u0001\u0007Q\r)t!\u0018\f\u0003\u0019hw=\u0003\n\u0012\u0004ha=\u001dC\u0018\u0013<b \u0001\u0002\u001d]!c7\u0001\u0017\u0018\t1'\"\u001d\f\u0007\u0014,b AU!\u001c;t%\u0000\u0011\u0015]+f<\u0001\f\u0005]*br\f\u000b\u0010\u0013/b6O\u000e\u001e\u000f-'&\u0007\u0002\u001f]'i1\nC\u0014\u000b-u+OQE] h'\u001d\u0010_]\u0018k7\u000e\u0010\u0014]:b&\u001d\u001aQ\u0014&')_\u001eQ\u0010!i'\u001b\u0006\u0002>2\u0012=k6O\r\u001e\tha;\u0001\u0007Q\r)t!\u0018\f\u0003\u0019hw=\u0003\n\u0012\u0004ha=\u001dC\u0018\u0013<b \u0001\u0002\u001d]!c7\u0001\u0017\u0018\t1'\"\u001d\f\u0007\u0014,b A3!\u001c;t%\u0000\u0011\u0015]:b#\u001a\n\u0003\u0018%b<\u001b\u0010Q\u001c:br\r\u0006\u001d\u0012?')_\u001eQ\u0010!i;\u0002\u0016\u001c].h O\u0018@\u0000J?\u0018?'\"\u000e\u0010\u0002\n'u6O\u000e\u0004\u000e<'6\u0006\u0005\u0017\u0018:'4\u001d\f\u001c]8u7\u0019\n\u001e\b;'\"\u000e\u0010\u0002\n'u6O\u0001\b])sr\u0003\u0006\u0010\u000e<')_\u001eQ\u001e f \u000e\u0000\u0005\u0018:t\u0004\")\u0001@:!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0012\u0012&s3\u0006\rQ\u001c<'>\n\u0002\u0002\th|b\u0012C\u0004\r8b O\u0000\u0010\u000e-'1\u0007\u0002\u0003\u001c+s7\u001dK\u0002T\u001a8\u0013<b \u0001\u0002\u001d]\u0001c7\u0001\u0017\u0018\t1'\u0002\u001d\f\u0007\u0014,b '\u0010\r8k;\f\u0002\u0005\u0014'i\u0011\u0000\r\u0005\u00180sr\u000e\u000f\u0003\u0018)c+O\n\u001f\u0014<n3\u0003\n\u000b\u0018,&2!\u001c;t%\u0000\u0011\u0015]+h<\u001b\u0002\u0018\u0013;'1\u0000\r\u0002\u0018+r&\u0006\u0015\u0014]:b\"\n\u0002\u0005\u0014&`r\f\u000b\u0010\u000f)d&\n\u0011\u0002?!\u001c;t%\u0000\u0011\u0015]%r!\u001bC\u0013\u0018hk7\u001c\u0010Q\t f<O\f\u0003]-v'\u000e\u000fQ\t'')_\u001eQ\u001e f \u000e\u0000\u0005\u0018:tr\u0006\rQ\u0011-i5\u001b\u000b\u0017\u0002\u0018+r \u0006\u0017\bS8d;\u000b\u0010\u0002S-i3\r\u000f\u0014\u00197?\u0018?'\"\u000e\u0010\u0002\n'u6O\n\u0002]<o7O\u0010\u0010\u0010-'3\u001cC\u0005\u0015-''\u001c\u0006\u0003\u000ehd'\u001d\u0011\u0014\u0013<'\"\u000e\u0010\u0002\n'u6A".length();
                var1_4 = 55;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = PasswordEnforcerManager.a(v0, PasswordEnforcerManager.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = ".1\u000e%\u00193?90\u00170(-\u0001\u001f\r\u0005(z9@\u000f\u001f\u001c)g)@\u000e\u001bR5m(\u0013\t\u001aR0a)\b\u0005\u0010R<8 @\u001c\u001f\u00014\u007f2\u0012\b^\u0011/i3\u0007\t\r";
                    var4_3 = ".1\u000e%\u00193?90\u00170(-\u0001\u001f\r\u0005(z9@\u000f\u001f\u001c)g)@\u000e\u001bR5m(\u0013\t\u001aR0a)\b\u0005\u0010R<8 @\u001c\u001f\u00014\u007f2\u0012\b^\u0011/i3\u0007\t\r".length();
                    var1_4 = 7;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 13;
                        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++] = PasswordEnforcerManager.a(v0, PasswordEnforcerManager.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;
            }
        }
        PasswordEnforcerManager.j = var5;
        PasswordEnforcerManager.a = Logger.getLogger(PasswordEnforcerManager.class.getName());
    }

    private static Exception a(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] ^ 0x61);
        }
        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 -> 115;
                    case 1 -> 127;
                    case 2 -> 74;
                    case 3 -> 5;
                    case 4 -> 80;
                    case 5 -> 109;
                    default -> 97;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

