eca5240cb5d1ce46c8e91304c5f023fddc3ad1c1
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SO
4  * ================================================================================
5  * Copyright (C) 2020 Samsung. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.vevnfm.provider;
22
23 import java.util.List;
24 import org.apache.logging.log4j.util.Strings;
25 import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
26 import org.springframework.http.HttpHeaders;
27
28 public class AuthorizationHeadersProvider extends BasicHttpHeadersProvider {
29
30     private List<String> previousAuthorization;
31
32     public void addAuthorization(final String authorization) {
33         final HttpHeaders headers = getHttpHeaders();
34         previousAuthorization = headers.get(AUTHORIZATION_HEADER);
35         headers.set(AUTHORIZATION_HEADER, authorization);
36     }
37
38     public void resetPrevious() {
39         if (!isPreviousAuthorizationBlank()) {
40             getHttpHeaders().addAll(AUTHORIZATION_HEADER, previousAuthorization);
41         }
42     }
43
44     private boolean isPreviousAuthorizationBlank() {
45         return previousAuthorization == null || previousAuthorization.isEmpty()
46                 || Strings.isBlank(previousAuthorization.get(0));
47     }
48 }