All Downloads are FREE. Search and download functionalities are using the official Maven repository.

apploader.common.ProxyConfig Maven / Gradle / Ivy

The newest version!
package apploader.common;

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.Proxy;

public final class ProxyConfig {

    public static final ProxyConfig NO_PROXY = new ProxyConfig(Proxy.NO_PROXY, null, null);

    public final Proxy proxy;
    public final String login;
    public final String password;

    public ProxyConfig(Proxy proxy, String login, String password) {
        this.proxy = proxy;
        this.login = login;
        this.password = password;
    }

    public void setLogin() {
        Authenticator a;
        if (login == null || login.trim().isEmpty()) {
            a = null;
        } else {
            a = new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(login, password != null ? password.toCharArray() : new char[0]);
                }
            };
        }
        Authenticator.setDefault(a);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy