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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=====================================================
18 package org.onap.sdnc.apps.pomba.servicedecomposition;
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.context.annotation.Conditional;
26 import org.springframework.stereotype.Component;
29 public class AAIConfiguration {
30 @Value("${aai.serviceName}")
33 @Value("${aai.servicePort}")
36 @Value("${aai.username}")
37 private String aaiUsername;
39 @Value("${aai.password}")
40 private String aaiPassword;
42 @Value("${aai.httpProtocol}")
43 private String httpProtocol;
45 @Value("${aai.securityProtocol}")
46 private String securityProtocol;
48 @Value("${aai.authentication}")
49 private String authenticationMode;
51 @Value("${aai.trustStorePath}")
52 private String trustStorePath;
54 @Value("${aai.keyStorePath}")
55 private String keyStorePath;
57 @Value("${aai.keyStorePassword}")
58 private String keyStorePassword;
60 @Value("${aai.connectionTimeout}")
61 private Integer connectionTimeout;
63 @Value("${aai.readTimeout}")
64 private Integer readTimeout;
66 @Value("${aai.serviceInstancePath}")
67 private String serviceInstancePath;
69 @Value("${aai.resourceList}")
70 private String resourceList;
72 @Value("${basicAuth.username:admin}")
73 private String username;
75 @Value("${basicAuth.password:OBF:1u2a1toa1w8v1tok1u30}")
76 private String password;
78 @Bean(name="aaiBasicAuthorization")
79 public String getAAIBasicAuth() {
80 return "Basic " + Base64.getEncoder().encodeToString((this.aaiUsername + ":" + Password.deobfuscate(this.aaiPassword)).getBytes());
83 @Bean(name="basicAuthHeader")
84 public String getSdBasicAuthHeader() {
85 return "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + Password.deobfuscate(this.password)).getBytes());
88 @Conditional(AAIBasicAuthCondition.class)
89 @Bean(name="aaiClient")
90 public RestClient restClientWithBasicAuth() {
91 return new RestClient()
92 .validateServerHostname(false)
93 .validateServerCertChain(false)
94 .basicAuthPassword(aaiUsername)
95 .basicAuthPassword(Password.deobfuscate(aaiPassword))
96 .connectTimeoutMs(this.connectionTimeout)
97 .readTimeoutMs(this.readTimeout);
100 @Conditional(AAIClientCertCondition.class)
101 @Bean(name="aaiClient")
102 public RestClient restClientWithClientCert() {
103 RestClient restClient = new RestClient();
104 System.out.println("in client cert");
105 if (httpProtocol.equals("https"))
106 restClient.validateServerHostname(false).validateServerCertChain(false).trustStore(trustStorePath).clientCertFile(keyStorePath).clientCertPassword(keyStorePassword).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout);
108 restClient.validateServerHostname(false).validateServerCertChain(false).connectTimeoutMs(connectionTimeout).readTimeoutMs(readTimeout);
112 @Bean(name="aaiBaseUrl")
113 public String getURL() {
114 return this.httpProtocol + "://" + this.host + ":" + this.port;
117 @Bean(name="aaiServiceInstancePath")
118 public String getServiceInstancePath() {
119 return this.serviceInstancePath;
122 @Bean(name="aaiResourceList")
123 public String getResourceList() {
124 return this.resourceList;