93432c9f23e71eeff4eadee30ca599a5509ef7e1
[clamp.git] / src / main / java / org / onap / clamp / clds / config / AAFConfiguration.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.config;
24
25 import java.util.Properties;
26
27 import javax.servlet.Filter;
28
29 import org.onap.clamp.clds.filter.ClampCadiFilter;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.boot.web.servlet.FilterRegistrationBean;
32 import org.springframework.context.annotation.Bean;
33 import org.springframework.context.annotation.Configuration;
34 import org.springframework.context.annotation.Profile;
35 import org.springframework.boot.context.properties.ConfigurationProperties;
36 import org.springframework.stereotype.Component;
37
38 @Component
39 @Configuration
40 @Profile("clamp-aaf-authentication")
41 @ConfigurationProperties(prefix = "clamp.config.cadi")
42 public class AAFConfiguration {
43     private static final String CADI_KEY_FILE = "cadi_keyfile";
44     private static final String CADI_LOG_LEVEL = "cadi_loglevel";
45     private static final String LATITUDE = "cadi_latitude";
46     private static final String LONGITUDE = "cadi_longitude";
47     private static final String LOCATE_URL = "aaf_locate_url";
48     private static final String OAUTH_TOKEN_URL = "aaf_oauth2_token_url";
49     private static final String OAUTH_INTROSPECT_URL = "aaf_oauth2_introspect_url";
50     private static final String AAF_ENV = "aaf_env";
51     private static final String AAF_URL = "aaf_url";
52     private static final String X509_ISSUERS = "cadi_x509_issuers";
53         
54     private String              keyFile;
55     private String              cadiLoglevel;
56     private String              cadiLatitude;
57     private String              cadiLongitude;
58     private String              aafLocateUrl;
59     private String              oauthTokenUrl;
60     private String              oauthIntrospectUrl;
61     private String              aafEnv;
62     private String              aafUrl;
63     private String              cadiX509Issuers;
64
65     /**
66      * Method to return clamp cadi filter.
67      * 
68      * @return Filter
69      */
70     @Bean(name = "cadiFilter")
71     public Filter cadiFilter() {
72         return new ClampCadiFilter();
73     }
74
75     /**
76      * Method to register cadi filter.
77      * 
78      * @return FilterRegistrationBean
79      */
80     @Bean
81     public FilterRegistrationBean cadiFilterRegistration() {
82         FilterRegistrationBean registration = new FilterRegistrationBean();
83         registration.setFilter(cadiFilter());
84         registration.addUrlPatterns("/restservices/*");
85         //registration.addUrlPatterns("*");
86         registration.setName("cadiFilter");
87         registration.setOrder(0);
88         return registration;
89     }
90
91         public String getKeyFile() {
92                 return keyFile;
93         }
94
95         public void setKeyFile(String keyFile) {
96                 this.keyFile = keyFile;
97         }
98
99         public String getCadiLoglevel() {
100                 return cadiLoglevel;
101         }
102
103         public void setCadiLoglevel(String cadiLoglevel) {
104                 this.cadiLoglevel = cadiLoglevel;
105         }
106
107         public String getCadiLatitude() {
108                 return cadiLatitude;
109         }
110
111         public void setCadiLatitude(String cadiLatitude) {
112                 this.cadiLatitude = cadiLatitude;
113         }
114
115         public String getCadiLongitude() {
116                 return cadiLongitude;
117         }
118
119         public void setCadiLongitude(String cadiLongitude) {
120                 this.cadiLongitude = cadiLongitude;
121         }
122
123         public String getAafLocateUrl() {
124                 return aafLocateUrl;
125         }
126
127         public void setAafLocateUrl(String aafLocateUrl) {
128                 this.aafLocateUrl = aafLocateUrl;
129         }
130
131         public String getOauthTokenUrl() {
132                 return oauthTokenUrl;
133         }
134
135         public void setOauthTokenUrl(String oauthTokenUrl) {
136                 this.oauthTokenUrl = oauthTokenUrl;
137         }
138
139         public String getOauthIntrospectUrl() {
140                 return oauthIntrospectUrl;
141         }
142
143         public void setOauthIntrospectUrl(String oauthIntrospectUrl) {
144                 this.oauthIntrospectUrl = oauthIntrospectUrl;
145         }
146
147         public String getAafEnv() {
148                 return aafEnv;
149         }
150
151         public void setAafEnv(String aafEnv) {
152                 this.aafEnv = aafEnv;
153         }
154
155         public String getAafUrl() {
156                 return aafUrl;
157         }
158
159         public void setAafUrl(String aafUrl) {
160                 this.aafUrl = aafUrl;
161         }
162
163         public String getCadiX509Issuers() {
164                 return cadiX509Issuers;
165         }
166
167         public void setCadiX509Issuers(String cadiX509Issuers) {
168                 this.cadiX509Issuers = cadiX509Issuers;
169         }
170
171         public Properties getProperties() {
172         Properties prop = System.getProperties();
173         //prop.put("cadi_prop_files", "");
174         prop.put(CADI_KEY_FILE, keyFile);
175         prop.put(CADI_LOG_LEVEL, cadiLoglevel);
176         prop.put(LATITUDE, cadiLatitude);
177         prop.put(LONGITUDE, cadiLongitude);
178         prop.put(LOCATE_URL, aafLocateUrl);
179         if (oauthTokenUrl != null) {
180             prop.put(OAUTH_TOKEN_URL, oauthTokenUrl);
181         }
182         if (oauthIntrospectUrl != null) {
183             prop.put(OAUTH_INTROSPECT_URL, oauthIntrospectUrl);
184         }
185         prop.put(AAF_ENV, aafEnv);
186         prop.put(AAF_URL, aafUrl);
187         prop.put(X509_ISSUERS, cadiX509Issuers);
188         return prop;
189     }
190 }