/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.audit.AssertionMessages
 *  com.l7tech.gateway.common.audit.AuditDetailMessage
 *  com.l7tech.identity.User
 *  com.l7tech.message.Message
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.PolicyAssertionException
 *  com.l7tech.policy.assertion.xmlsec.LookupOutboundSecureConversationSession
 *  org.springframework.beans.factory.BeanFactory
 */
package com.l7tech.server.policy.assertion.xmlsec;

import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.identity.User;
import com.l7tech.message.Message;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.PolicyAssertionException;
import com.l7tech.policy.assertion.xmlsec.LookupOutboundSecureConversationSession;
import com.l7tech.server.message.AuthenticationContext;
import com.l7tech.server.message.PolicyEnforcementContext;
import com.l7tech.server.policy.assertion.AbstractMessageTargetableServerAssertion;
import com.l7tech.server.policy.variable.ExpandVariables;
import com.l7tech.server.secureconversation.OutboundSecureConversationContextManager;
import com.l7tech.server.secureconversation.SecureConversationSession;
import java.io.IOException;
import org.springframework.beans.factory.BeanFactory;

public class ServerLookupOutboundSecureConversationSession
extends AbstractMessageTargetableServerAssertion<LookupOutboundSecureConversationSession> {
    private final String[] d;
    private final OutboundSecureConversationContextManager e;
    private static final String[] f;

    public ServerLookupOutboundSecureConversationSession(LookupOutboundSecureConversationSession lookupOutboundSecureConversationSession, BeanFactory beanFactory) {
        super(lookupOutboundSecureConversationSession);
        this.d = lookupOutboundSecureConversationSession.getVariablesUsed();
        this.e = (OutboundSecureConversationContextManager)beanFactory.getBean(f[1], OutboundSecureConversationContextManager.class);
    }

    @Override
    protected AssertionStatus doCheckRequest(PolicyEnforcementContext policyEnforcementContext, Message message, String string, AuthenticationContext authenticationContext) throws IOException, PolicyAssertionException {
        SecureConversationSession secureConversationSession;
        User user = authenticationContext.getLastAuthenticatedUser();
        try {
            if (user == null) {
                this.logAndAudit((AuditDetailMessage)AssertionMessages.OUTBOUND_SECURE_CONVERSATION_LOOKUP_FAILURE, f[0]);
                return AssertionStatus.FALSIFIED;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ServerLookupOutboundSecureConversationSession.b(illegalArgumentException);
        }
        String string2 = ExpandVariables.process(((LookupOutboundSecureConversationSession)this.assertion).getServiceUrl(), policyEnforcementContext.getVariableMap(this.d, this.getAudit()), this.getAudit());
        try {
            secureConversationSession = this.e.getSession(OutboundSecureConversationContextManager.newSessionKey(user, string2));
        }
        catch (IllegalArgumentException illegalArgumentException) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.OUTBOUND_SECURE_CONVERSATION_LOOKUP_FAILURE, illegalArgumentException.getMessage());
            return AssertionStatus.FALSIFIED;
        }
        try {
            if (secureConversationSession == null) {
                String[] stringArray = new String[1];
                stringArray[0] = f[2] + user.getId() + f[3] + string2 + f[4];
                this.logAndAudit((AuditDetailMessage)AssertionMessages.OUTBOUND_SECURE_CONVERSATION_LOOKUP_FAILURE, stringArray);
                return AssertionStatus.FALSIFIED;
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw ServerLookupOutboundSecureConversationSession.b(illegalArgumentException);
        }
        StringBuilder stringBuilder = new StringBuilder(((LookupOutboundSecureConversationSession)this.assertion).getVariablePrefix()).append(".").append(LookupOutboundSecureConversationSession.VARIABLE_SESSION);
        policyEnforcementContext.setVariable(stringBuilder.toString(), secureConversationSession);
        return AssertionStatus.NONE;
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[5];
                var3_1 = 0;
                var2_2 = "=U\u001d\u00119i\u000b\u000eX\f\u0011 m\n\u001a\\\u001fTml\u0016\fNX_\"|Y\nR\u0016E,a\u0017I\\\u0016\u0011,}\r\u0001X\u0016E$k\u0018\u001dX\u001c\u00118{\u001c\u001b\u0013(\u0006H\fS\"}\u0017\rn\u001dR8z\u001c*R\u0016G(z\n\bI\u0011^#K\u0016\u0007I\u001dI9E\u0018\u0007\\\u001fT?\u001b=U\u001d\u0011>m\n\u001aT\u0017_m \u000e\u0000I\u0010\u0011\u0018{\u001c\u001b\u001d1uw(";
                var4_3 = "=U\u001d\u00119i\u000b\u000eX\f\u0011 m\n\u001a\\\u001fTml\u0016\fNX_\"|Y\nR\u0016E,a\u0017I\\\u0016\u0011,}\r\u0001X\u0016E$k\u0018\u001dX\u001c\u00118{\u001c\u001b\u0013(\u0006H\fS\"}\u0017\rn\u001dR8z\u001c*R\u0016G(z\n\bI\u0011^#K\u0016\u0007I\u001dI9E\u0018\u0007\\\u001fT?\u001b=U\u001d\u0011>m\n\u001aT\u0017_m \u000e\u0000I\u0010\u0011\u0018{\u001c\u001b\u001d1uw(".length();
                var1_4 = 58;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = ServerLookupOutboundSecureConversationSession.c(v0, ServerLookupOutboundSecureConversationSession.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "MX\u0012Qi_\u0018\u001fO\u0015V,,(?uF\u0015!D\u0019\u0015Fii\u0014\u0019Q\u0019Gii\u0005\u001dP\u000eP-,\u0012\u001f\u0019\u0012Z=,\u001b\u0002L\u0012Qg";
                    var4_3 = "MX\u0012Qi_\u0018\u001fO\u0015V,,(?uF\u0015!D\u0019\u0015Fii\u0014\u0019Q\u0019Gii\u0005\u001dP\u000eP-,\u0012\u001f\u0019\u0012Z=,\u001b\u0002L\u0012Qg".length();
                    var1_4 = 18;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 61;
                        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++] = ServerLookupOutboundSecureConversationSession.c(v0, ServerLookupOutboundSecureConversationSession.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;
            }
        }
        ServerLookupOutboundSecureConversationSession.f = 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 c(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 -> 4;
                    case 2 -> 65;
                    case 3 -> 8;
                    case 4 -> 116;
                    case 5 -> 49;
                    default -> 64;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

