summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-11-12 14:59:57 +0100
committerBjörn Hagemeister2014-11-12 14:59:57 +0100
commit677b57ccf33b2c213c833960fb8ec944f81d867f (patch)
tree414f5b8f64e05134e46f55de696fe9b5591fa0fe
parentChanged condition for using proxy with authentication. (diff)
downloadsatellite-daemon-677b57ccf33b2c213c833960fb8ec944f81d867f.tar.gz
satellite-daemon-677b57ccf33b2c213c833960fb8ec944f81d867f.tar.xz
satellite-daemon-677b57ccf33b2c213c833960fb8ec944f81d867f.zip
Moved proxy configuration file to /opt/openslx/proxy/config and adapted classes therefor.
-rw-r--r--src/main/java/org/openslx/satellitedaemon/App.java15
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Globals.java56
-rw-r--r--src/main/java/org/openslx/satellitedaemon/Identity.java2
-rw-r--r--src/main/java/org/openslx/satellitedaemon/db/MySQL.java2
-rw-r--r--src/main/java/org/openslx/satellitedaemon/util/Util.java57
5 files changed, 12 insertions, 120 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java
index 3fe143a..cf99ba0 100644
--- a/src/main/java/org/openslx/satellitedaemon/App.java
+++ b/src/main/java/org/openslx/satellitedaemon/App.java
@@ -11,6 +11,7 @@ import java.security.interfaces.RSAPublicKey;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
+import org.openslx.network.ProxyConfiguration;
import org.openslx.network.StaticProxyAuthenticator;
import org.openslx.network.StaticProxySelector;
import org.openslx.satellitedaemon.filetransfer.FileDownloadWorker;
@@ -123,7 +124,7 @@ public class App
log.info( "Configure proxy settings ..." );
// Configuring proxy settings. First read options from config file.
- String proxyConfiguration = Globals.getProxyConf();
+ String proxyConfiguration = ProxyConfiguration.getProxyConf();
if ( ( proxyConfiguration.equals( "AUTO" ) ) || ( proxyConfiguration.equals( "" ) ) ) {
log.info( "Configuring proxy settings automatically..." );
// Configuring proxy settings automatically.
@@ -137,20 +138,20 @@ public class App
} 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 ( ProxyConfiguration.checkProxySettings() ) {
+ String proxyAddress = ProxyConfiguration.getProxyAddress();
+ int proxyPort = ProxyConfiguration.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( "" ) ) ) {
+ if ( ! ( ProxyConfiguration.getProxyUsername().equals( "" ) ) && ! ( ProxyConfiguration.getProxyPassword().equals( "" ) ) ) {
log.info( "Configuring proxy settings manually WITH authentication..." );
// use Proxy with authentication.
- String proxyUname = Globals.getProxyUsername();
- String proxyPass = Globals.getProxyPassword();
+ String proxyUname = ProxyConfiguration.getProxyUsername();
+ String proxyPass = ProxyConfiguration.getProxyPassword();
// Set authentication.
StaticProxyAuthenticator sPA = new StaticProxyAuthenticator( proxyUname, proxyPass );
diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java
index d75459b..fa39d2d 100644
--- a/src/main/java/org/openslx/satellitedaemon/Globals.java
+++ b/src/main/java/org/openslx/satellitedaemon/Globals.java
@@ -5,13 +5,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
-import java.security.KeyFactory;
-import java.security.KeyManagementException;
import java.security.KeyStore;
-import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.cert.CertificateException;
import java.util.Properties;
import javax.net.ssl.SSLContext;
@@ -19,7 +14,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import org.apache.log4j.Logger;
-import org.openslx.satellitedaemon.util.Util;
+import org.openslx.util.Util;
public class Globals
{
@@ -50,39 +45,14 @@ public class Globals
{
return properties.getProperty( "IMAGE_FOLDER" );
}
-
- public static String getProxyConf()
- {
- return properties.getProperty( "PROXY_CONF" );
- }
-
- public static String getProxyAddress()
- {
- return properties.getProperty( "PROXY_ADDR" );
- }
-
- public static String getProxyUsername()
- {
- return properties.getProperty( "PROXY_USERNAME" );
- }
-
- public static String getProxyPassword()
- {
- return properties.getProperty( "PROXY_PASSWORD" );
- }
// Integers //
public static int getThriftPort()
{
- return tryToParseInt( properties.getProperty( "THRIFT_PORT" ) );
+ return Util.tryToParseInt( properties.getProperty( "THRIFT_PORT" ) );
}
- public static int getProxyPort()
- {
- return tryToParseInt( properties.getProperty( "PROXY_PORT" ) );
- }
-
/**
* Load properties
*/
@@ -149,26 +119,4 @@ public class Globals
{
return context;
}
-
- /**
- * Tries to parse an int. Returns 0 on error.
- *
- * @param s
- * The string to parse
- * @return The parsed int or 0 on error
- */
- public static int tryToParseInt( String s )
- {
- try {
- return Integer.parseInt( s );
- } catch ( NumberFormatException e ) {
- return 0;
- }
- }
-
- public static boolean checkProxySettings() {
- return (
- (getProxyAddress() != "") &&
- (getProxyPort() != 0));
- }
}
diff --git a/src/main/java/org/openslx/satellitedaemon/Identity.java b/src/main/java/org/openslx/satellitedaemon/Identity.java
index 947d90a..6ddbfb3 100644
--- a/src/main/java/org/openslx/satellitedaemon/Identity.java
+++ b/src/main/java/org/openslx/satellitedaemon/Identity.java
@@ -20,7 +20,7 @@ import java.util.Random;
import org.apache.log4j.Logger;
import org.openslx.encryption.AsymKeyHolder;
import org.openslx.satellitedaemon.filetransfer.ThriftConnection;
-import org.openslx.satellitedaemon.util.Util;
+import org.openslx.util.Util;
public class Identity
{
diff --git a/src/main/java/org/openslx/satellitedaemon/db/MySQL.java b/src/main/java/org/openslx/satellitedaemon/db/MySQL.java
index 230f455..d24a13b 100644
--- a/src/main/java/org/openslx/satellitedaemon/db/MySQL.java
+++ b/src/main/java/org/openslx/satellitedaemon/db/MySQL.java
@@ -8,7 +8,7 @@ import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;
-import org.openslx.satellitedaemon.util.Util;
+import org.openslx.util.Util;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
diff --git a/src/main/java/org/openslx/satellitedaemon/util/Util.java b/src/main/java/org/openslx/satellitedaemon/util/Util.java
deleted file mode 100644
index 986ff73..0000000
--- a/src/main/java/org/openslx/satellitedaemon/util/Util.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.openslx.satellitedaemon.util;
-
-import java.io.Closeable;
-
-import org.apache.log4j.Logger;
-
-public class Util
-{
- private static Logger log = Logger.getLogger( Util.class );
-
- /**
- * Check if the given object is null, abort program if true. An optional
- * message to be printed can be passed. A stack trace will be printed, too.
- * Finally the application terminates with exit code 2.
- *
- * This comes in handy if something must not be null, and you want user
- * friendly output. A perfect example would be reading settings from a
- * config file. You can use this on mandatory fields.
- *
- * @param something
- * the object to compare to null
- * @param message
- * the message to be printed if something is null
- */
- public static void notNullFatal( Object something, String message )
- {
- if ( something == null ) {
- if ( message != null )
- log.fatal( "[NOTNULL] " + message );
- log.warn( Thread.currentThread().getStackTrace().toString() );
- System.exit( 2 );
- }
- }
-
- public static void notNullOrEmptyFatal( String something, String message )
- {
- if ( something == null || something.isEmpty() ) {
- if ( message != null )
- log.fatal( "[NOTNULL] " + message );
- log.warn( Thread.currentThread().getStackTrace().toString() );
- System.exit( 2 );
- }
- }
-
- public static void streamClose( Closeable... closeable )
- {
- for ( Closeable c : closeable ) {
- if ( c == null )
- continue;
- try {
- c.close();
- } catch ( Throwable t ) {
- }
- }
- }
-
-}