2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
23 package org.onap.clamp.clds.filter;
25 import javax.servlet.FilterConfig;
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;
41 import org.springframework.beans.factory.annotation.Value;
43 import org.onap.aaf.cadi.filter.CadiFilter;
44 import org.onap.clamp.clds.config.AAFConfiguration;
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";
53 @Value("${server.ssl.key-store:none}")
54 private String keyStore;
56 @Value("${clamp.config.cadi.cadiKeystorePassword:none}")
57 private String keyStorePass;
59 @Value("${server.ssl.trust:none}")
60 private String trustStore;
62 @Value("${clamp.config.cadi.cadiTruststorePassword:none}")
63 private String trustStorePass;
65 @Value("${server.ssl.key-alias:clamp@clamp.onap.org}")
69 private AAFConfiguration aafConfiguration;
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);
80 super.init(filterConfig);
83 private String trimFileName (String fileName) {
84 int index= fileName.indexOf("file:");
88 return fileName.substring(index+5);