/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.gateway.common.resources.HttpConfiguration
 *  com.l7tech.gateway.common.resources.HttpProxyConfiguration
 */
package com.l7tech.server.globalresources;

import com.l7tech.gateway.common.resources.HttpConfiguration;
import com.l7tech.gateway.common.resources.HttpProxyConfiguration;
import com.l7tech.server.globalresources.i;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;

final class s
extends Authenticator {
    private final AtomicReference<i> a;

    private s(AtomicReference<i> atomicReference) {
        this.a = atomicReference;
    }

    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        PasswordAuthentication passwordAuthentication = null;
        i i2 = this.a.get();
        Authenticator.RequestorType requestorType = this.getRequestorType();
        URL uRL = this.getRequestingURL();
        String string = this.getRequestingHost();
        int n2 = this.getRequestingPort();
        if (i2 != null) {
            if (Authenticator.RequestorType.PROXY == requestorType) {
                HttpProxyConfiguration httpProxyConfiguration = null;
                if (uRL != null) {
                    httpProxyConfiguration = i2.getHttpProxyConfiguration(uRL);
                } else if (string != null) {
                    httpProxyConfiguration = i2.getHttpProxyConfiguration(null, string, n2, null);
                }
                if (httpProxyConfiguration != null && httpProxyConfiguration.getUsername() != null && httpProxyConfiguration.getPasswordGoid() != null) {
                    passwordAuthentication = new PasswordAuthentication(httpProxyConfiguration.getUsername(), i2.getPassword(httpProxyConfiguration.getPasswordGoid()));
                }
            } else if (Authenticator.RequestorType.SERVER == requestorType) {
                HttpConfiguration httpConfiguration = null;
                if (uRL != null) {
                    httpConfiguration = i2.getHttpConfiguration(uRL);
                } else if (string != null) {
                    httpConfiguration = i2.getHttpConfiguration(null, string, n2, null);
                }
                if (httpConfiguration != null && httpConfiguration.getUsername() != null) {
                    Object object = httpConfiguration.getUsername();
                    if (httpConfiguration.getNtlmDomain() != null) {
                        object = httpConfiguration.getNtlmDomain() + "\\" + (String)object;
                    }
                    passwordAuthentication = new PasswordAuthentication((String)object, i2.getPassword(httpConfiguration.getPasswordGoid()));
                }
            }
        }
        return passwordAuthentication;
    }
}

