/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.identity.Group
 *  com.l7tech.identity.User
 *  com.l7tech.security.token.SecurityToken
 */
package com.l7tech.server.identity;

import com.l7tech.identity.Group;
import com.l7tech.identity.User;
import com.l7tech.security.token.SecurityToken;
import com.l7tech.server.identity.c;
import com.l7tech.server.identity.e;
import com.l7tech.server.identity.f;
import com.l7tech.server.identity.g;
import java.security.cert.X509Certificate;

public final class AuthenticationResult {
    private final g a;
    private final User b;
    private final long c;
    private final boolean d;
    private final X509Certificate e;
    private final SecurityToken[] f;
    private static final String[] g;

    public AuthenticationResult(User user, SecurityToken securityToken, X509Certificate x509Certificate, boolean bl2) {
        this(user, new SecurityToken[]{securityToken}, x509Certificate, bl2);
    }

    public AuthenticationResult(User user, SecurityToken[] securityTokenArray, X509Certificate x509Certificate, boolean bl2) {
        this(user, securityTokenArray, x509Certificate, bl2, System.currentTimeMillis(), AuthenticationResult.b());
    }

    public AuthenticationResult(User user, SecurityToken[] securityTokenArray) {
        this(user, securityTokenArray, null, false);
    }

    public AuthenticationResult(User user, SecurityToken securityToken) {
        this(user, securityToken, null, false);
    }

    public User getUser() {
        return this.b;
    }

    public boolean isCertSignedByStaleCA() {
        return this.d;
    }

    public X509Certificate getAuthenticatedCert() {
        return this.e;
    }

    public boolean matchesSecurityToken(SecurityToken securityToken) {
        boolean bl2 = false;
        if (securityToken != null) {
            for (SecurityToken securityToken2 : this.f) {
                if (securityToken != securityToken2) continue;
                bl2 = true;
                break;
            }
        }
        return bl2;
    }

