d226dc8ff2c2ab7e63bfe1c13395bbbb4798f977
[aaf/cadi.git] / sidecar / fproxy / src / main / java / org / onap / aaf / fproxy / FProxyApplication.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aaf
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
10  *
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.aaf.fproxy;
21
22 import java.util.HashMap;
23 import javax.annotation.PostConstruct;
24 import org.eclipse.jetty.util.security.Password;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.boot.autoconfigure.SpringBootApplication;
27 import org.springframework.boot.builder.SpringApplicationBuilder;
28 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
29 import org.springframework.context.annotation.PropertySource;
30 import org.springframework.core.env.Environment;
31
32 @SpringBootApplication
33 @PropertySource("file:${CONFIG_HOME}/fproxy.properties")
34 public class FProxyApplication extends SpringBootServletInitializer {
35
36     @Autowired
37     private Environment env;
38     
39     /**
40      * Spring Boot Initialization.
41      * 
42      * @param args main args
43      */
44     public static void main(String[] args) {
45         String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD");
46         if (keyStorePassword == null || keyStorePassword.isEmpty()) {
47             throw new IllegalArgumentException("Env property KEY_STORE_PASSWORD not set");
48         }
49         HashMap<String, Object> props = new HashMap<>();
50         props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword));
51         new FProxyApplication().configure(new SpringApplicationBuilder(FProxyApplication.class).properties(props))
52                 .run(args);
53     }
54     
55     /**
56      * Set required trust store system properties using values from application.properties
57      */
58     @PostConstruct
59     public void setSystemProperties() {
60         String keyStorePath = env.getProperty("server.ssl.key-store");
61         if (keyStorePath != null) {
62             String keyStorePassword = env.getProperty("server.ssl.key-store-password");
63
64             if (keyStorePassword != null) {
65                 System.setProperty("javax.net.ssl.keyStore", keyStorePath);
66                 System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
67                 System.setProperty("javax.net.ssl.trustStore", keyStorePath);
68                 System.setProperty("javax.net.ssl.trustStorePassword", keyStorePassword);
69             } else {
70                 throw new IllegalArgumentException("Env property server.ssl.key-store-password not set");
71             }
72         }
73     }
74 }