ac5849b80f92c3ac867208532a49b7f4fb57aafd
[clamp.git] / src / main / java / org / onap / clamp / clds / config / spring / SSLConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * ===================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END============================================
21  * ===================================================================
22  *
23  */
24
25 package org.onap.clamp.clds.config.spring;
26
27 import java.net.URL;
28
29 import javax.annotation.PostConstruct;
30
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.annotation.Configuration;
33 import org.springframework.core.env.Environment;
34
35 @Configuration
36 public class SSLConfiguration {
37     @Autowired
38     private Environment env;
39
40     @PostConstruct
41     private void configureSSL() {
42         if (env.getProperty("server.ssl.trust-store") != null) {
43             URL storeResource = SSLConfiguration.class
44                 .getResource(env.getProperty("server.ssl.trust-store").replaceAll("classpath:", ""));
45             System.setProperty("javax.net.ssl.trustStore", storeResource.getPath());
46             System.setProperty("javax.net.ssl.trustStorePassword", env.getProperty("server.ssl.trust-store-password"));
47             System.setProperty("javax.net.ssl.trustStoreType", env.getProperty("server.ssl.key-store-type"));
48
49             storeResource = SSLConfiguration.class
50                 .getResource(env.getProperty("server.ssl.key-store").replaceAll("classpath:", ""));
51             System.setProperty("javax.net.ssl.keyStore", storeResource.getPath());
52             System.setProperty("javax.net.ssl.keyStorePassword", env.getProperty("server.ssl.key-store-password"));
53             System.setProperty("javax.net.ssl.keyStoreType", env.getProperty("server.ssl.key-store-type"));
54         }
55     }
56 }