diff options
| author | Simon Rettberg | 2014-11-13 13:47:24 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2014-11-13 13:47:24 +0100 |
| commit | 7a5ce393bd4db00ad930e0559e05f504661c0c05 (patch) | |
| tree | 5597924190d6da7da5464e3f539d72a77b0ce51f /src/main/java/org/openslx/network/ProxyConfiguration.java | |
| parent | Add DataReceived callback to Downloader (diff) | |
| parent | Example file for proxy config file. Proxy config file MUST be stored as "/opt... (diff) | |
| download | master-sync-shared-7a5ce393bd4db00ad930e0559e05f504661c0c05.tar.gz master-sync-shared-7a5ce393bd4db00ad930e0559e05f504661c0c05.tar.xz master-sync-shared-7a5ce393bd4db00ad930e0559e05f504661c0c05.zip | |
Merge branch 'master' of git.openslx.org:bwlp/master-sync-shared
Diffstat (limited to 'src/main/java/org/openslx/network/ProxyConfiguration.java')
| -rw-r--r-- | src/main/java/org/openslx/network/ProxyConfiguration.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/network/ProxyConfiguration.java b/src/main/java/org/openslx/network/ProxyConfiguration.java new file mode 100644 index 0000000..cfdcdb9 --- /dev/null +++ b/src/main/java/org/openslx/network/ProxyConfiguration.java @@ -0,0 +1,62 @@ +package org.openslx.network; + +import java.net.Authenticator; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.ProxySelector; + +import org.apache.log4j.Logger; + +import com.btr.proxy.search.wpad.WpadProxySearchStrategy; +import com.btr.proxy.util.ProxyException; + +/** + * Class for configuring proxy settings system wide, if necessary. + * + * @author bjoern + * + */ +public class ProxyConfiguration +{ + private static final Logger log = Logger.getLogger( ProxyConfiguration.class ); + + public static void configProxy() + { + // Configuring proxy settings. First read options from config file. + String proxyConfiguration = ProxyProperties.getProxyConf(); + if ( ( proxyConfiguration.equals( "AUTO" ) ) || ( proxyConfiguration.equals( "" ) ) ) { + log.info( "Configuring proxy settings automatically..." ); + // Configuring proxy settings automatically. + WpadProxySearchStrategy wPSS = new WpadProxySearchStrategy(); + try { + ProxySelector pS = wPSS.getProxySelector(); + ProxySelector.setDefault( pS ); + } catch ( ProxyException e ) { + log.error( "Setting proxy configuration automatically failed.", e ); + } + } else if ( proxyConfiguration.equals( "YES" ) ) { + // Take the proxy settings from config file. + // First check if one of the following necessary options might not be set. + if ( ProxyProperties.checkProxySettings() ) { + String proxyAddress = ProxyProperties.getProxyAddress(); + int proxyPort = ProxyProperties.getProxyPort(); + + // Configure proxy. + Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) ); + StaticProxySelector sPS = new StaticProxySelector( proxy ); + ProxySelector.setDefault( sPS ); + + if ( ! ( ProxyProperties.getProxyUsername().equals( "" ) ) && ! ( ProxyProperties.getProxyPassword().equals( "" ) ) ) { + log.info( "Configuring proxy settings manually WITH authentication..." ); + // use Proxy with authentication. + String proxyUname = ProxyProperties.getProxyUsername(); + String proxyPass = ProxyProperties.getProxyPassword(); + + // Set authentication. + StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass ); + Authenticator.setDefault( sPA ); + } + } + } + } +} |
