diff options
author | Ioannis Sotiropoulos <Ioannis.Sotiropoulos@amdocs.com> | 2018-08-21 15:14:19 +0100 |
---|---|---|
committer | Ioannis Sotiropoulos <Ioannis.Sotiropoulos@amdocs.com> | 2018-08-21 15:31:06 +0100 |
commit | 08ded90b8c72fba3b75eec4dbf6f1603d6ab2340 (patch) | |
tree | 54f8387d9168232f6af34036508642bcb9c3db87 /src | |
parent | 84707925fec2e8998cc66888fbaa8d1960a68ed0 (diff) |
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 <Ioannis.Sotiropoulos@amdocs.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/onap/crud/CrudApplication.java | 24 |
1 files changed, 24 insertions, 0 deletions
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"); + } + } + } } |