diff options
author | 2025-01-06 11:34:17 +0100 | |
---|---|---|
committer | 2025-01-06 15:05:46 +0100 | |
commit | 671edd133f4858b4b17663d109a23c80bbffa6b7 (patch) | |
tree | a9b05a6180b7c061b57c711b58f867281c3b4d52 /aai-els-onap-logging | |
parent | e0d6fcbfcdc38edd17b36050feead7314667f4a5 (diff) |
Make aai-common agnostic of the embedded server (remove jetty-specific code)
- remove spring-boot-starter-[web,tomcat,jetty,jersey] in aai-rest
- remove spring-boot-starter-web in aai-schema-ingest
- remove keystore and certificate related leftovers
- this prepares the move to tomcat for the spring boot 3 upgrade (details in the ticket)
Issue-ID: AAI-4100
Change-Id: I04194c636f0548f7a832e430a40e48710ea4c00f
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'aai-els-onap-logging')
5 files changed, 20 insertions, 271 deletions
diff --git a/aai-els-onap-logging/pom.xml b/aai-els-onap-logging/pom.xml index 31802ea0..1f818661 100644 --- a/aai-els-onap-logging/pom.xml +++ b/aai-els-onap-logging/pom.xml @@ -80,17 +80,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>3.12.4</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <scope>test</scope> @@ -131,11 +120,22 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> - <exclusion> - <groupId>com.vaadin.external.google</groupId> - <artifactId>android-json</artifactId> - </exclusion> - </exclusions> + <exclusion> + <groupId>com.vaadin.external.google</groupId> + <artifactId>android-json</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>3.12.4</version> + <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java index a7a87dca..30dd66b8 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIApplicationConfig.java @@ -20,16 +20,12 @@ package org.onap.aai.util; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.Charset; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.IOUtils; import org.eclipse.jetty.util.security.Password; import org.onap.aai.exceptions.AAIException; import org.slf4j.Logger; @@ -39,19 +35,10 @@ public class AAIApplicationConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AAIApplicationConfig.class); private static String GLOBAL_PROP_FILE_NAME = "application.properties"; - private static final String SERVER_CERTS_LOCATION_PROP_NAME = "server.certs.location"; - private static final String PASSPHRASSES_FILENAME = ".passphrases"; - private static final String PASSWORD_FILENAME = ".password"; - private static final String TRUSTSTORE_PASSWORD_PROP_NAME = "cadi_truststore_password"; - public static final String SERVER_SSL_KEYSTORE_PROP_NAME = "server.ssl.key-store"; - public static final String SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME = "server.ssl.key-store.pkcs12"; - public static final String SERVER_SSL_TRUSTSTORE_PROP_NAME = "server.ssl.trust-store"; - public static final String TRUSTSTORE_PASSWORD_NAME = "server.ssl.trust-store-password"; - public static final String KEYSTORE_PASSWORD_NAME = "server.ssl.key-store-password"; + private static Properties serverProps; private static boolean propsInitialized = false; - private static String TRUSTSTORE_PASSWORD = null; - private static String KEYSTORE_PASSWORD = null; + private static final String PROPERTY_REGEX = "\\$\\{([^\\$\\{\\}]+)\\}"; /** @@ -85,8 +72,6 @@ public class AAIApplicationConfig { newServerProps.load(is); propsInitialized = true; serverProps = newServerProps; - TRUSTSTORE_PASSWORD = retrieveTruststorePassword(); - KEYSTORE_PASSWORD = retrieveKeystorePassword(); } catch (Exception fnfe) { final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"); @@ -95,8 +80,6 @@ public class AAIApplicationConfig { try { newServerProps.load(is); serverProps = newServerProps; - TRUSTSTORE_PASSWORD = retrieveTruststorePassword(); - KEYSTORE_PASSWORD = retrieveKeystorePassword(); } catch (IOException e) { LOGGER.warn("Encountered IO Exception during loading of props from inputstream", e); } @@ -158,162 +141,6 @@ public class AAIApplicationConfig { } /** - * Gets the keystore path - * - * @return the string - * @throws AAIException the AAI exception - */ - public static String getKeystore() throws AAIException { - return (get(SERVER_SSL_KEYSTORE_PROP_NAME)); - } - - /** - * Gets the PKCS12 keystore path - * - * @return the string - * @throws AAIException the AAI exception - */ - public static String getKeystorePkcs12() throws AAIException { - return (get(SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME)); - } - - /** - * Gets the keystore path - * - * @return the string - * @throws AAIException the AAI exception - */ - public static String getTruststore() throws AAIException { - return (get(SERVER_SSL_TRUSTSTORE_PROP_NAME)); - } - - /** - * Retrieve the keystore password - * - * @return the password - */ - private static String retrieveKeystorePassword() { - String certPath = serverProps.getProperty(SERVER_CERTS_LOCATION_PROP_NAME); - if (certPath == null) { - return null; - } - try { - certPath = replaceProperties(certPath); - } catch (AAIException e) { - return null; - } - return (retrieveKeystorePasswordWithCertPath(certPath)); - } - - /** - * Retrieve the keystore password - * - * @return the password - */ - private static String retrieveKeystorePasswordWithCertPath(String certPath) { - - File passwordFile = null; - InputStream passwordStream = null; - String keystorePassword = null; - - // Override the passwords from application.properties if we find AAF certman files - try { - passwordFile = new File(certPath + PASSWORD_FILENAME); - passwordStream = new FileInputStream(passwordFile); - keystorePassword = IOUtils.toString(passwordStream, Charset.defaultCharset()); - if (keystorePassword != null) { - keystorePassword = keystorePassword.trim(); - } - - } catch (IOException e) { - LOGGER.warn("Not using AAF Certman password file, e=" + e.getMessage()); - } catch (NullPointerException n) { - LOGGER.warn("Not using AAF Certman passphrases file, e=" + n.getMessage()); - } finally { - if (passwordStream != null) { - try { - passwordStream.close(); - } catch (Exception e) { - } - } - } - return keystorePassword; - } - - /** - * Get the keystore password - * - * @return the password - */ - public static String getKeystorePassword() { - return (KEYSTORE_PASSWORD); - } - - /** - * Gets the truststore password - * - * @return the password - */ - private static String retrieveTruststorePasswordWithCertPath(String certPath) { - - File passphrasesFile = null; - InputStream passphrasesStream = null; - String truststorePassword = null; - try { - passphrasesFile = new File(certPath + PASSPHRASSES_FILENAME); - passphrasesStream = new FileInputStream(passphrasesFile); - - Properties passphrasesProps = new Properties(); - passphrasesProps.load(passphrasesStream); - truststorePassword = passphrasesProps.getProperty(TRUSTSTORE_PASSWORD_PROP_NAME); - if (truststorePassword != null) { - truststorePassword = truststorePassword.trim(); - } - - } catch (IOException e) { - LOGGER.warn("Not using AAF Certman passphrases file, e=" + e.getMessage()); - } catch (NullPointerException n) { - LOGGER.warn("Not using AAF Certman passphrases file, e=" + n.getMessage()); - } finally { - if (passphrasesStream != null) { - try { - passphrasesStream.close(); - } catch (Exception e) { - } - } - } - - return truststorePassword; - } - - /** - * Gets the truststore password - * - * @return the password - */ - private static String retrieveTruststorePassword() { - String certPath = serverProps.getProperty(SERVER_CERTS_LOCATION_PROP_NAME); - if (certPath == null) { - return null; - } - try { - certPath = replaceProperties(certPath); - } catch (AAIException e) { - return null; - } - return (retrieveTruststorePasswordWithCertPath(certPath)); - } - - /** - * Get the trustore password - * - * @return the password - */ - public static String getTruststorePassword() { - return (TRUSTSTORE_PASSWORD); - } - - /** * Gets the int value for the key. * * @param key the key @@ -370,49 +197,4 @@ public class AAIApplicationConfig { m.appendTail(sb); return (sb.toString()); } - - public static Properties retrieveKeystoreProps() throws AAIException { - - Properties props = new Properties(); - String truststorePath = System.getProperty(SERVER_SSL_TRUSTSTORE_PROP_NAME); - String truststorePassword = System.getProperty(TRUSTSTORE_PASSWORD_NAME); - String keystorePath = System.getProperty(SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME); - String keystorePassword = System.getProperty(KEYSTORE_PASSWORD_NAME); - String certLocation = System.getProperty(SERVER_CERTS_LOCATION_PROP_NAME); - - if (truststorePath == null || truststorePath.isEmpty()) { - truststorePath = AAIApplicationConfig.getTruststore(); - } - if (truststorePath != null) { - props.setProperty(SERVER_SSL_TRUSTSTORE_PROP_NAME, truststorePath); - } - if (truststorePassword == null || truststorePassword.isEmpty()) { - if (certLocation != null && (!certLocation.isEmpty())) { - truststorePassword = AAIApplicationConfig.retrieveTruststorePasswordWithCertPath(certLocation); - } else { - truststorePassword = AAIApplicationConfig.getTruststorePassword(); - } - - } - if (truststorePassword != null) { - props.setProperty(TRUSTSTORE_PASSWORD_NAME, truststorePassword); - } - if (keystorePath == null || keystorePath.isEmpty()) { - keystorePath = AAIApplicationConfig.getKeystorePkcs12(); - } - if (keystorePath != null) { - props.setProperty(SERVER_SSL_KEYSTORE_PKCS12_PROP_NAME, keystorePath); - } - if (keystorePassword == null || keystorePassword.isEmpty()) { - if (certLocation != null && (!certLocation.isEmpty())) { - keystorePassword = AAIApplicationConfig.retrieveKeystorePasswordWithCertPath(certLocation); - } else { - keystorePassword = AAIApplicationConfig.getKeystorePassword(); - } - } - if (keystorePassword != null) { - props.setProperty(KEYSTORE_PASSWORD_NAME, keystorePassword); - } - return (props); - } } diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java index a1a36189..4a7c4896 100644 --- a/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java +++ b/aai-els-onap-logging/src/main/java/org/onap/aai/util/AAIConstants.java @@ -59,11 +59,6 @@ public final class AAIConstants { public static final String AAI_SCHEMA_MOD_LOGBACK_PROPS = "schemaMod-logback.xml"; public static final String AAI_FORCE_DELETE_LOGBACK_PROPS = "forceDelete-logback.xml"; - public static final String AAI_TRUSTSTORE_FILENAME = "aai.truststore.filename"; - public static final String AAI_TRUSTSTORE_PASSWD = "aai.truststore.passwd"; - public static final String AAI_KEYSTORE_FILENAME = "aai.keystore.filename"; - public static final String AAI_KEYSTORE_PASSWD = "aai.keystore.passwd"; - public static final String AAI_SERVER_URL_BASE = "aai.server.url.base"; public static final String AAI_SERVER_URL = "aai.server.url"; public static final String AAI_OLDSERVER_URL = "aai.oldserver.url"; diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java index 242e3441..82942190 100644 --- a/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java +++ b/aai-els-onap-logging/src/test/java/org/onap/aai/util/AAIApplicationConfigTest.java @@ -37,28 +37,13 @@ public class AAIApplicationConfigTest { } @Test - public void truststoreTest() throws AAIException { - assertEquals("truststore.jks", AAIApplicationConfig.getTruststore()); - } - - @Test - public void keystoreTest() throws AAIException { - assertEquals("keystore.jks", AAIApplicationConfig.getKeystore()); - } - - @Test - public void getKeystorePkcs12Test() throws AAIException { - assertEquals("keystore.pkcs12", AAIApplicationConfig.getKeystorePkcs12()); - } - - @Test public void getValueWithDefaultTest() throws AAIException { assertEquals("default-value", AAIApplicationConfig.get("non-existing-key", "default-value")); } @Test public void getValueTest() throws AAIException { - assertEquals("certificates", AAIApplicationConfig.get("server.certs.location")); + assertEquals("8446", AAIApplicationConfig.get("server.port")); } @Test @@ -70,10 +55,4 @@ public class AAIApplicationConfigTest { public void getIntValueWithDefaultTest() throws AAIException { assertTrue(9999 == AAIApplicationConfig.getInt("non-existing-key", "9999")); } - - @Test - public void getValueWithReplacementTest() throws AAIException { - assertEquals("/opt/app/aai/etc/auth/aai-client-cert.p12", - AAIApplicationConfig.get("schema.service.ssl.key-store")); - } } diff --git a/aai-els-onap-logging/src/test/resources/application.properties b/aai-els-onap-logging/src/test/resources/application.properties index df8fd64d..bd2fd55f 100644 --- a/aai-els-onap-logging/src/test/resources/application.properties +++ b/aai-els-onap-logging/src/test/resources/application.properties @@ -2,7 +2,7 @@ # ============LICENSE_START======================================================= # org.onap.aai # ================================================================================ -# Copyright © 2017-18 AT&T Intellectual Property. All rights reserved. +# Copyright � 2017-18 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,10 +20,3 @@ spring.application.name=AAI Microservice server.port=8446 server.local.startpath=/opt/app/aai schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19 -server.certs.location=certificates -server.ssl.key-store=keystore.jks -server.ssl.key-store.pkcs12=keystore.pkcs12 -server.ssl.trust-store=truststore.jks -schema.service.ssl.key-store=${server.local.startpath}/etc/auth/aai-client-cert.p12 -schema.service.ssl.trust-store=${server.local.startpath}/etc/auth/aai_keystore.jks - |