diff options
author | 2025-01-06 11:34:17 +0100 | |
---|---|---|
committer | 2025-01-06 15:05:46 +0100 | |
commit | 671edd133f4858b4b17663d109a23c80bbffa6b7 (patch) | |
tree | a9b05a6180b7c061b57c711b58f867281c3b4d52 /aai-rest | |
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-rest')
9 files changed, 18 insertions, 333 deletions
diff --git a/aai-rest/pom.xml b/aai-rest/pom.xml index c59ddbe7..3623f51c 100644 --- a/aai-rest/pom.xml +++ b/aai-rest/pom.xml @@ -46,25 +46,7 @@ </dependency> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <exclusions> - <exclusion> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-tomcat</artifactId> - </exclusion> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>log4j-over-slf4j</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jetty</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-jersey</artifactId> + <artifactId>spring-boot-autoconfigure</artifactId> </dependency> <dependency> <groupId>javax.ws.rs</groupId> @@ -86,11 +68,6 @@ </exclusions> </dependency> <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-test</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.onap.aai.aai-common</groupId> <artifactId>aai-els-onap-logging</artifactId> <scope>compile</scope> @@ -101,6 +78,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <scope>provided</scope> + </dependency> </dependencies> </project> diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java index 3e4eceb4..c4b95090 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java @@ -36,49 +36,15 @@ import org.springframework.util.MultiValueMap; @ConditionalOnExpression("${aai-rest-client.enabled:false}") public class AAIRestClient extends TwoWaySSLRestClient { - private static Logger logger = LoggerFactory.getLogger(AAIRestClient.class); - @Value("${aai.base.url}") private String baseUrl; - @Value("${aai.ssl.key-store}") - private String keystorePath; - - @Value("${aai.ssl.trust-store}") - private String truststorePath; - - @Value("${aai.ssl.key-store-password}") - private String keystorePassword; - - @Value("${aai.ssl.trust-store-password}") - private String truststorePassword; - @Override public String getBaseUrl() { return baseUrl; } @Override - protected String getKeystorePath() { - return keystorePath; - } - - @Override - protected String getTruststorePath() { - return truststorePath; - } - - @Override - protected char[] getKeystorePassword() { - return keystorePassword.toCharArray(); - } - - @Override - protected char[] getTruststorePassword() { - return truststorePassword.toCharArray(); - } - - @Override public MultiValueMap<String, String> getHeaders(Map<String, String> headers) { HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java b/aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java deleted file mode 100644 index 7a1bc110..00000000 --- a/aai-rest/src/main/java/org/onap/aai/restclient/JettyPasswordDecoder.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.aai.restclient; - -import org.eclipse.jetty.util.security.Password; - -public class JettyPasswordDecoder implements PasswordDecoder { - - @Override - public String decode(String input) { - if (input.startsWith("OBF:")) { - return Password.deobfuscate(input); - } - return Password.deobfuscate("OBF:" + input); - } -} diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java index b5585460..09792bbb 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/NoAuthRestClient.java @@ -32,8 +32,6 @@ import org.springframework.web.client.RestTemplate; public abstract class NoAuthRestClient extends RestClient { - private static Logger logger = LoggerFactory.getLogger(NoAuthRestClient.class); - protected RestTemplate restTemplate; @PostConstruct diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java index 614f6770..80d32137 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/OneWaySSLRestClient.java @@ -35,8 +35,6 @@ import org.springframework.web.client.RestTemplate; public abstract class OneWaySSLRestClient extends RestClient { - private static Logger logger = LoggerFactory.getLogger(OneWaySSLRestClient.class); - private RestTemplate restTemplate; @PostConstruct @@ -56,26 +54,19 @@ public abstract class OneWaySSLRestClient extends RestClient { protected HttpClient getClient() throws Exception { - char[] trustStorePassword = getTruststorePassword(); - - String trustStore = getTruststorePath(); - - SSLContext sslContext = SSLContextBuilder.create() - .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword).build(); + SSLContext sslContext = SSLContextBuilder.create().build(); HttpClient client = - HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier((s, sslSession) -> true).build(); + HttpClients.custom() + .setSSLContext(sslContext) + .setSSLHostnameVerifier((s, sslSession) -> true) + .build(); return client; } - protected abstract String getTruststorePath(); - - protected abstract char[] getTruststorePassword(); - @Override public RestTemplate getRestTemplate() { return restTemplate; } - } diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java b/aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java deleted file mode 100644 index a11e2b6c..00000000 --- a/aai-rest/src/main/java/org/onap/aai/restclient/PasswordDecoder.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.aai.restclient; - -public interface PasswordDecoder { - - String decode(String input); -} diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java b/aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java deleted file mode 100644 index a6028f9c..00000000 --- a/aai-rest/src/main/java/org/onap/aai/restclient/PropertyPasswordConfiguration.java +++ /dev/null @@ -1,161 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.aai.restclient; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.Charset; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.EnumerablePropertySource; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.PropertySource; - -public class PropertyPasswordConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext> { - - private static final Pattern decodePasswordPattern = Pattern.compile("password\\((.*?)\\)"); - private PasswordDecoder passwordDecoder = new JettyPasswordDecoder(); - private static final Logger logger = LoggerFactory.getLogger(PropertyPasswordConfiguration.class.getName()); - - @Override - public void initialize(ConfigurableApplicationContext applicationContext) { - ConfigurableEnvironment environment = applicationContext.getEnvironment(); - String certPath = environment.getProperty("server.certs.location"); - File passwordFile = null; - File passphrasesFile = null; - InputStream passwordStream = null; - InputStream passphrasesStream = null; - Map<String, Object> sslProps = new LinkedHashMap<>(); - - // Override the passwords from application.properties if we find AAF certman files - if (certPath != null) { - try { - passwordFile = new File(certPath + ".password"); - passwordStream = new FileInputStream(passwordFile); - - if (passwordStream != null) { - String keystorePassword = null; - - keystorePassword = IOUtils.toString(passwordStream, Charset.defaultCharset()); - if (keystorePassword != null) { - keystorePassword = keystorePassword.trim(); - } - sslProps.put("server.ssl.key-store-password", keystorePassword); - sslProps.put("schema.service.ssl.key-store-password", keystorePassword); - sslProps.put("validation.service.ssl.key-store-password", keystorePassword); - } else { - logger.info("Not using AAF Certman password file"); - } - } catch (IOException e) { - logger.warn("Not using AAF Certman password file, e=" + e.getMessage()); - } finally { - if (passwordStream != null) { - try { - passwordStream.close(); - } catch (Exception e) { - } - } - } - try { - passphrasesFile = new File(certPath + ".passphrases"); - passphrasesStream = new FileInputStream(passphrasesFile); - - if (passphrasesStream != null) { - String truststorePassword = 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); - sslProps.put("schema.service.ssl.trust-store-password", truststorePassword); - sslProps.put("validation.service.ssl.trust-store-password", truststorePassword); - } else { - logger.info("Not using AAF Certman passphrases file"); - } - } catch (IOException e) { - logger.warn("Not using AAF Certman passphrases file, e=" + e.getMessage()); - } finally { - if (passphrasesStream != null) { - try { - passphrasesStream.close(); - } catch (Exception e) { - } - } - } - } - for (PropertySource<?> propertySource : environment.getPropertySources()) { - Map<String, Object> propertyOverrides = new LinkedHashMap<>(); - decodePasswords(propertySource, propertyOverrides); - if (!propertyOverrides.isEmpty()) { - PropertySource<?> decodedProperties = - new MapPropertySource("decoded " + propertySource.getName(), propertyOverrides); - environment.getPropertySources().addBefore(propertySource.getName(), decodedProperties); - } - - } - if (!sslProps.isEmpty()) { - logger.info("Using AAF Certman files"); - PropertySource<?> additionalProperties = new MapPropertySource("additionalProperties", sslProps); - environment.getPropertySources().addFirst(additionalProperties); - } - } - - private void decodePasswords(PropertySource<?> source, Map<String, Object> propertyOverrides) { - if (source instanceof EnumerablePropertySource) { - EnumerablePropertySource<?> enumerablePropertySource = (EnumerablePropertySource<?>) source; - for (String key : enumerablePropertySource.getPropertyNames()) { - Object rawValue = source.getProperty(key); - if (rawValue instanceof String) { - String decodedValue = decodePasswordsInString((String) rawValue); - propertyOverrides.put(key, decodedValue); - } - } - } - } - - private String decodePasswordsInString(String input) { - if (input == null) - return null; - StringBuffer output = new StringBuffer(); - Matcher matcher = decodePasswordPattern.matcher(input); - while (matcher.find()) { - String replacement = passwordDecoder.decode(matcher.group(1)); - matcher.appendReplacement(output, replacement); - } - matcher.appendTail(output); - return output.toString(); - } - -} diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java index 44b1fe44..1b4a3d94 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/RestClient.java @@ -133,9 +133,9 @@ public abstract class RestClient { HttpEntity<String> httpEntity; log.debug("Headers: " + headers.toString()); if (body == null) { - httpEntity = new HttpEntity(getHeaders(headers)); + httpEntity = new HttpEntity<String>(getHeaders(headers)); } else { - httpEntity = new HttpEntity(body, getHeaders(headers)); + httpEntity = new HttpEntity<String>(body, getHeaders(headers)); } String url = getBaseUrl() + uri; return getRestTemplate().exchange(url, method, httpEntity, Resource.class); diff --git a/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java b/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java index 5ea4fc33..7d759107 100644 --- a/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java +++ b/aai-rest/src/main/java/org/onap/aai/restclient/TwoWaySSLRestClient.java @@ -20,11 +20,6 @@ package org.onap.aai.restclient; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.security.KeyStore; - import javax.annotation.PostConstruct; import javax.net.ssl.SSLContext; @@ -32,16 +27,11 @@ import org.apache.http.client.HttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; import org.onap.aai.aailog.filter.RestClientLoggingInterceptor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.util.ResourceUtils; import org.springframework.web.client.RestTemplate; public abstract class TwoWaySSLRestClient extends RestClient { - private static Logger logger = LoggerFactory.getLogger(TwoWaySSLRestClient.class); - private RestTemplate restTemplate; @PostConstruct @@ -60,39 +50,18 @@ public abstract class TwoWaySSLRestClient extends RestClient { protected HttpClient getClient() throws Exception { - char[] keyStorePassword = getKeystorePassword(); - char[] trustStorePassword = getTruststorePassword(); - - String keyStore = getKeystorePath(); - String trustStore = getTruststorePath(); - SSLContext sslContext = - SSLContextBuilder.create().loadKeyMaterial(loadPfx(keyStore, keyStorePassword), keyStorePassword) - .loadTrustMaterial(ResourceUtils.getFile(trustStore), trustStorePassword).build(); + SSLContextBuilder.create().build(); HttpClient client = - HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier((s, sslSession) -> true).build(); + HttpClients.custom() + .setSSLContext(sslContext) + .setSSLHostnameVerifier((s, sslSession) -> true) + .build(); return client; } - private KeyStore loadPfx(String file, char[] password) throws Exception { - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - File key = ResourceUtils.getFile(file); - try (InputStream in = new FileInputStream(key)) { - keyStore.load(in, password); - } - return keyStore; - } - - protected abstract String getKeystorePath(); - - protected abstract String getTruststorePath(); - - protected abstract char[] getTruststorePassword(); - - protected abstract char[] getKeystorePassword(); - @Override public RestTemplate getRestTemplate() { return restTemplate; |