4ae1d431b4c343d9460a1c8b9acc7c368d71f88e
[so/adapters/so-cnf-adapter.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 Nordix Foundation.
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  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.cnfm.lcm.bpmn.flows.extclients.sdc;
21
22 import java.nio.charset.StandardCharsets;
23 import java.security.GeneralSecurityException;
24 import org.apache.commons.codec.binary.Base64;
25 import org.onap.so.cnfm.lcm.bpmn.flows.exceptions.BasicAuthConfigException;
26 import org.onap.so.utils.CryptoUtils;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.context.annotation.Configuration;
31
32 /**
33  * @author Waqas Ikram (waqas.ikram@est.tech)
34  *
35  */
36 @Configuration
37 public class SdcClientConfigurationProvider {
38
39     private static final Logger logger = LoggerFactory.getLogger(SdcClientConfigurationProvider.class);
40
41     @Value("${sdc.username:mso}")
42     private String sdcUsername;
43
44     @Value("${sdc.password:76966BDD3C7414A03F7037264FF2E6C8EEC6C28F2B67F2840A1ED857C0260FEE731D73F47F828E5527125D29FD25D3E0DE39EE44C058906BF1657DE77BF897EECA93BDC07FA64F}")
45     private String sdcPassword;
46
47     @Value("${sdc.key:566B754875657232314F5548556D3665}")
48     private String sdcKey;
49
50     @Value("${sdc.endpoint:https://sdc-be.onap:8443}")
51     private String baseUrl;
52
53     private static String basicAuth = null;
54
55
56     public String getBasicAuth() {
57         if (basicAuth == null) {
58             synchronized (this) {
59                 if (basicAuth == null) {
60                     try {
61                         final String auth = sdcUsername + ":" + CryptoUtils.decrypt(sdcPassword, sdcKey);
62                         final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1));
63                         basicAuth = "Basic " + new String(encodedAuth);
64                     } catch (final GeneralSecurityException exception) {
65                         logger.error("Unable to process basic auth information", exception);
66                         throw new BasicAuthConfigException("Unable to process basic auth information", exception);
67                     }
68                 }
69             }
70         }
71         return basicAuth;
72     }
73
74     public String getSdcPackageUrl(final String packageId) {
75         return baseUrl + "/sdc/v1/catalog/resources/" + packageId + "/toscaModel";
76
77     }
78
79 }