    public boolean equals(Object object) {
        block23: {
            block22: {
                try {
                    if (this == object) {
                        return true;
                    }
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw AuthenticationResult.a(illegalArgumentException);
                }
                try {
                    try {
                        if (object != null && this.getClass() == object.getClass()) break block22;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw AuthenticationResult.a(illegalArgumentException);
                    }
                    return false;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw AuthenticationResult.a(illegalArgumentException);
                }
            }
            try {
                if (!(object instanceof AuthenticationResult)) {
                    return false;
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw AuthenticationResult.a(illegalArgumentException);
            }
            AuthenticationResult authenticationResult = (AuthenticationResult)object;
            try {
                if (!authenticationResult.getUser().equals((Object)this.b)) {
                    return false;
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw AuthenticationResult.a(illegalArgumentException);
            }
            try {
                if (authenticationResult.isCertSignedByStaleCA() != this.d) {
                    return false;
                }
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw AuthenticationResult.a(illegalArgumentException);
            }
            X509Certificate x509Certificate = authenticationResult.getAuthenticatedCert();
            try {
                block24: {
                    try {
                        try {
                            if (x509Certificate == this.e) break block23;
                            if (x509Certificate == null) break block24;
                        }
                        catch (IllegalArgumentException illegalArgumentException) {
                            throw AuthenticationResult.a(illegalArgumentException);
                        }
                        if (x509Certificate.equals(this.e)) break block23;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw AuthenticationResult.a(illegalArgumentException);
                    }
                }
                return false;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw AuthenticationResult.a(illegalArgumentException);
            }
        }
        return true;
    }

    public int hashCode() {
        int n2;
        int n3;
        int n4;
        int n5;
        int n6 = this.b.hashCode();
        try {
            n5 = 31 * n6;
            n4 = this.d ? 1 : 0;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw AuthenticationResult.a(illegalArgumentException);
        }
        n6 = n5 + n4;
        try {
            n3 = 31 * n6;
            n2 = this.e != null ? this.e.hashCode() : 0;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw AuthenticationResult.a(illegalArgumentException);
        }
        n6 = n3 + n2;
        return n6;
    }

    public void setCachedGroupMembership(Group group, boolean bl2) {
        long l2;
        long l3;
        e e10;
        g g2;
        try {
            g2 = this.a;
            e10 = new e(this.b.getProviderId(), this.b.getId(), group.getProviderId(), group.getId());
            l3 = System.currentTimeMillis();
            l2 = bl2 ? 1L : -1L;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw AuthenticationResult.a(illegalArgumentException);
        }
        g2.put(e10, l3 * l2);
    }

    public Boolean getCachedGroupMembership(Group group) {
        boolean bl2;
        Long l2 = this.a.get(new e(this.b.getProviderId(), this.b.getId(), group.getProviderId(), group.getId()));
        try {
            if (l2 == null) {
                return null;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw AuthenticationResult.a(illegalArgumentException);
        }
        long l3 = l2;
        try {
            bl2 = l3 > 0L;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw AuthenticationResult.a(illegalArgumentException);
        }
        boolean bl3 = bl2;
        l3 = Math.abs(l3);
        try {
            if (l3 < this.c) {
                return null;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw AuthenticationResult.a(illegalArgumentException);
        }
        return bl3;
    }

    long a() {
        return this.c;
    }

    AuthenticationResult(AuthenticationResult authenticationResult, SecurityToken[] securityTokenArray) {
        this(authenticationResult.getUser(), securityTokenArray, authenticationResult.getAuthenticatedCert(), authenticationResult.isCertSignedByStaleCA(), authenticationResult.a(), AuthenticationResult.c());
    }

    private AuthenticationResult(User user, SecurityToken[] securityTokenArray, X509Certificate x509Certificate, boolean bl2, long l2, g g2) {
        block10: {
            block9: {
                if (user == null) {
                    String[] stringArray = g;
                    throw new IllegalArgumentException(stringArray[0]);
                }
                try {
                    try {
                        if (securityTokenArray != null && securityTokenArray.length != 0) break block9;
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw AuthenticationResult.a(illegalArgumentException);
                    }
                    throw new IllegalArgumentException(g[1]);
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw AuthenticationResult.a(illegalArgumentException);
                }
            }
            try {
                try {
                    if (!bl2 || x509Certificate != null) break block10;
                }
                catch (IllegalArgumentException illegalArgumentException) {
                    throw AuthenticationResult.a(illegalArgumentException);
                }
                throw new IllegalArgumentException(g[2]);
            }
            catch (IllegalArgumentException illegalArgumentException) {
                throw AuthenticationResult.a(illegalArgumentException);
            }
        }
        this.b = user;
        this.f = securityTokenArray;
        this.d = bl2;
        this.e = x509Certificate;
        this.c = l2;
        this.a = g2;
    }

    private static g b() {
        return com.l7tech.server.identity.c.a;
    }

    private static g c() {
        return new f();
    }

    private static IllegalArgumentException a(IllegalArgumentException illegalArgumentException) {
        return illegalArgumentException;
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "\u001c.u`nSjI/uc;Sk\f9\u001e\u001a8sg<Sm\u0010}d}%_wA.92/H|I/uc;Sk\f9+$(cfnSw\n1ev+\u001am\u000180a:[u\f}sw<N9\u0000;0f&_k\f}yanUw\f";
        int n3 = "\u001c.u`nSjI/uc;Sk\f9\u001e\u001a8sg<Sm\u0010}d}%_wA.92/H|I/uc;Sk\f9+$(cfnSw\n1ev+\u001am\u000180a:[u\f}sw<N9\u0000;0f&_k\f}yanUw\f".length();
        int n4 = 16;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = AuthenticationResult.a(2, AuthenticationResult.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                g = 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] ^ 0x1B);
        }
        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 -> 107;
                    case 1 -> 95;
                    case 2 -> 18;
                    case 3 -> 16;
                    case 4 -> 76;
                    case 5 -> 56;
                    default -> 27;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

