/*
 * 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.objectmodel.Goid
 *  com.l7tech.policy.assertion.AssertionStatus
 *  com.l7tech.policy.assertion.identity.SpecificUser
 *  org.springframework.context.ApplicationContext
 */
package com.l7tech.server.policy.assertion.identity;

import com.l7tech.gateway.common.audit.AssertionMessages;
import com.l7tech.gateway.common.audit.AuditDetailMessage;
import com.l7tech.identity.User;
import com.l7tech.objectmodel.Goid;
import com.l7tech.policy.assertion.AssertionStatus;
import com.l7tech.policy.assertion.identity.SpecificUser;
import com.l7tech.server.identity.AuthenticationResult;
import com.l7tech.server.policy.assertion.identity.ServerIdentityAssertion;
import org.springframework.context.ApplicationContext;

public class ServerSpecificUser
extends ServerIdentityAssertion<SpecificUser> {
    protected SpecificUser specificUser;
    private final String e;
    private final String f;
    private final Goid g;
    private static final String i = ServerSpecificUser.d(59, ServerSpecificUser.b("[\u000eS\u0000@\u0010Bc\fD\u0006[CWc\u0003"));

    public ServerSpecificUser(SpecificUser specificUser, ApplicationContext applicationContext) {
        super(specificUser, applicationContext);
        this.e = specificUser.getUserLogin();
        this.f = specificUser.getUserUid();
        this.g = specificUser.getIdentityProviderOid();
    }

    @Override
    public AssertionStatus checkUser(AuthenticationResult authenticationResult) {
        if (this.e == null && this.f == null) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.SPECIFICUSER_NOLOGIN_NOOID);
            return AssertionStatus.SERVER_ERROR;
        }
        User user = authenticationResult.getUser();
        Goid goid = user.getProviderId();
        String string = user.getLogin();
        if (!goid.equals((Object)this.g)) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.SPECIFICUSER_PROVIDER_MISMATCH, Goid.toString((Goid)goid), Goid.toString((Goid)this.g));
            return AssertionStatus.AUTH_FAILED;
        }
        if (this.f != null && !"".equals(this.f) && !user.isEquivalentId((Object)this.f)) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.SPECIFICUSER_USERID_MISMATCH);
            return AssertionStatus.AUTH_FAILED;
        }
        if (this.e != null && !"".equals(this.e) && !this.e.equals(string)) {
            this.logAndAudit((AuditDetailMessage)AssertionMessages.SPECIFICUSER_LOGIN_MISMATCH);
            return AssertionStatus.AUTH_FAILED;
        }
        this.logger.fine(i);
        return AssertionStatus.NONE;
    }

    private static char[] b(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0xA);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String d(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 -> 45;
                    case 1 -> 84;
                    case 2 -> 28;
                    case 3 -> 88;
                    case 4 -> 19;
                    case 5 -> 11;
                    default -> 10;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

