aboutsummaryrefslogtreecommitdiffstats
path: root/sidecar/fproxy/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'sidecar/fproxy/src/main/java')
-rw-r--r--sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/FProxyApplication.java45
-rw-r--r--sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/RestTemplateConfig.java14
2 files changed, 30 insertions, 29 deletions
diff --git a/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/FProxyApplication.java b/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/FProxyApplication.java
index 7e3ffe4..9ca301a 100644
--- a/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/FProxyApplication.java
+++ b/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/FProxyApplication.java
@@ -20,6 +20,7 @@
package org.onap.aaf.cadi.sidecar.fproxy;
import java.util.HashMap;
+import java.util.Optional;
import javax.annotation.PostConstruct;
import org.eclipse.jetty.util.security.Password;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,40 +36,40 @@ public class FProxyApplication extends SpringBootServletInitializer {
@Autowired
private Environment env;
-
+
+ @FunctionalInterface
+ public interface AppProperty {
+ String getProperty(String p);
+ }
+
/**
- * Spring Boot Initialization.
- *
+ * Spring Boot initialization.
+ *
* @param args main args
*/
public static void main(String[] args) {
- String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD");
- if (keyStorePassword == null || keyStorePassword.isEmpty()) {
- throw new IllegalArgumentException("Env property KEY_STORE_PASSWORD not set");
- }
+ AppProperty appProp = (String propertyName) -> Optional.ofNullable(System.getProperty(propertyName))
+ .orElseThrow(() -> new IllegalArgumentException("Env property " + propertyName + " not set"));
+
HashMap<String, Object> props = new HashMap<>();
- props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword));
+ props.put("server.ssl.key-store-password", Password.deobfuscate(appProp.getProperty("KEY_STORE_PASSWORD")));
+ props.put("server.ssl.trust-store-password", Password.deobfuscate(appProp.getProperty("TRUST_STORE_PASSWORD")));
new FProxyApplication().configure(new SpringApplicationBuilder(FProxyApplication.class).properties(props))
.run(args);
}
-
+
/**
- * Set required trust store system properties using values from application.properties
+ * Set required trust and key store system properties using values from application.properties
*/
@PostConstruct
public void setSystemProperties() {
- String keyStorePath = env.getProperty("server.ssl.key-store");
- if (keyStorePath != null) {
- String keyStorePassword = env.getProperty("server.ssl.key-store-password");
+ AppProperty appProp = (String propertyName) -> Optional.ofNullable(env.getProperty(propertyName))
+ .orElseThrow(() -> new IllegalArgumentException("Env property " + propertyName + " not set"));
- if (keyStorePassword != null) {
- System.setProperty("javax.net.ssl.keyStore", keyStorePath);
- System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
- System.setProperty("javax.net.ssl.trustStore", keyStorePath);
- System.setProperty("javax.net.ssl.trustStorePassword", keyStorePassword);
- } else {
- throw new IllegalArgumentException("Env property server.ssl.key-store-password not set");
- }
- }
+ System.setProperty("javax.net.ssl.keyStore", appProp.getProperty("server.ssl.key-store"));
+ System.setProperty("javax.net.ssl.keyStorePassword", appProp.getProperty("server.ssl.key-store-password"));
+ System.setProperty("javax.net.ssl.trustStore", appProp.getProperty("server.ssl.trust-store"));
+ System.setProperty("javax.net.ssl.trustStorePassword", appProp.getProperty("server.ssl.trust-store-password"));
}
+
}
diff --git a/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/RestTemplateConfig.java b/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/RestTemplateConfig.java
index 23f3471..33ecb7e 100644
--- a/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/RestTemplateConfig.java
+++ b/sidecar/fproxy/src/main/java/org/onap/aaf/cadi/sidecar/fproxy/RestTemplateConfig.java
@@ -45,11 +45,11 @@ public class RestTemplateConfig {
@Value("${server.ssl.client-cert-password}")
private String clientCertPassword;
- @Value("${server.ssl.key-store}")
- private String keystorePath;
+ @Value("${server.ssl.trust-store}")
+ private String trustStorePath;
- @Value("${server.ssl.key-store-password}")
- private String keystorePassword;
+ @Value("${server.ssl.trust-store-password}")
+ private String trustStorePassword;
@Profile("secure")
@Bean
@@ -66,11 +66,11 @@ public class RestTemplateConfig {
}
private HttpClientBuilder getClientBuilder() throws GeneralSecurityException, IOException {
+ char[] clientPassword = Password.deobfuscate(clientCertPassword).toCharArray();
SSLContext sslContext = SSLContextBuilder.create()
- .loadKeyMaterial(ResourceUtils.getFile(clientCertPath), Password.deobfuscate(clientCertPassword).toCharArray(),
- keystorePassword.toCharArray())
- .loadTrustMaterial(ResourceUtils.getFile(keystorePath), keystorePassword.toCharArray()).build();
+ .loadKeyMaterial(ResourceUtils.getFile(clientCertPath), clientPassword, clientPassword)
+ .loadTrustMaterial(ResourceUtils.getFile(trustStorePath), trustStorePassword.toCharArray()).build();
return HttpClients.custom().setSSLContext(sslContext);
}