diff options
Diffstat (limited to 'src/main')
6 files changed, 27 insertions, 68 deletions
diff --git a/src/main/java/org/onap/aai/auth/FileWatcher.java b/src/main/java/org/onap/aai/auth/FileWatcher.java index 9c4e04e..1edad1d 100644 --- a/src/main/java/org/onap/aai/auth/FileWatcher.java +++ b/src/main/java/org/onap/aai/auth/FileWatcher.java @@ -33,7 +33,7 @@ public abstract class FileWatcher extends TimerTask { * * @param file the file */ - public FileWatcher(File file) { + protected FileWatcher(File file) { this.file = file; this.timeStamp = file.lastModified(); } diff --git a/src/main/java/org/onap/aai/babel/BabelApplication.java b/src/main/java/org/onap/aai/babel/BabelApplication.java index 71fe7e0..4f67b21 100644 --- a/src/main/java/org/onap/aai/babel/BabelApplication.java +++ b/src/main/java/org/onap/aai/babel/BabelApplication.java @@ -50,17 +50,11 @@ public class BabelApplication extends SpringBootServletInitializer { if (keyStorePassword == null || keyStorePassword.isEmpty()) { throw new IllegalArgumentException("Mandatory property KEY_STORE_PASSWORD not set"); } - try { - SpringApplication app = new SpringApplication(BabelApplication.class); - app.setLogStartupInfo(false); - app.setRegisterShutdownHook(true); - app.addInitializers(new PropertyPasswordConfiguration()); - context = app.run(args); - } - catch(Exception ex){ - ex.printStackTrace(); - throw ex; - } + SpringApplication app = new SpringApplication(BabelApplication.class); + app.setLogStartupInfo(false); + app.setRegisterShutdownHook(true); + app.addInitializers(new PropertyPasswordConfiguration()); + context = app.run(args); } public static void exit() { diff --git a/src/main/java/org/onap/aai/babel/config/PropertyPasswordConfiguration.java b/src/main/java/org/onap/aai/babel/config/PropertyPasswordConfiguration.java index c8efa01..7539d41 100644 --- a/src/main/java/org/onap/aai/babel/config/PropertyPasswordConfiguration.java +++ b/src/main/java/org/onap/aai/babel/config/PropertyPasswordConfiguration.java @@ -19,16 +19,14 @@ */ package org.onap.aai.babel.config; -import org.apache.commons.io.IOUtils; +import java.nio.charset.StandardCharsets; import org.eclipse.jetty.util.security.Password; -import org.onap.aai.babel.logging.LogHelper; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; -import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -38,79 +36,50 @@ import java.util.Properties; public class PropertyPasswordConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext> { + private static final String PROP_KEY_STORE_PASS = "server.ssl.key-store-password"; + @Override public void initialize(ConfigurableApplicationContext applicationContext) { Map<String, Object> sslProps = new LinkedHashMap<>(); ConfigurableEnvironment environment = applicationContext.getEnvironment(); String certPath = environment.getProperty("server.certs.location"); - File passwordFile = null; - File passphrasesFile = null; - InputStream passwordStream = null; - InputStream passphrasesStream = null; String keystorePassword = null; String truststorePassword = null; if (certPath != null) { - try { - passwordFile = new File(certPath + ".password"); - passwordStream = new FileInputStream(passwordFile); - - if (passwordStream != null) { - keystorePassword = IOUtils.toString(passwordStream); - if (keystorePassword != null) { - keystorePassword = keystorePassword.trim(); - } - sslProps.put("server.ssl.key-store-password", keystorePassword); - } + try (InputStream passwordStream = new FileInputStream(certPath + ".password")) { + keystorePassword = new String(passwordStream.readAllBytes(), StandardCharsets.UTF_8); + keystorePassword = keystorePassword.trim(); + sslProps.put(PROP_KEY_STORE_PASS, keystorePassword); } catch (IOException e) { - } finally { - if (passwordStream != null) { - try { - passwordStream.close(); - } catch (Exception e) { - } - } + keystorePassword = null; } - try { - passphrasesFile = new File(certPath + ".passphrases"); - passphrasesStream = new FileInputStream(passphrasesFile); - - if (passphrasesStream != null) { - Properties passphrasesProps = new Properties(); - passphrasesProps.load(passphrasesStream); - truststorePassword = passphrasesProps.getProperty("cadi_truststore_password"); - if (truststorePassword != null) { - truststorePassword = truststorePassword.trim(); - } - sslProps.put("server.ssl.trust-store-password", truststorePassword); - } else { + try (InputStream passphrasesStream = new FileInputStream(certPath + ".passphrases");) { + Properties passphrasesProps = new Properties(); + passphrasesProps.load(passphrasesStream); + truststorePassword = passphrasesProps.getProperty("cadi_truststore_password"); + if (truststorePassword != null) { + truststorePassword = truststorePassword.trim(); } + sslProps.put("server.ssl.trust-store-password", truststorePassword); } catch (IOException e) { - } finally { - if (passphrasesStream != null) { - try { - passphrasesStream.close(); - } catch (Exception e) { - } - } + truststorePassword = null; } } if (keystorePassword == null || keystorePassword.isEmpty()) { keystorePassword = System.getProperty("KEY_STORE_PASSWORD"); if (keystorePassword != null && (!keystorePassword.isEmpty()) ) { - System.setProperty("server.ssl.key-store-password", new Password(keystorePassword).toString()); + System.setProperty(PROP_KEY_STORE_PASS, new Password(keystorePassword).toString()); } if (keystorePassword == null || keystorePassword.isEmpty()) { throw new IllegalArgumentException("Mandatory property KEY_STORE_PASSWORD not set"); } } else { - sslProps.put("server.ssl.key-store-password", keystorePassword); + sslProps.put(PROP_KEY_STORE_PASS, keystorePassword); } - if (truststorePassword == null || truststorePassword.isEmpty()) { - } - else { + if (truststorePassword != null && !truststorePassword.isEmpty()) { sslProps.put("server.ssl.trust-store-password", truststorePassword); } if (!sslProps.isEmpty()) { diff --git a/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java b/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java index 18d294e..c38e730 100644 --- a/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java +++ b/src/main/java/org/onap/aai/babel/csar/CsarToXmlConverter.java @@ -79,8 +79,6 @@ public class CsarToXmlConverter { } catch (XmlArtifactGenerationException e) { throw new CsarConverterException( "An error occurred trying to generate XML files from a collection of YAML files : " + e); - } finally { - } return xmlArtifacts; diff --git a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java index f94da4a..ecc81fd 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/ModelGenerator.java @@ -45,8 +45,6 @@ public class ModelGenerator implements ArtifactGenerator { private static final LogHelper logger = LogHelper.INSTANCE; - private static final String VERSION_DELIMITER = "."; - private static final String VERSION_DELIMITER_REGEXP = "\\" + VERSION_DELIMITER; private static final String DEFAULT_SERVICE_VERSION = "1.0"; /** diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java index 50c5d5b..69bbb80 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiModelGenerator.java @@ -80,8 +80,8 @@ public class AaiModelGenerator { org.onap.aai.babel.xml.generator.xsd.Model aaiModel = new org.onap.aai.babel.xml.generator.xsd.Model(); aaiModel.setModelInvariantId(model.getModelId()); aaiModel.setModelType(model.getModelTypeName()); - if (model.getModelTypeName() == "service"){ - aaiModel.setModelRole(model.getCategory()); + if ("service".equals(model.getModelTypeName())){ + aaiModel.setModelRole(model.getCategory()); } aaiModel.setModelVers(new ModelVers()); aaiModel.getModelVers().getModelVer().add(createModelVersion(model)); |