Update application class to handle https 69/64469/1
authormichaere <michaere@amdocs.com>
Tue, 4 Sep 2018 15:57:48 +0000 (16:57 +0100)
committermichaere <michaere@amdocs.com>
Tue, 4 Sep 2018 15:57:48 +0000 (16:57 +0100)
Provide a secure connection to the event client for async flow

Issue-ID: AAI-1562

Change-Id: I686e2e6cf4ba88751455627d2755d18ea571f1f4
Signed-off-by: michaere <michaere@amdocs.com>
src/main/java/org/onap/aai/datarouter/Application.java

index 5abe7f3..245797c 100644 (file)
 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<String, Object> 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