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
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.adapters.etsi.sol003.adapter.packagemanagement.subscriptionmanagement;
22 import static org.slf4j.LoggerFactory.getLogger;
23 import org.onap.so.adapters.etsi.sol003.adapter.packagemanagement.model.SubscriptionsAuthentication;
24 import org.onap.so.adapters.etsi.sol003.adapter.packagemanagement.model.SubscriptionsAuthentication.AuthTypeEnum;
25 import org.onap.so.configuration.rest.HttpHeadersProvider;
26 import org.onap.so.rest.service.HttpRestServiceProvider;
27 import org.slf4j.Logger;
28 import org.springframework.http.ResponseEntity;
29 import org.springframework.stereotype.Service;
32 * Implementation of a NotificationServiceProvider which supports Basic Authentication
34 * @author Waqas Ikram (waqas.ikram@est.tech)
35 * @author Andrew Lamb (andrew.a.lamb@est.tech)
38 public class BasicAuthNotificationServiceProvider extends AbstractNotificationServiceProvider
39 implements NotificationServiceProvider {
41 private static final Logger logger = getLogger(BasicAuthNotificationServiceProvider.class);
44 public boolean send(final Object notification, final SubscriptionsAuthentication subscriptionsAuthentication,
45 final String callbackUri) {
46 logger.info("Sending notification to uri: {}", callbackUri);
47 final HttpHeadersProvider httpHeadersProvider =
48 getBasicHttpHeadersProviderWithBasicAuth(subscriptionsAuthentication.getParamsBasic().getUserName(),
49 subscriptionsAuthentication.getParamsBasic().getPassword());
50 final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider();
52 final ResponseEntity<Void> responseEntity = httpRestServiceProvider.postHttpRequest(notification, callbackUri,
53 httpHeadersProvider.getHttpHeaders(), Void.class);
54 if (responseEntity.getStatusCode().is2xxSuccessful()) {
55 logger.info("Notification sent successfully.");
59 logger.error("Failed to send notification.");
64 public AuthTypeEnum getAuthType() {
65 return AuthTypeEnum.BASIC;