2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 European Software Marketing Ltd.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.aaf.cadi.sidecar.fproxy;
22 import java.util.HashMap;
23 import java.util.Optional;
24 import javax.annotation.PostConstruct;
25 import org.eclipse.jetty.util.security.Password;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.boot.autoconfigure.SpringBootApplication;
28 import org.springframework.boot.builder.SpringApplicationBuilder;
29 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
30 import org.springframework.context.annotation.PropertySource;
31 import org.springframework.core.env.Environment;
33 @SpringBootApplication
34 @PropertySource("file:${CONFIG_HOME}/fproxy.properties")
35 public class FProxyApplication extends SpringBootServletInitializer {
38 private Environment env;
41 public interface AppProperty {
42 String getProperty(String p);
46 * Spring Boot initialization.
48 * @param args main args
50 public static void main(String[] args) {
51 AppProperty appProp = (String propertyName) -> Optional.ofNullable(System.getProperty(propertyName))
52 .orElseThrow(() -> new IllegalArgumentException("Env property " + propertyName + " not set"));
54 HashMap<String, Object> props = new HashMap<>();
55 props.put("server.ssl.key-store-password", Password.deobfuscate(appProp.getProperty("KEY_STORE_PASSWORD")));
56 props.put("server.ssl.trust-store-password", Password.deobfuscate(appProp.getProperty("TRUST_STORE_PASSWORD")));
57 new FProxyApplication().configure(new SpringApplicationBuilder(FProxyApplication.class).properties(props))
62 * Set required trust and key store system properties using values from application.properties
65 public void setSystemProperties() {
66 AppProperty appProp = (String propertyName) -> Optional.ofNullable(env.getProperty(propertyName))
67 .orElseThrow(() -> new IllegalArgumentException("Env property " + propertyName + " not set"));
69 System.setProperty("javax.net.ssl.keyStore", appProp.getProperty("server.ssl.key-store"));
70 System.setProperty("javax.net.ssl.keyStorePassword", appProp.getProperty("server.ssl.key-store-password"));
71 System.setProperty("javax.net.ssl.trustStore", appProp.getProperty("server.ssl.trust-store"));
72 System.setProperty("javax.net.ssl.trustStorePassword", appProp.getProperty("server.ssl.trust-store-password"));