2 * Copyright (C) 2019 Bell Canada. All rights reserved.
4 * NOTICE: All the intellectual and technical concepts contained herein are
5 * proprietary to Bell Canada and are protected by trade secret or copyright law.
6 * Unauthorized copying of this file, via any medium is strictly prohibited.
9 package org.onap.ccsdk.cds.cdssdclistener.client;
11 import io.grpc.CallOptions;
12 import io.grpc.Channel;
13 import io.grpc.ClientCall;
14 import io.grpc.ClientInterceptor;
15 import io.grpc.ForwardingClientCall;
16 import io.grpc.Metadata;
17 import io.grpc.Metadata.Key;
18 import io.grpc.MethodDescriptor;
19 import org.springframework.beans.factory.annotation.Value;
20 import org.springframework.boot.context.properties.ConfigurationProperties;
21 import org.springframework.stereotype.Component;
24 * To provide authentication with GRPC server.
26 @ConfigurationProperties("listenerservice")
28 public class CdsSdcListenerAuthClientInterceptor implements ClientInterceptor {
30 @Value("${listenerservice.config.authHeader}")
31 private String basicAuth;
34 public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> methodDescriptor,
35 CallOptions callOptions, Channel channel) {
36 Key<String> authHeader = Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER);
37 return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
38 channel.newCall(methodDescriptor, callOptions)) {
40 public void start(Listener<RespT> responseListener, Metadata headers) {
41 headers.put(authHeader, basicAuth);
42 super.start(responseListener, headers);