a163d2d21ee0614cfee9fc8dce8e79c19509cfdc
[sdnc/apps.git] /
1 /*
2  * ============LICENSE_START===================================================
3  * Copyright (c) 2018 Amdocs
4  * ============================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=====================================================
17  */
18 package org.onap.sdnc.apps.pomba.servicedecomposition;
19
20 import java.util.Base64;
21 import org.eclipse.jetty.util.security.Password;
22 import org.onap.aai.restclient.client.RestClient;
23 import org.springframework.beans.factory.annotation.Value;
24 import org.springframework.context.annotation.Bean;
25 import org.springframework.stereotype.Component;
26
27 @Component
28 public class AAIConfiguration {
29     @Value("${aai.serviceName}")
30     private String host;
31
32     @Value("${aai.servicePort}")
33     private String port;
34
35     @Value("${aai.username}")
36     private String aaiUsername;
37
38     @Value("${aai.password}")
39     private String aaiPassword;
40
41     @Value("${aai.httpProtocol}")
42     private String httpProtocol;
43
44     @Value("${aai.securityProtocol}")
45     private String securityProtocol;
46
47     @Value("${aai.connectionTimeout}")
48     private Integer connectionTimeout;
49
50     @Value("${aai.readTimeout}")
51     private Integer readTimeout;
52
53     @Value("${aai.serviceInstancePath}")
54     private String serviceInstancePath;
55
56     @Value("${aai.resourceList}")
57     private String resourceList;
58
59     @Value("${basicAuth.username:admin}")
60     private String username;
61
62     @Value("${basicAuth.password:OBF:1u2a1toa1w8v1tok1u30}")
63     private String password;
64
65     @Bean(name="aaiBasicAuthorization")
66     public String getAAIBasicAuth() {
67         return "Basic " + Base64.getEncoder().encodeToString((this.aaiUsername + ":" + Password.deobfuscate(this.aaiPassword)).getBytes());
68     }
69
70     @Bean(name="basicAuthHeader")
71     public String getSdBasicAuthHeader() {
72         return "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + Password.deobfuscate(this.password)).getBytes());
73     }
74
75     @Bean(name="aaiClient")
76     public RestClient restClient() {
77         return new RestClient()
78                 .validateServerHostname(false)
79                 .validateServerCertChain(false)
80                 .basicAuthPassword(aaiUsername)
81                 .basicAuthPassword(Password.deobfuscate(aaiPassword))
82                 .connectTimeoutMs(this.connectionTimeout)
83                 .readTimeoutMs(this.readTimeout);
84     }
85
86     @Bean(name="aaiBaseUrl")
87     public String getURL() {
88         return this.httpProtocol + "://" + this.host + ":" + this.port;
89     }
90
91     @Bean(name="aaiServiceInstancePath")
92     public String getServiceInstancePath() {
93         return this.serviceInstancePath;
94     }
95
96     @Bean(name="aaiResourceList")
97     public String getResourceList() {
98         return this.resourceList;
99     }
100 }