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

org.powertac.util.ProxyAuthenticator Maven / Gradle / Ivy

The newest version!
package org.powertac.util;

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


public class ProxyAuthenticator extends Authenticator
{
  private String username;
  private String password;

  public ProxyAuthenticator (boolean useSocks)
  {
    String proxyHost;
    String proxyPort;
    if (useSocks) {
      proxyHost = System.getProperty("socksProxyHost", "");
      proxyPort = System.getProperty("socksProxyPort", "");
      username = System.getProperty("java.net.socks.username", "");
      password = System.getProperty("java.net.socks.password", "");
    }
    else {
      proxyHost = System.getProperty("http.proxyHost", "");
      proxyPort = System.getProperty("http.proxyPort", "");
      username = System.getProperty("http.proxyUser", "");
      password = System.getProperty("http.proxyPassword", "");
    }

    if (!proxyHost.isEmpty()) {
      System.out.printf("\nConnecting via proxy %s:%s\n", proxyHost, proxyPort);
    }
    if (!username.isEmpty()) {
      System.out.printf("Username : %s\n\n", username);
      Authenticator.setDefault(this);
    }
  }

  public PasswordAuthentication getPasswordAuthentication ()
  {
    return new PasswordAuthentication(username, password.toCharArray());
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy