From 08ded90b8c72fba3b75eec4dbf6f1603d6ab2340 Mon Sep 17 00:00:00 2001 From: Ioannis Sotiropoulos Date: Tue, 21 Aug 2018 15:14:19 +0100 Subject: [PATCH] Set trust store Set required system parameters to specify the correct trust store to use for outgoing HTTPS connections. Change-Id: I455c5c217a976c3b99cc8ff28883f34215caf47c Issue-ID: AAI-1526 Signed-off-by: Ioannis Sotiropoulos --- src/main/java/org/onap/crud/CrudApplication.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/onap/crud/CrudApplication.java b/src/main/java/org/onap/crud/CrudApplication.java index d1446ba..008ff3f 100644 --- a/src/main/java/org/onap/crud/CrudApplication.java +++ b/src/main/java/org/onap/crud/CrudApplication.java @@ -22,11 +22,14 @@ package org.onap.crud; import java.util.HashMap; import java.util.Map; +import javax.annotation.PostConstruct; import org.eclipse.jetty.util.security.Password; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.context.annotation.ImportResource; +import org.springframework.core.env.Environment; /** * Crud application class - SpringApplication.run @@ -34,6 +37,9 @@ import org.springframework.context.annotation.ImportResource; @SpringBootApplication @ImportResource({"file:${SERVICE_BEANS}/*.xml"}) public class CrudApplication extends SpringBootServletInitializer{// NOSONAR + @Autowired + private Environment env; + public static void main(String[] args) {// NOSONAR String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD"); if(keyStorePassword==null || keyStorePassword.isEmpty()){ @@ -43,4 +49,22 @@ public class CrudApplication extends SpringBootServletInitializer{// NOSONAR props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword)); new CrudApplication().configure(new SpringApplicationBuilder(CrudApplication.class).properties(props)).run(args); } + + /** + * Set required trust store system properties using values from application.properties + */ + @PostConstruct + public void setSystemProperties() { + String trustStorePath = env.getProperty("server.ssl.key-store"); + if (trustStorePath != null) { + String trustStorePassword = env.getProperty("server.ssl.key-store-password"); + + if (trustStorePassword != null) { + System.setProperty("javax.net.ssl.trustStore", trustStorePath); + System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword); + } else { + throw new IllegalArgumentException("Env property server.ssl.key-store-password not set"); + } + } + } } -- 2.16.6