aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-03-04 21:44:35 -0500
committerMarcus Williams <marcus.williams@intel.com>2019-03-06 15:58:15 +0000
commit9434bf784aae4fa85fd2e1b99145b403643327ab (patch)
tree313ad692797a2344818390d08ca775f71fc77769
parent91426ec9f221e288ea3f54fa62030e6f17420b90 (diff)
Add support for CDS basic-auth
Change-Id: I22834f989afb748917aa2099b1da78c5f794bbe5 Issue-ID: CCSDK-1055 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/CDSPropertiesImpl.java6
-rw-r--r--common/src/main/java/org/onap/so/client/cds/BasicAuthClientInterceptor.java53
-rw-r--r--common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java1
-rw-r--r--common/src/main/java/org/onap/so/client/cds/CDSProperties.java3
-rw-r--r--common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java9
5 files changed, 70 insertions, 2 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/CDSPropertiesImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/CDSPropertiesImpl.java
index b8ab588a75..dfdef74886 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/CDSPropertiesImpl.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/restproperties/CDSPropertiesImpl.java
@@ -24,6 +24,7 @@ public class CDSPropertiesImpl implements CDSProperties {
private static final String ENDPOINT = "cds.endpoint";
private static final String PORT = "cds.port";
+ private static final String AUTH = "cds.auth";
public CDSPropertiesImpl() {
// Needed for service loader
@@ -40,6 +41,11 @@ public class CDSPropertiesImpl implements CDSProperties {
}
@Override
+ public String getBasicAuth() {
+ return Objects.requireNonNull(UrnPropertiesReader.getVariable(AUTH));
+ }
+
+ @Override
public URL getEndpoint() {
return null;
}
diff --git a/common/src/main/java/org/onap/so/client/cds/BasicAuthClientInterceptor.java b/common/src/main/java/org/onap/so/client/cds/BasicAuthClientInterceptor.java
new file mode 100644
index 0000000000..384d479501
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/cds/BasicAuthClientInterceptor.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2019 Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.so.client.cds;
+
+import io.grpc.CallOptions;
+import io.grpc.Channel;
+import io.grpc.ClientCall;
+import io.grpc.ClientCall.Listener;
+import io.grpc.ClientInterceptor;
+import io.grpc.ForwardingClientCall;
+import io.grpc.Metadata;
+import io.grpc.Metadata.Key;
+import io.grpc.MethodDescriptor;
+
+public class BasicAuthClientInterceptor implements ClientInterceptor {
+
+ private CDSProperties props;
+
+ public BasicAuthClientInterceptor(CDSProperties props) {
+ this.props = props;
+ }
+
+ @Override
+ public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
+ MethodDescriptor<ReqT, RespT> method,
+ CallOptions callOptions,
+ Channel channel) {
+
+ Key<String> authHeader = Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER);
+
+ return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
+ channel.newCall(method, callOptions)) {
+ @Override
+ public void start(Listener<RespT> responseListener, Metadata headers) {
+ headers.put(authHeader, props.getBasicAuth());
+ super.start(responseListener, headers);
+ }
+ };
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java b/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java
index 0901cf589b..1e372112f1 100644
--- a/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java
+++ b/common/src/main/java/org/onap/so/client/cds/CDSProcessingClient.java
@@ -73,6 +73,7 @@ public class CDSProcessingClient implements AutoCloseable {
.forAddress(props.getHost(), props.getPort())
.nameResolverFactory(new DnsNameResolverProvider())
.loadBalancerFactory(new PickFirstLoadBalancerProvider())
+ .intercept(new BasicAuthClientInterceptor(props))
.usePlaintext()
.build();
this.handler = new CDSProcessingHandler(listener);
diff --git a/common/src/main/java/org/onap/so/client/cds/CDSProperties.java b/common/src/main/java/org/onap/so/client/cds/CDSProperties.java
index bb2a54ec98..52d1d614ed 100644
--- a/common/src/main/java/org/onap/so/client/cds/CDSProperties.java
+++ b/common/src/main/java/org/onap/so/client/cds/CDSProperties.java
@@ -21,5 +21,8 @@ import org.onap.so.client.RestProperties;
public interface CDSProperties extends RestProperties {
String getHost();
+
int getPort();
+
+ String getBasicAuth();
}
diff --git a/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java b/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java
index efb9b07871..a2937869c8 100644
--- a/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java
+++ b/common/src/test/java/org/onap/so/client/cds/TestCDSPropertiesImpl.java
@@ -26,12 +26,17 @@ public class TestCDSPropertiesImpl implements CDSProperties {
@Override
public String getHost() {
- return "endpoint";
+ return "localhost";
}
@Override
public int getPort() {
- return 9999;
+ return 9111;
+ }
+
+ @Override
+ public String getBasicAuth() {
+ return "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw==";
}
@Override