2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 Bell Canada.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.cds;
23 import io.grpc.CallOptions;
24 import io.grpc.Channel;
25 import io.grpc.ClientCall;
26 import io.grpc.ClientCall.Listener;
27 import io.grpc.ClientInterceptor;
28 import io.grpc.ForwardingClientCall;
29 import io.grpc.Metadata;
30 import io.grpc.Metadata.Key;
31 import io.grpc.MethodDescriptor;
33 public class BasicAuthClientInterceptor implements ClientInterceptor {
35 private CDSProperties props;
37 public BasicAuthClientInterceptor(CDSProperties props) {
42 public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
43 CallOptions callOptions, Channel channel) {
45 Key<String> authHeader = Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER);
47 return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(channel.newCall(method, callOptions)) {
49 public void start(Listener<RespT> responseListener, Metadata headers) {
50 headers.put(authHeader, props.getBasicAuth());
51 super.start(responseListener, headers);