From 89a0e48dce48a915682000b90de43b70871aff75 Mon Sep 17 00:00:00 2001 From: michaere Date: Tue, 4 Sep 2018 16:57:48 +0100 Subject: [PATCH] Update application class to handle https Provide a secure connection to the event client for async flow Issue-ID: AAI-1562 Change-Id: I686e2e6cf4ba88751455627d2755d18ea571f1f4 Signed-off-by: michaere --- .../java/org/onap/aai/datarouter/Application.java | 40 +++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/onap/aai/datarouter/Application.java b/src/main/java/org/onap/aai/datarouter/Application.java index 5abe7f3..245797c 100644 --- a/src/main/java/org/onap/aai/datarouter/Application.java +++ b/src/main/java/org/onap/aai/datarouter/Application.java @@ -21,21 +21,26 @@ package org.onap.aai.datarouter; import java.util.HashMap; - +import javax.annotation.PostConstruct; import org.apache.camel.component.servlet.CamelHttpTransportServlet; 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.servlet.ServletRegistrationBean; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.context.annotation.Bean; +import org.springframework.core.env.Environment; @SpringBootApplication public class Application extends SpringBootServletInitializer{ - - private static final String CAMEL_URL_MAPPING = "/*"; - private static final String CAMEL_SERVLET_NAME = "CamelServlet"; + + private static final String CAMEL_URL_MAPPING = "/*"; + private static final String CAMEL_SERVLET_NAME = "CamelServlet"; + + @Autowired + private Environment env; public static void main(String[] args) { String keyStorePassword = System.getenv("KEY_STORE_PASSWORD"); @@ -45,10 +50,10 @@ public class Application extends SpringBootServletInitializer{ HashMap props = new HashMap<>(); props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword)); new Application().configure(new SpringApplicationBuilder(Application.class).properties(props)).run(args); - - + + } - + @Bean public ServletRegistrationBean getServletRegistrationBean() { ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(), CAMEL_URL_MAPPING); @@ -56,5 +61,24 @@ public class Application extends SpringBootServletInitializer{ return registration; } - + /** + * 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"); + } + } + } + + + } \ No newline at end of file -- 2.16.6