/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.protocol.SecureSpanConstants
 *  com.l7tech.common.protocol.SecureSpanConstants$HttpHeaders
 *  com.l7tech.identity.AuthenticationException
 *  com.l7tech.identity.IdentityProvider
 *  com.l7tech.identity.InvalidClientCertificateException
 *  com.l7tech.identity.User
 *  com.l7tech.objectmodel.FindException
 *  com.l7tech.policy.assertion.credential.LoginCredentials
 */
package com.l7tech.server;

import com.l7tech.common.protocol.SecureSpanConstants;
import com.l7tech.identity.AuthenticationException;
import com.l7tech.identity.IdentityProvider;
import com.l7tech.identity.InvalidClientCertificateException;
import com.l7tech.identity.User;
import com.l7tech.objectmodel.FindException;
import com.l7tech.policy.assertion.credential.LoginCredentials;
import com.l7tech.server.TokenService;
import com.l7tech.server.TokenServiceServlet;
import com.l7tech.server.identity.AuthCache;
import com.l7tech.server.identity.AuthenticationResult;
import com.l7tech.server.identity.IdentityProviderFactory;
import com.l7tech.server.message.PolicyEnforcementContext;
import java.util.Collection;
import java.util.logging.Level;

class a_
implements TokenService.CredentialsAuthenticator {
    final PolicyEnforcementContext val$context;
    final TokenServiceServlet this$0;
    private static final String[] a;

    /*
     * Ignored method signature, as it can't be verified against descriptor
     */
    a_(TokenServiceServlet tokenServiceServlet, PolicyEnforcementContext policyEnforcementContext) {
        this.this$0 = tokenServiceServlet;
        this.val$context = policyEnforcementContext;
    }

    /*
     * Loose catch block
     */
    @Override
    public User authenticate(LoginCredentials loginCredentials) {
        User user;
        block16: {
            block15: {
                user = null;
                boolean bl2 = false;
                try {
                    String[] stringArray = a;
                    IdentityProviderFactory identityProviderFactory = (IdentityProviderFactory)this.this$0.applicationContext.getBean(stringArray[0]);
                    Collection<IdentityProvider> collection = identityProviderFactory.findAllIdentityProviders();
                    for (IdentityProvider identityProvider : collection) {
                        try {
                            AuthenticationResult authenticationResult;
                            block14: {
                                authenticationResult = AuthCache.getInstance().getCachedAuthResult(loginCredentials, identityProvider);
                                if (authenticationResult == null) continue;
                                try {
                                    block17: {
                                        if (user == null) break block14;
                                        break block17;
                                        catch (InvalidClientCertificateException invalidClientCertificateException) {
                                            throw a_.a(invalidClientCertificateException);
                                        }
                                    }
                                    throw new AuthenticationException(a[1]);
                                }
                                catch (InvalidClientCertificateException invalidClientCertificateException) {
                                    throw a_.a(invalidClientCertificateException);
                                }
                            }
                            user = authenticationResult.getUser();
                        }
                        catch (InvalidClientCertificateException invalidClientCertificateException) {
                            bl2 = true;
                            stringArray = a;
                            this.this$0.logger.log(Level.INFO, stringArray[6], new String[]{invalidClientCertificateException.getMessage(), identityProvider.getConfig().getName()});
                        }
                        catch (AuthenticationException authenticationException) {
                            stringArray = a;
                            this.this$0.logger.log(Level.INFO, stringArray[2], new String[]{authenticationException.getMessage(), identityProvider.getConfig().getName()});
                        }
                    }
                }
                catch (FindException findException) {
                    String[] stringArray = a;
                    this.this$0.logger.log(Level.WARNING, stringArray[4], findException);
                    return null;
                }
                try {
                    try {
                        if (user != null) break block15;
                        this.this$0.logger.fine(a[3]);
                        if (!bl2) break block16;
                    }
                    catch (InvalidClientCertificateException invalidClientCertificateException) {
                        throw a_.a(invalidClientCertificateException);
                    }
                    this.val$context.getResponse().getHeadersKnob().addHeader(SecureSpanConstants.HttpHeaders.CERT_STATUS, (Object)SecureSpanConstants.CERT_INVALID, a[5]);
                    break block16;
                }
                catch (InvalidClientCertificateException invalidClientCertificateException) {
                    throw a_.a(invalidClientCertificateException);
                }
            }
            this.this$0.logger.finer(a[7] + String.valueOf(user));
        }
        return user;
    }

    private static InvalidClientCertificateException a(InvalidClientCertificateException invalidClientCertificateException) {
        return invalidClientCertificateException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "\u0018)=>7*\"\b\u001d*?5*2\u0014?\u001e1 79\u00034\u0091%%=p &$\u0005m-#&'v\u0005\"x#*$8Q9090c$\u0014<-507v\u0018>x&\"/?\u0015m7>c.9\u0003(x$+\"8Q\"65c3$\u001e;14&1xQ\u001e=3613Q.7>5&$\u0002,,9,-v\u0012\"6$&;\"\u0002m5%07v\u0013(x1009\u0012$9$&'v\u0004#9=!*1\u0004\"-#/:v\u0005\"x?-&v\u0004>=\"mX08,8&-\"\u0018.9$*,845;537?\u001e#x$1:?\u001f*x$,c7\u0004905-7?\u0012,,5c $\u0014)=>7*7\u001d>xwd8f\fj\u007f|c,8Q=*?5*2\u0014?xwd8g\fj\u007f~62?=4&-\"\u0018,4#c'?\u0015m6?7c7\u0004905-7?\u0012,,5c\"1\u0010$6#7c7\u001f4x 1, \u0018)=\"m&\u0012\"-<'c8\u001e9x7&7v\u0018)x 1, \u0018)=\"c%$\u001e x6\" \"\u001e?!\u000b9\u0019\f\u0000c\u000b3\u0010)=\"";
                var4_3 = "\u0018)=>7*\"\b\u001d*?5*2\u0014?\u001e1 79\u00034\u0091%%=p &$\u0005m-#&'v\u0005\"x#*$8Q9090c$\u0014<-507v\u0018>x&\"/?\u0015m7>c.9\u0003(x$+\"8Q\"65c3$\u001e;14&1xQ\u001e=3613Q.7>5&$\u0002,,9,-v\u0012\"6$&;\"\u0002m5%07v\u0013(x1009\u0012$9$&'v\u0004#9=!*1\u0004\"-#/:v\u0005\"x?-&v\u0004>=\"mX08,8&-\"\u0018.9$*,845;537?\u001e#x$1:?\u001f*x$,c7\u0004905-7?\u0012,,5c $\u0014)=>7*7\u001d>xwd8f\fj\u007f|c,8Q=*?5*2\u0014?xwd8g\fj\u007f~62?=4&-\"\u0018,4#c'?\u0015m6?7c7\u0004905-7?\u0012,,5c\"1\u0010$6#7c7\u001f4x 1, \u0018)=\"m&\u0012\"-<'c8\u001e9x7&7v\u0018)x 1, \u0018)=\"c%$\u001e x6\" \"\u001e?!\u000b9\u0019\f\u0000c\u000b3\u0010)=\"".length();
                var1_4 = 23;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = a_.a(v0, a_.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "D_RMSVN-RHEZQ^-RA^KVLdREXZzRnTTXVPD-EVUVQM-EK\f^J^eTJXV\\KyT\u0004OMZNh_PE^SY-\u0016\u0003W\u000fB\r*\u001d\u0004CQ\u001fZ\u007f^RE[ZX-\u0016\u0003W\u000eB\r*\u001f\u000flDPDZQ^dREXZ[\u0010-";
                    var4_3 = "D_RMSVN-RHEZQ^-RA^KVLdREXZzRnTTXVPD-EVUVQM-EK\f^J^eTJXV\\KyT\u0004OMZNh_PE^SY-\u0016\u0003W\u000fB\r*\u001d\u0004CQ\u001fZ\u007f^RE[ZX-\u0016\u0003W\u000eB\r*\u001f\u000flDPDZQ^dREXZ[\u0010-".length();
                    var1_4 = 100;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 106;
                        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++] = a_.a(v0, a_.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;
            }
        }
        a_.a = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x40);
        }
        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 -> 103;
                    case 1 -> 91;
                    case 2 -> 78;
                    case 3 -> 70;
                    case 4 -> 85;
                    case 5 -> 85;
                    default -> 64;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

