From: Ioannis Sotiropoulos Date: Tue, 21 Aug 2018 14:14:19 +0000 (+0100) Subject: Set trust store X-Git-Tag: 1.3.0~4 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F09%2F61609%2F2;p=aai%2Fgizmo.git 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 --- 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"); + } + } + } }