Merge "Fix the docker push"
[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 javax.servlet.FilterConfig;
26
27 import java.io.IOException;
28 import java.security.Principal;
29 import java.security.cert.X509Certificate;
30 import java.util.Properties;
31 import javax.servlet.FilterChain;
32 import javax.servlet.ServletException;
33 import javax.servlet.ServletRequest;
34 import javax.servlet.ServletResponse;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpSession;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.security.core.context.SecurityContextImpl;
39 import org.springframework.security.core.userdetails.UserDetails;
40
41 import org.springframework.beans.factory.annotation.Value;
42
43 import org.onap.aaf.cadi.filter.CadiFilter;
44 import org.onap.clamp.clds.config.AAFConfiguration;
45
46 public class ClampCadiFilter extends CadiFilter {
47     private static final String CADI_TRUST_STORE = "cadi_truststore";
48     private static final String CADI_TRUST_STORE_PW = "cadi_truststore_password";
49     private static final String CADI_KEY_STORE = "cadi_keystore";
50     private static final String CADI_KEY_STORE_PW = "cadi_keystore_password";
51     private static final String ALIAS = "cadi_alias";
52
53     @Value("${server.ssl.key-store:none}")
54     private String              keyStore;
55     
56     @Value("${clamp.config.cadi.cadiKeystorePassword:none}")
57     private String              keyStorePass;
58
59     @Value("${server.ssl.trust:none}")
60     private String              trustStore;
61     
62     @Value("${clamp.config.cadi.cadiTruststorePassword:none}")
63     private String              trustStorePass;
64
65     @Value("${server.ssl.key-alias:clamp@clamp.onap.org}")
66     private String              alias;
67
68     @Autowired
69     private AAFConfiguration aafConfiguration;
70     
71     @Override
72     public void init(FilterConfig filterConfig) throws ServletException {
73         Properties props = aafConfiguration.getProperties();
74         props.setProperty(CADI_KEY_STORE, trimFileName(keyStore));
75         props.setProperty(CADI_TRUST_STORE, trimFileName(trustStore));
76         props.setProperty(ALIAS, alias);
77         props.setProperty(CADI_KEY_STORE_PW,  keyStorePass);
78         props.setProperty(CADI_TRUST_STORE_PW, trustStorePass);
79
80         super.init(filterConfig);
81     }
82
83     private String trimFileName (String fileName) {
84         int index= fileName.indexOf("file:");
85         if (index == -1) { 
86             return fileName;
87         } else {
88             return fileName.substring(index+5);
89         }
90     }
91 }