9849db380f2c2ab4e9c613099e8fcd42066537a1
[so.git] / common / src / main / java / org / onap / so / security / SoCadiFilter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP SO
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.so.security;
24
25 import javax.servlet.FilterConfig;
26 import javax.servlet.ServletException;
27 import org.onap.aaf.cadi.config.Config;
28 import org.onap.aaf.cadi.filter.CadiFilter;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Value;
32 import org.springframework.context.annotation.Profile;
33 import org.springframework.stereotype.Component;
34
35 @Component
36 @Profile("!test & aaf")
37 public class SoCadiFilter extends CadiFilter {
38
39     protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class);
40
41     private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT";
42     private static String AAF_API_VERSION = "aaf_api_version";
43
44     @Value("${mso.config.cadi.cadiLoglevel:#{null}}")
45     private String cadiLoglevel;
46
47     @Value("${mso.config.cadi.cadiKeyFile:#{null}}")
48     private String cadiKeyFile;
49
50     @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}")
51     private String cadiTrustStorePassword;
52
53     @Value("${mso.config.cadi.cadiTrustStore:#{null}}")
54     private String cadiTrustStore;
55
56     @Value("${mso.config.cadi.cadiLatitude:#{null}}")
57     private String cadiLatitude;
58
59     @Value("${mso.config.cadi.cadiLongitude:#{null}}")
60     private String cadiLongitude;
61
62     @Value("${mso.config.cadi.aafEnv:#{null}}")
63     private String aafEnv;
64
65     @Value("${mso.config.cadi.aafApiVersion:#{null}}")
66     private String aafApiVersion;
67
68     @Value("${mso.config.cadi.aafRootNs:#{null}}")
69     private String aafRootNs;
70
71     @Value("${mso.config.cadi.aafId:#{null}}")
72     private String aafMechId;
73
74     @Value("${mso.config.cadi.aafPassword:#{null}}")
75     private String aafMechIdPassword;
76
77     @Value("${mso.config.cadi.aafLocateUrl:#{null}}")
78     private String aafLocateUrl;
79
80     @Value("${mso.config.cadi.aafUrl:#{null}}")
81     private String aafUrl;
82
83     @Value("${mso.config.cadi.apiEnforcement:#{null}}")
84     private String apiEnforcement;
85
86     @Value("${mso.config.cadi.userExpires:#{null}}")
87     private String userExpires;
88
89     private void checkIfNullProperty(String key, String value) {
90         /*
91          * When value is null, it is not defined in application.yaml set nothing in System properties
92          */
93         if (value != null) {
94             System.setProperty(key, value);
95         }
96     }
97
98     @Override
99     public void init(FilterConfig filterConfig) throws ServletException {
100         checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel);
101         checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile);
102         checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore);
103         checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword);
104         checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude);
105         checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude);
106         checkIfNullProperty(Config.AAF_ENV, aafEnv);
107         checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion);
108         checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs);
109         checkIfNullProperty(Config.AAF_APPID, aafMechId);
110         checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword);
111         checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl);
112         checkIfNullProperty(Config.AAF_URL, aafUrl);
113         checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement);
114         checkIfNullProperty(Config.AAF_USER_EXPIRES, userExpires);
115         // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv);
116         logger.debug(" *** init Filter Config *** ");
117         super.init(filterConfig);
118     }
119
120
121 }