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

com.sumologic.log4j.http.ProxySettings Maven / Gradle / Ivy

There is a newer version: 2.12
Show newest version
package com.sumologic.log4j.http;


public class ProxySettings {

    public static final String NTLM_AUTH = "ntlm";
    public static final String BASIC_AUTH = "basic";

    private String hostname = null;
    private int port = -1;
    private String authType = null;
    private String username = null;
    private String password = null;
    private String domain = null;


    public ProxySettings(String hostname, int port, String authType, String username, String password, String domain) {
        this.hostname = hostname;
        this.port = port;
        this.authType = authType;
        this.username = username;
        this.password = password;
        this.domain = domain;

        normalize();
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
        normalize();
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
        normalize();
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
        normalize();
    }

    public String getAuthType() {
        return authType;
    }

    public void setAuthType(String authType) {
        this.authType = authType;
        normalize();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
        normalize();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
        normalize();
    }

    private void normalize() {
        // Default to Basic Auth when credentials are specified without an auth type
        if (username != null && authType == null)
            this.authType = BASIC_AUTH;
    }

    public void validate() {
        if (hostname != null) {
            if (port == -1)
                throw new IllegalArgumentException("port property must be set");

            if (authType != null && (username == null || password == null))
                throw new IllegalArgumentException("username and password properties must be set if authType property is set");

            if (NTLM_AUTH.equals(authType) && domain == null)
                throw new IllegalArgumentException("domain property must be set if authType property is ntlm");

            if (authType != null && ! (NTLM_AUTH.equals(authType) || BASIC_AUTH.equals(authType)))
                throw new IllegalArgumentException("authType type not supported: " + authType);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy