From f0f414b063905de9051a242abb85f20285451941 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 7 Oct 2014 14:39:49 +0200 Subject: Adapt to login@uni format for user-ids, Put asym keys in extra class --- src/main/java/org/openslx/satellitedaemon/App.java | 27 +-- .../org/openslx/satellitedaemon/AsymKeyHolder.java | 109 ++++++++++ .../java/org/openslx/satellitedaemon/Globals.java | 226 +++++++++------------ .../org/openslx/satellitedaemon/db/DbImage.java | 2 +- .../filetransfer/ThriftConnection.java | 107 ++++------ 5 files changed, 248 insertions(+), 223 deletions(-) create mode 100644 src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java index 2dcaec6..e29520f 100644 --- a/src/main/java/org/openslx/satellitedaemon/App.java +++ b/src/main/java/org/openslx/satellitedaemon/App.java @@ -1,10 +1,6 @@ package org.openslx.satellitedaemon; -import java.security.KeyPair; -import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; @@ -19,29 +15,12 @@ import org.openslx.satellitedaemon.filetransfer.FileUploadWorker; public class App { private static Logger log = Logger.getLogger( App.class ); - + public static void main( String[] args ) throws NoSuchAlgorithmException { BasicConfigurator.configure(); - -// KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); -// kpg.initialize(4096); -// KeyPair kp = kpg.generateKeyPair(); -// RSAPrivateKey privateKey = (RSAPrivateKey) kp.getPrivate(); -// RSAPublicKey publicKey = (RSAPublicKey) kp.getPublic(); -// -// log.debug("modulus: " + privateKey.getModulus().toString()); -// log.debug("exponent: " + privateKey.getPrivateExponent().toString()); -// -// -// log.debug("modulus: " + publicKey.getModulus().toString()); -// log.debug("exponent: " + publicKey.getPublicExponent().toString()); -// -// System.exit(1); - - // Loads all entries from the configuration file config/globals.properties - Globals.init(); - if (!Globals.masterServerSslContextInit()){ + + if ( !Globals.masterServerSslContextInit() ) { log.error( "Problem with initializing the SSLContext" ); System.exit( 1 ); } diff --git a/src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java b/src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java new file mode 100644 index 0000000..7eab79f --- /dev/null +++ b/src/main/java/org/openslx/satellitedaemon/AsymKeyHolder.java @@ -0,0 +1,109 @@ +package org.openslx.satellitedaemon; + +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.math.BigInteger; +import java.security.KeyFactory; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.RSAPrivateKeySpec; + +import org.apache.log4j.Logger; + +public class AsymKeyHolder +{ + private static final Logger LOG = Logger.getLogger( AsymKeyHolder.class ); + + private static PrivateKey privKey = null; + private static PublicKey pubKey = null; + + /** + * Get private key for this server. If none exists yet, create a new one. + * + * @return + */ + public static PrivateKey getPrivateKey() + { + if (privKey == null) { + if (!loadKey() && !generateKey()) { + LOG.warn( "Could not load or generate keypair for communication with masterserver" ); + } + } + + return privKey; + } + + private static boolean loadKey() + { + BufferedReader br = null; + String modulus, exponent; + KeyFactory keyFact; + + try { + keyFact = KeyFactory.getInstance( "RSA" ); + } catch ( NoSuchAlgorithmException nSAE ) { + LOG.warn( "Could not get a KeyFactory to load the key from disk", nSAE ); + return false; + } + + try { + br = new BufferedReader( new FileReader( "config/private.key" ) ); + modulus = br.readLine(); + exponent = br.readLine(); + } catch ( FileNotFoundException e ) { + LOG.error( "File 'private.key' not found!", e ); + return false; + } catch ( IOException e ) { + LOG.error( "File 'private.key' not correct readable.", e ); + return false; + } finally { + try { + br.close(); + } catch ( IOException e ) { + } + } + if ( modulus == null || exponent == null ) { + return false; + } + + try { + BigInteger mod = new BigInteger( modulus ); + BigInteger exp = new BigInteger( exponent ); + + RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec( mod, exp ); + synchronized ( keyFact ) { + privKey = keyFact.generatePrivate( keySpec ); + } + return privKey != null; + } catch ( InvalidKeySpecException e ) { + LOG.error( "Not able to build key with given numbers.", e ); + } catch ( NumberFormatException e ) { + LOG.error( "Invalid number format.", e ); + } + return false; + } + + private static boolean generateKey() + { + // KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); + // kpg.initialize(4096); + // KeyPair kp = kpg.generateKeyPair(); + // RSAPrivateKey privateKey = (RSAPrivateKey) kp.getPrivate(); + // RSAPublicKey publicKey = (RSAPublicKey) kp.getPublic(); + // + // log.debug("modulus: " + privateKey.getModulus().toString()); + // log.debug("exponent: " + privateKey.getPrivateExponent().toString()); + // + // + // log.debug("modulus: " + publicKey.getModulus().toString()); + // log.debug("exponent: " + publicKey.getPublicExponent().toString()); + // + // System.exit(1); + return true; + } + +} diff --git a/src/main/java/org/openslx/satellitedaemon/Globals.java b/src/main/java/org/openslx/satellitedaemon/Globals.java index 9ff6911..cf61aaf 100644 --- a/src/main/java/org/openslx/satellitedaemon/Globals.java +++ b/src/main/java/org/openslx/satellitedaemon/Globals.java @@ -1,12 +1,9 @@ package org.openslx.satellitedaemon; -import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; -import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.KeyFactory; import java.security.KeyManagementException; @@ -15,9 +12,6 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.cert.CertificateException; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.RSAPrivateKeySpec; -import java.security.spec.RSAPublicKeySpec; import java.util.Properties; import javax.net.ssl.SSLContext; @@ -26,65 +20,72 @@ import javax.net.ssl.TrustManagerFactory; import org.apache.log4j.Logger; -public class Globals { - private static Logger log = Logger.getLogger(Globals.class); +public class Globals +{ + private static Logger log = Logger.getLogger( Globals.class ); private static final Properties properties = new Properties(); private static SSLContext context = null; - private static final KeyFactory keyFact; public static final int BLOCKSIZE = 16 * 1024 * 1024; // 16 MB blocksize - public static void init() { - } - /***********************************************************************************************/ /** * A call of Globals.getXXXXXX() returns the corresponding entry in config/global.properties */ - + // * Properties *// // Strings // - public static String getMasterserverHost() { - return properties.getProperty("MASTERSERVER_HOST"); + public static String getMasterserverHost() + { + return properties.getProperty( "MASTERSERVER_HOST" ); } - public static String getKeystoreType() { - return properties.getProperty("KEYSTORE_TYPE"); + public static String getKeystoreType() + { + return properties.getProperty( "KEYSTORE_TYPE" ); } - public static String getFiletransferKeystorePath() { - return properties.getProperty("FILETRANSFER_KEYSTORE_PATH"); + public static String getFiletransferKeystorePath() + { + return properties.getProperty( "FILETRANSFER_KEYSTORE_PATH" ); } - public static String getFiletransferKeystorePassword() { - return properties.getProperty("FILETRANSFER_KEYSTORE_PASSWORD"); + public static String getFiletransferKeystorePassword() + { + return properties.getProperty( "FILETRANSFER_KEYSTORE_PASSWORD" ); } - public static String getOrganizationName() { - return properties.getProperty("ORGANIZATION_NAME"); + public static String getOrganizationName() + { + return properties.getProperty( "ORGANIZATION_NAME" ); } - public static String getThriftKeystoreAlias() { - return properties.getProperty("THRIFT_KEYSTORE_ALIAS"); + public static String getThriftKeystoreAlias() + { + return properties.getProperty( "THRIFT_KEYSTORE_ALIAS" ); } - public static String getThriftKeystorePassword() { - return properties.getProperty("THRIFT_KEYSTORE_PASSWORD"); + public static String getThriftKeystorePassword() + { + return properties.getProperty( "THRIFT_KEYSTORE_PASSWORD" ); } - public static String getThriftKeystorePath() { - return properties.getProperty("THRIFT_KEYSTORE_PATH"); + public static String getThriftKeystorePath() + { + return properties.getProperty( "THRIFT_KEYSTORE_PATH" ); } - - public static String getImageFolder() { - return properties.getProperty("IMAGE_FOLDER"); + + public static String getImageFolder() + { + return properties.getProperty( "IMAGE_FOLDER" ); } // Integers // - public static int getThriftPort() { - return tryToParseInt(properties.getProperty("THRIFT_PORT")); + public static int getThriftPort() + { + return tryToParseInt( properties.getProperty( "THRIFT_PORT" ) ); } /** @@ -94,31 +95,23 @@ public class Globals { try { // Load all entries of the config file into properties InputStreamReader stream = new InputStreamReader( - new FileInputStream("config/global.properties"), StandardCharsets.UTF_8); - properties.load(stream); + new FileInputStream( "config/global.properties" ), StandardCharsets.UTF_8 ); + properties.load( stream ); stream.close(); - } catch (IOException e) { - log.error("Could not load properties. Exiting."); - System.exit(2); + } catch ( IOException e ) { + log.error( "Could not load properties. Exiting." ); + System.exit( 2 ); } - - KeyFactory kf; - try { - kf = KeyFactory.getInstance("RSA"); - } catch (NoSuchAlgorithmException nSAE) { - kf = null; - } - keyFact = kf; - - notNullOrEmptyFatal(getMasterserverHost(), "Masterserver Host must not be empty!"); - notNullOrEmptyFatal(getKeystoreType(), "Keystore Type must not be empty"); - notNullOrEmptyFatal(getFiletransferKeystorePassword(), "File transfer Keystore Password must not be empty!"); - notNullOrEmptyFatal(getFiletransferKeystorePath(), "File transfer Keystore Path must not be empty!"); - notNullOrEmptyFatal(getOrganizationName(), "Organiziation Name must not be empty!"); - notNullOrEmptyFatal(getThriftKeystoreAlias(), "Thrift Keystore Alias must not be empty!"); - notNullOrEmptyFatal(getThriftKeystorePassword(), "Thrift Keystore Password must not be empty!"); - notNullOrEmptyFatal(getThriftKeystorePath(), "Thrift Keystore Path must not be empty!"); - notNullOrEmptyFatal(getImageFolder(), "Image Folder must not be empty!"); + + notNullOrEmptyFatal( getMasterserverHost(), "Masterserver Host must not be empty!" ); + notNullOrEmptyFatal( getKeystoreType(), "Keystore Type must not be empty" ); + notNullOrEmptyFatal( getFiletransferKeystorePassword(), "File transfer Keystore Password must not be empty!" ); + notNullOrEmptyFatal( getFiletransferKeystorePath(), "File transfer Keystore Path must not be empty!" ); + notNullOrEmptyFatal( getOrganizationName(), "Organiziation Name must not be empty!" ); + notNullOrEmptyFatal( getThriftKeystoreAlias(), "Thrift Keystore Alias must not be empty!" ); + notNullOrEmptyFatal( getThriftKeystorePassword(), "Thrift Keystore Password must not be empty!" ); + notNullOrEmptyFatal( getThriftKeystorePath(), "Thrift Keystore Path must not be empty!" ); + notNullOrEmptyFatal( getImageFolder(), "Image Folder must not be empty!" ); } /***********************************************************************************************/ @@ -126,42 +119,44 @@ public class Globals { * * @return */ - public static boolean masterServerSslContextInit() { + public static boolean masterServerSslContextInit() + { char[] passphrase = getFiletransferKeystorePassword().toCharArray(); KeyStore keystore; try { - keystore = KeyStore.getInstance("JKS"); - keystore.load(new FileInputStream(getFiletransferKeystorePath()), - passphrase); + keystore = KeyStore.getInstance( "JKS" ); + keystore.load( new FileInputStream( getFiletransferKeystorePath() ), + passphrase ); TrustManagerFactory tmf = TrustManagerFactory - .getInstance(TrustManagerFactory.getDefaultAlgorithm()); - tmf.init(keystore); - context = SSLContext.getInstance("SSLv3"); + .getInstance( TrustManagerFactory.getDefaultAlgorithm() ); + tmf.init( keystore ); + context = SSLContext.getInstance( "SSLv3" ); TrustManager[] trustManagers = tmf.getTrustManagers(); - context.init(null, trustManagers, null); - } catch (KeyStoreException e) { - log.error("KeyStoreException"); + context.init( null, trustManagers, null ); + } catch ( KeyStoreException e ) { + log.error( "KeyStoreException" ); return false; - } catch (NoSuchAlgorithmException e) { - log.error("NoSuchAlgorithmException"); + } catch ( NoSuchAlgorithmException e ) { + log.error( "NoSuchAlgorithmException" ); return false; - } catch (CertificateException e) { - log.error("CertificateException"); + } catch ( CertificateException e ) { + log.error( "CertificateException" ); return false; - } catch (FileNotFoundException e) { - log.error("Could not find the keystore for the filetransfer. Path was '" + getFiletransferKeystorePath() + "'"); + } catch ( FileNotFoundException e ) { + log.error( "Could not find the keystore for the filetransfer. Path was '" + getFiletransferKeystorePath() + "'" ); return false; - } catch (IOException e) { - log.error("IOException", e); + } catch ( IOException e ) { + log.error( "IOException", e ); return false; - } catch (KeyManagementException e) { - log.error("KeyManagementException"); + } catch ( KeyManagementException e ) { + log.error( "KeyManagementException" ); return false; } return true; } - public static SSLContext getMasterServerSslContext() { + public static SSLContext getMasterServerSslContext() + { return Globals.context; } @@ -169,65 +164,36 @@ public class Globals { * Tries to parse an int. Returns 0 on error. * * @param s - * The strig to parse + * The strig to parse * @return The parsed int or 0 on error */ - public static int tryToParseInt(String s) { + public static int tryToParseInt( String s ) + { try { - return Integer.parseInt(s); - } catch (NumberFormatException e) { + return Integer.parseInt( s ); + } catch ( NumberFormatException e ) { return 0; } } - 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 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 PrivateKey getPrivateKey() { - PrivateKey ret; - BufferedReader br = null; - String modulus, exponent; - try { - br = new BufferedReader(new FileReader("config/private.key")); - modulus = br.readLine(); - exponent = br.readLine(); - } catch (FileNotFoundException e) { - log.error("File 'private.key' not found!", e); - return null; - } catch (IOException e) { - log.error("File 'private.key' not correct readable.", e); - return null; - } finally { - try { - br.close(); - } catch (IOException e) { - } - } - if (modulus == null || exponent == null) { - return null; - } - - try { - BigInteger mod = new BigInteger(modulus); - BigInteger exp = new BigInteger(exponent); - - RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(mod, exp); - synchronized (keyFact) { - ret = keyFact.generatePrivate(keySpec); - } - } catch (InvalidKeySpecException e) { - log.error("Not able to build key with given numbers.", e); - return null; - } catch (NumberFormatException e) { - log.error("Invalid number format.", e); - return null; - } - return ret; + + /** + * Get private key for this server. If none exists yet, create a new one. + * + * @return + */ + public static PrivateKey getPrivateKey() + { + return AsymKeyHolder.getPrivateKey(); } -} \ No newline at end of file + +} diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java index a7dcbc3..7079380 100644 --- a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java +++ b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java @@ -45,7 +45,7 @@ public class DbImage public static List getAllMarkedForUpload() { return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," + - " Concat(user.loginName, '@', institution.name) AS userID, image.image_filesize" + + " user.loginName, '@', institution.name) AS userID, image.image_filesize" + " FROM m_VLData_imageInfo image" + " INNER JOIN m_user user ON (image.image_owner = user.userID)" + " INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" + diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java index 89a8122..18462be 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java @@ -31,8 +31,6 @@ import org.openslx.satellitedaemon.Globals; import org.openslx.satellitedaemon.db.DbImage; import org.openslx.satellitedaemon.db.DbImage.Status; -// TODO: Handle all the auto-generated catch blocks in a meaningful way - /***********************************************************************************************/ /** * Handles the authentication with the Satellite Server and sends the @@ -40,7 +38,7 @@ import org.openslx.satellitedaemon.db.DbImage.Status; */ public class ThriftConnection { - private static ImageServer.Client client = null; + private static ThreadLocal client = new ThreadLocal(); private static ServerSessionData sSD = null; private static Logger log = Logger.getLogger( ThriftConnection.class ); private static CrcFile crc = null; @@ -69,10 +67,6 @@ public class ThriftConnection crc = new CrcFile( crcPath ); log.info( "Made CRCFile from " + crcPath ); log.info( "crc.getCrcSums( ).size = " + crc.getCrcSums().size() ); - // log.info( "crc.getMasterSum() : " + crc.getMasterSum() ); - // for ( int i = 0; i < crc.getCrcSums().size() - 1; i++ ) { - // log.info( "crc.getCRCSum() : " + crc.getCRCSum( i ) ); - // } crcSums = crc.getCrcSums(); } catch ( FileNotFoundException e ) { log.debug( "crcFile " + crcPath + " not found." ); @@ -82,42 +76,29 @@ public class ThriftConnection try { return theClient.submitImage( sSD.sessionId, imDat, crcSums ); } catch ( AuthorizationException e ) { - if ( e.isSetNumber() - && e.getNumber().equals( - AuthorizationError.NOT_AUTHENTICATED ) ) { - // SessionID is not valid - // TODO: Code for new SSID - } else if ( e.getNumber().equals( AuthorizationError.NO_PERMISSION ) ) { + if ( e.number == AuthorizationError.NOT_AUTHENTICATED ) { + log.warn( "Suddenly nut authenticated anymore.", e ); + } else if ( e.number == AuthorizationError.NO_PERMISSION ) { log.error( "No permission for uploading.", e ); // TODO: add error message into database. } else { - e.printStackTrace(); + log.warn( "Unknown authorization error.", e ); } } catch ( ImageDataException e ) { - if ( e.isSetNumber() - && e.getNumber().equals( ImageDataError.INVALID_DATA ) ) { - e.printStackTrace(); - // Data in the db is not valid + if ( e.number == ImageDataError.INVALID_DATA ) { + log.warn( "Data for image not valid", e ); // TODO: add e.message into DB; } else { - e.printStackTrace(); + log.warn( "ImageDataException", e ); } } catch ( UploadException e ) { - if ( e.isSetNumber() - && e.getNumber().equals( UploadError.BROKEN_BLOCK ) ) { + if ( e.number == UploadError.BROKEN_BLOCK ) { // A Block was transmitted 20 times unsuccessfully. // TODO: Mark the Image as corrupted. - } else if ( e.getNumber().equals( UploadError.INVALID_CRC ) ) { + } else if ( e.number == UploadError.INVALID_CRC ) { // The CRC sum contained errors - try { - crc = new CrcFile( crcPath ); - } catch ( IOException e1 ) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - if ( !crc.isValid() ) { - // TODO: Mark CRC-file as corrupted. - } + if ( crc != null && !crc.isValid() ) + crc.delete(); } else { e.printStackTrace(); } @@ -157,8 +138,7 @@ public class ThriftConnection // TODO: change field image_syncMode, so the image is not asked // for again. // For now just changed status of image. Currently no - // possibility - // for creating new useful state in DB. (Offenburg) + // possibility for creating new useful state in DB. (Offenburg) log.info( "Image not known. For skipping next time, mark as only_local." ); imDat.updateStatus( Status.only_local ); // Plus add a note in some way to mark as unknown by Server @@ -194,66 +174,58 @@ public class ThriftConnection */ private static ImageServer.Client getConnection() { - ImageServer.Client theClient = null; - boolean isAuthenticated = false; - if ( client == null ) { - log.info( "The global client was null. Making a new client ..." ); + ImageServer.Client theClient = client.get(); + boolean isAuthenticated; + + if ( theClient == null ) { + // There is no client instance for this thread, create a new one + log.info( "No existing client for this thread. Making a new client ..." ); theClient = newClient(); + isAuthenticated = false; if ( theClient == null ) { - log.debug( "ThriftConnection: The client was null after newClient()" ); + log.debug( "The client was null after newClient()" ); return null; } } else { - log.info( "The global Client was already used. Setting isAuthenticated = true." ); - theClient = client; - isAuthenticated = true; - } - // here the client was already used so we are just assuming that the - // client is still - // authenticated. Should be checked with the ping() method. - try { - isAuthenticated = theClient.isServerAuthenticated( sSD.sessionId ); - } catch ( TException x ) { - theClient = newClient(); - if ( theClient == null ) { - return null; + // There is a client instance for this thread, see if it's still usable and authenticated + try { + isAuthenticated = theClient.isServerAuthenticated( sSD.sessionId ); + log.debug( "Existing client is " + ( isAuthenticated ? "still" : "not" ) + " authenticated." ); + } catch ( TException x ) { + theClient = newClient(); + if ( theClient == null ) { + log.warn( "Masterserver connection fail" ); + return null; + } + log.debug( "Existing client was not connected anymore." ); + isAuthenticated = false; } } + if ( !isAuthenticated ) { - log.info( "ThriftConnection: Client not yet Authenticated. Trying..." ); try { ByteBuffer tmpBuffer = theClient .startServerAuthentication( Globals .getOrganizationName() ); byte[] toEncrypt = new byte[ tmpBuffer.remaining() ]; tmpBuffer.get( toEncrypt ); - log.info( "The random String we want to encrypt: " + toEncrypt ); - log.info( "Length of the random String : " + toEncrypt.length ); AsymEncryptionHandler aeh = new AsymEncryptionHandler( Globals.getPrivateKey() ); byte[] byteArray = aeh.encryptMessage( toEncrypt ); - log.info( "Length of the byteArray of the random string after encryption :" - + byteArray.length ); - ByteBuffer b = ByteBuffer.wrap( byteArray ); - log.info( "Length of the byteBuffer after encryption :" - + b.remaining() ); sSD = theClient.serverAuthenticate( Globals.getOrganizationName(), ByteBuffer.wrap( byteArray ) ); } catch ( AuthenticationException e ) { - log.error( "ThriftConnection: AuthenticationException: Server Authetication was not sucessful." ); - e.printStackTrace(); + log.error( "ThriftConnection: AuthenticationException: Server Authetication was not sucessful.", e ); return null; } catch ( TException e ) { - log.error( "ThriftConnection: TException: Server Authetication was not sucessful." ); - e.printStackTrace(); + log.error( "ThriftConnection: TException: Server Authetication was not sucessful.", e ); return null; } log.info( "is Authenticated." ); } - client = theClient; return theClient; } @@ -265,7 +237,7 @@ public class ThriftConnection */ private static ImageServer.Client newClient() { - ImageServer.Client newClient = null; + final ImageServer.Client newClient; try { TTransport transport = new TFramedTransport( new TSocket( Globals.getMasterserverHost(), Globals.getThriftPort() ) ); @@ -274,11 +246,10 @@ public class ThriftConnection newClient = new ImageServer.Client( protocol ); log.debug( "ThriftConnection: Made a new Client" ); } catch ( TTransportException e ) { - log.error( - "Transport could not be opened. Couldn't create new client.", - e ); + log.error( "Transport could not be opened. Couldn't create new client.", e ); return null; } + client.set( newClient ); return newClient; } } -- cgit v1.2.3-55-g7522