From 1e641c99ff2371d4ddd3a49a1efd5e210683b4ac Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Wed, 12 Nov 2014 14:03:25 +0100 Subject: Changed condition for using proxy with authentication. --- src/main/java/org/openslx/satellitedaemon/App.java | 67 ++++++++++------------ 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index e43c9a1..3fe143a 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -105,68 +105,61 @@ public class App + " [--genid ] or\n" + " [--import ] or\n" + " [--submitkey ] or\n" - + " [--updateaddress ]"); + + " [--updateaddress ]" ); System.exit( 2 ); } } else if ( args.length == 0 ) { // No Option choosed, try to load existing identity. - + if ( !tryLoadIdentity() ) { System.exit( 2 ); } } - + if ( !Globals.masterServerSslContextInit() ) { log.error( "Problem with initializing the SSLContext" ); System.exit( 1 ); } - + log.info( "Configure proxy settings ..." ); // Configuring proxy settings. First read options from config file. String proxyConfiguration = Globals.getProxyConf(); - if ((proxyConfiguration.equals( "AUTO")) || (proxyConfiguration.equals( "" ))) { + if ( ( proxyConfiguration.equals( "AUTO" ) ) || ( proxyConfiguration.equals( "" ) ) ) { log.info( "Configuring proxy settings automatically..." ); // Configuring proxy settings automatically. - WpadProxySearchStrategy wPSS = new WpadProxySearchStrategy(); + WpadProxySearchStrategy wPSS = new WpadProxySearchStrategy(); try { ProxySelector pS = wPSS.getProxySelector(); - ProxySelector.setDefault(pS); - } catch (ProxyException e) { + ProxySelector.setDefault( pS ); + } catch ( ProxyException e ) { log.error( "Setting proxy configuration automatically failed.", e ); } - } else if (proxyConfiguration.equals( "YES" )) { + } 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 (Globals.checkProxySettings()) { - String proxyAddress = Globals.getProxyAddress(); - int proxyPort = Globals.getProxyPort(); - if (Globals.getProxyUsername().equals( "" ) || Globals.getProxyPassword().equals("")) { - log.info( "Configuring proxy settings manually without authentication..." ); - // use Proxy without authentication. - Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) ); - - StaticProxySelector sPS = new StaticProxySelector(proxy); - ProxySelector.setDefault( sPS ); - } else { - log.info( "Configuring proxy settings manually with authentication..." ); - // Use proxy with authentication. - String proxyUname = Globals.getProxyUsername(); - String proxyPass = Globals.getProxyPassword(); - - Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) ); - - StaticProxySelector sPS = new StaticProxySelector( proxy ); - ProxySelector.setDefault( sPS ); - - // Set authentication. - StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass ); - Authenticator.setDefault( sPA ); - } - } - } + if ( Globals.checkProxySettings() ) { + String proxyAddress = Globals.getProxyAddress(); + int proxyPort = Globals.getProxyPort(); + + // Configure proxy. + Proxy proxy = new Proxy( Proxy.Type.SOCKS, new InetSocketAddress( proxyAddress, proxyPort ) ); + StaticProxySelector sPS = new StaticProxySelector( proxy ); + ProxySelector.setDefault( sPS ); + + if ( ! ( Globals.getProxyUsername().equals( "" ) ) && ! ( Globals.getProxyPassword().equals( "" ) ) ) { + log.info( "Configuring proxy settings manually WITH authentication..." ); + // use Proxy with authentication. + String proxyUname = Globals.getProxyUsername(); + String proxyPass = Globals.getProxyPassword(); + + // Set authentication. + StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass ); + Authenticator.setDefault( sPA ); + } + } + } log.info( "... proxy settings are done." ); - // Start Up- and Download. Thread uploadWorker = new Thread( new FileUploadWorker() ); uploadWorker.start(); -- cgit v1.2.3-55-g7522