Created
October 24, 2016 13:18
-
-
Save equinoxel/51772d3acc3ba42f47a8805ab708ae97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.play.util; | |
import static java.lang.System.getProperty; | |
import static java.lang.System.setProperty; | |
import static java.util.logging.Level.SEVERE; | |
import static java.util.logging.Logger.getLogger; | |
import java.net.Authenticator; | |
import java.net.InetAddress; | |
import java.net.PasswordAuthentication; | |
import java.net.UnknownHostException; | |
/** | |
* Call <code>#authenticate()</code>once per app life cycle… | |
* | |
* @author Octavian Theodor NITA ([email protected]) | |
* @version 1.0, Sep 12, 2013 | |
*/ | |
public class ProxyUtils { | |
public static void authenticate() { | |
// A sort of whitelist | |
try { | |
if (!InetAddress.getLocalHost().toString().toLowerCase().contains("whitelisted")) { | |
return; | |
} | |
} catch (UnknownHostException e) { | |
getLogger(ProxyUtils.class.getName()).log(SEVERE, null, e); | |
return; | |
} | |
// Set system properties | |
setProperty("http.proxyHost", "192.168.0.110"); | |
setProperty("http.proxyPort", "88"); | |
setProperty("http.proxyUser", "user"); | |
setProperty("http.proxyPassword", "pass"); | |
setProperty("https.proxyHost", getProperty("http.proxyHost")); | |
setProperty("https.proxyPort", getProperty("http.proxyPort")); | |
setProperty("https.proxyUser", getProperty("http.proxyUser")); | |
setProperty("https.proxyPassword", getProperty("http.proxyPassword")); | |
// Set the authenticator | |
Authenticator.setDefault(new Authenticator() { | |
@Override | |
protected PasswordAuthentication getPasswordAuthentication() { | |
return new PasswordAuthentication("user", "pass".toCharArray()); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment