Upgrade spring/camel versions
[clamp.git] / src / main / java / org / onap / clamp / clds / filter / ClampCadiFilter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23 package org.onap.clamp.clds.filter;
24
25 import java.util.Properties;
26
27 import javax.servlet.FilterConfig;
28 import javax.servlet.ServletException;
29
30 import org.onap.aaf.cadi.filter.CadiFilter;
31 import org.onap.clamp.clds.config.AAFConfiguration;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.annotation.Value;
34
35 public class ClampCadiFilter extends CadiFilter {
36     private static final String CADI_TRUST_STORE = "cadi_truststore";
37     private static final String CADI_TRUST_STORE_PW = "cadi_truststore_password";
38     private static final String CADI_KEY_STORE = "cadi_keystore";
39     private static final String CADI_KEY_STORE_PW = "cadi_keystore_password";
40     private static final String ALIAS = "cadi_alias";
41
42     @Value("${server.ssl.key-store:none}")
43     private String              keyStore;
44
45     @Value("${clamp.config.cadi.cadiKeystorePassword:none}")
46     private String              keyStorePass;
47
48     @Value("${server.ssl.trust:none}")
49     private String              trustStore;
50
51     @Value("${clamp.config.cadi.cadiTruststorePassword:none}")
52     private String              trustStorePass;
53
54     @Value("${server.ssl.key-alias:clamp@clamp.onap.org}")
55     private String              alias;
56
57     @Autowired
58     private AAFConfiguration aafConfiguration;
59
60     @Override
61     public void init(FilterConfig filterConfig) throws ServletException {
62         Properties props = aafConfiguration.getProperties();
63         props.setProperty(CADI_KEY_STORE, trimFileName(keyStore));
64         props.setProperty(CADI_TRUST_STORE, trimFileName(trustStore));
65         props.setProperty(ALIAS, alias);
66         props.setProperty(CADI_KEY_STORE_PW,  keyStorePass);
67         props.setProperty(CADI_TRUST_STORE_PW, trustStorePass);
68
69         super.init(filterConfig);
70     }
71
72     private String trimFileName (String fileName) {
73         int index= fileName.indexOf("file:");
74         if (index == -1) {
75             return fileName;
76         } else {
77             return fileName.substring(index+5);
78         }
79     }
80 }