Merge "BB workflow with post instantiation is not working"
[so.git] / adapters / etsi-sol003-adapter / etsi-sol003-package-management / etsi-sol003-package-management-adapter / src / main / java / org / onap / so / adapters / vnfmadapter / packagemanagement / subscriptionmanagement / AbstractNotificationServiceProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Ericsson. All rights reserved.
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.adapters.vnfmadapter.packagemanagement.subscriptionmanagement;
21
22 import static org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmHttpServiceProviderConfiguration.VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN;
23 import java.nio.charset.StandardCharsets;
24 import org.apache.commons.codec.binary.Base64;
25 import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
26 import org.onap.so.rest.service.HttpRestServiceProvider;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.beans.factory.annotation.Qualifier;
29
30 /**
31  * A base class that can be extended by classes for providing notification services. Provides common methods that will
32  * be useful to those classes.
33  *
34  * @author Waqas Ikram (waqas.ikram@est.tech)
35  * @author Andrew Lamb (andrew.a.lamb@est.tech)
36  */
37 public abstract class AbstractNotificationServiceProvider {
38
39     @Autowired
40     @Qualifier(VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN)
41     private HttpRestServiceProvider httpRestServiceProvider;
42
43     protected HttpRestServiceProvider getHttpRestServiceProvider() {
44         return httpRestServiceProvider;
45     }
46
47     protected BasicHttpHeadersProvider getBasicHttpHeadersProviderWithBasicAuth(final String username,
48             final String password) {
49         final byte[] encodedAuth = getBasicAuth(username, password);
50         final String authHeader = "Basic " + new String(encodedAuth);
51         return new BasicHttpHeadersProvider(authHeader);
52     }
53
54     protected byte[] getBasicAuth(final String username, final String password) {
55         final String auth = username + ":" + password;
56         return Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1));
57     }
58
59 }