aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKalkere Ramesh, Sharan (sk720x) <sk720x@att.com>2018-12-06 15:36:24 -0500
committerKalkere Ramesh, Sharan (sk720x) <sk720x@att.com>2018-12-06 15:41:20 -0500
commit7882eaefffb7f4927f2bde9fb9ab91582004cc66 (patch)
tree5d746f5c85d11281225b78f6de6d8d3e6521bb14
parentf4eb1ccfa197b1a96195a6179a8290435ba02fd2 (diff)
grm clients use encrypted auth loading
Change-Id: I328e7c0913acf3d84d4a51ba9b9237ec337b0ee1 Issue-ID: SO-1288 Signed-off-by: Kalkere Ramesh, Sharan (sk720x) <sk720x@att.com>
-rw-r--r--common/src/main/java/org/onap/so/client/grm/GRMClient.java2
-rw-r--r--common/src/main/java/org/onap/so/client/grm/GRMDefaultPropertiesImpl.java63
-rw-r--r--common/src/main/java/org/onap/so/client/grm/GRMProperties.java4
-rw-r--r--common/src/main/java/org/onap/so/client/grm/GRMRestClient.java17
-rw-r--r--common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java15
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java19
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java (renamed from common/src/test/java/org/onap/so/client/grm/GRMClientTest.java)28
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json145
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml3
9 files changed, 181 insertions, 115 deletions
diff --git a/common/src/main/java/org/onap/so/client/grm/GRMClient.java b/common/src/main/java/org/onap/so/client/grm/GRMClient.java
index 84e25b9ce4..653e1cc7b3 100644
--- a/common/src/main/java/org/onap/so/client/grm/GRMClient.java
+++ b/common/src/main/java/org/onap/so/client/grm/GRMClient.java
@@ -53,7 +53,7 @@ public class GRMClient {
}
}
- protected ServiceEndPointLookupRequest buildServiceEndPointlookupRequest(String name, int majorVersion, String env) {
+ public ServiceEndPointLookupRequest buildServiceEndPointlookupRequest(String name, int majorVersion, String env) {
VersionLookup version = new VersionLookup();
version.setMajor(majorVersion);
diff --git a/common/src/main/java/org/onap/so/client/grm/GRMDefaultPropertiesImpl.java b/common/src/main/java/org/onap/so/client/grm/GRMDefaultPropertiesImpl.java
deleted file mode 100644
index b38072e769..0000000000
--- a/common/src/main/java/org/onap/so/client/grm/GRMDefaultPropertiesImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.client.grm;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.ws.rs.core.MediaType;
-
-public class GRMDefaultPropertiesImpl implements GRMProperties {
-
- public GRMDefaultPropertiesImpl() {
- }
-
- @Override
- public URL getEndpoint() throws MalformedURLException {
- return new URL("http://localhost:47389");
- }
-
- @Override
- public String getSystemName() {
- return "MSO";
- }
-
- @Override
- public String getDefaultVersion() {
- return "v1";
- }
-
- @Override
- public String getUsername() {
- return "gmruser";
- }
-
- @Override
- public String getPassword() {
- return "cGFzc3dvcmQ=";
- }
-
- @Override
- public String getContentType() {
- return MediaType.APPLICATION_JSON;
- }
-
-}
diff --git a/common/src/main/java/org/onap/so/client/grm/GRMProperties.java b/common/src/main/java/org/onap/so/client/grm/GRMProperties.java
index da9f215aac..1206896bf9 100644
--- a/common/src/main/java/org/onap/so/client/grm/GRMProperties.java
+++ b/common/src/main/java/org/onap/so/client/grm/GRMProperties.java
@@ -24,7 +24,7 @@ import org.onap.so.client.RestProperties;
public interface GRMProperties extends RestProperties {
public String getDefaultVersion();
- public String getUsername();
- public String getPassword();
+ public String getAuth();
+ public String getKey();
public String getContentType();
}
diff --git a/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java b/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java
index ce16ccaaaa..0bb55e627a 100644
--- a/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java
+++ b/common/src/main/java/org/onap/so/client/grm/GRMRestClient.java
@@ -32,13 +32,11 @@ import org.onap.so.utils.TargetEntity;
public class GRMRestClient extends RestClient {
- private final String username;
- private final String password;
+ private final GRMProperties properties;
- public GRMRestClient(RestProperties props, URI path, String username, String password) {
- super(props, Optional.of(path));
- this.username = username;
- this.password = password;
+ public GRMRestClient(GRMProperties props, URI path) {
+ super(props, Optional.of(path));
+ this.properties = props;
}
@Override
@@ -48,7 +46,12 @@ public class GRMRestClient extends RestClient {
@Override
protected void initializeHeaderMap(Map<String, String> headerMap) {
- headerMap.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(new String(username + ":" + password).getBytes()));
+ String auth = properties.getAuth();
+ String key = properties.getKey();
+
+ if (auth != null && !auth.isEmpty() && key != null && !key.isEmpty()) {
+ addBasicAuthHeader(auth, key);
+ }
}
}
diff --git a/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java b/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java
index 3045cb35f4..0c95a66979 100644
--- a/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java
+++ b/common/src/main/java/org/onap/so/client/grm/GRMRestInvoker.java
@@ -21,7 +21,6 @@
package org.onap.so.client.grm;
import java.net.URI;
-import java.util.Base64;
import javax.ws.rs.core.UriBuilder;
@@ -34,11 +33,8 @@ public class GRMRestInvoker {
public GRMRestInvoker(GRMAction action) {
GRMProperties props = GRMPropertiesLoader.getInstance().getImpl();
- if (props == null) {
- props = new GRMDefaultPropertiesImpl();
- }
this.properties = props;
- this.client = new GRMRestClient(this.properties, this.createURI(action), this.properties.getUsername(), this.decode(this.properties.getPassword()));
+ this.client = new GRMRestClient(properties, this.createURI(action));
}
private URI createURI(GRMAction action) {
@@ -49,15 +45,6 @@ public class GRMRestInvoker {
.build();
}
- private String decode(String cred) {
- try {
- return new String(Base64.getDecoder().decode(cred.getBytes()));
- }
- catch(IllegalArgumentException iae) {
- return cred;
- }
- }
-
private RestClient getClient() {
return this.client;
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
index f83e707258..60a05d74e5 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java
@@ -32,15 +32,14 @@ import org.springframework.context.ApplicationContext;
public class GrmClientPropertiesImpl implements GRMProperties {
private String grmEndpoint;
- private String grmUsername;
- private String grmPassword;
+ private String grmAuth;
+ private String grmKey;
public GrmClientPropertiesImpl() {
- ApplicationContext context = SpringContextHelper.getAppContext();
-
+ ApplicationContext context = SpringContextHelper.getAppContext();
grmEndpoint = context.getEnvironment().getProperty("mso.grm.endpoint");
- grmUsername = context.getEnvironment().getProperty("mso.grm.username");
- grmPassword = context.getEnvironment().getProperty("mso.grm.password");
+ grmAuth = context.getEnvironment().getProperty("mso.grm.auth");
+ grmKey = context.getEnvironment().getProperty("mso.msoKey");
}
@Override
@@ -59,13 +58,13 @@ public class GrmClientPropertiesImpl implements GRMProperties {
}
@Override
- public String getUsername() {
- return grmUsername;
+ public String getAuth() {
+ return grmAuth;
}
@Override
- public String getPassword() {
- return grmPassword;
+ public String getKey() {
+ return grmKey;
}
@Override
diff --git a/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java
index 388e89a438..6555a9a66e 100644
--- a/common/src/test/java/org/onap/so/client/grm/GRMClientTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java
@@ -1,5 +1,5 @@
/*-
- * ============LICENSE_START=======================================================
+ * ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
@@ -25,10 +25,10 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -40,29 +40,26 @@ import java.util.Map;
import javax.ws.rs.core.MediaType;
-
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.apihandlerinfra.BaseTest;
+import org.onap.so.apihandlerinfra.TestAppender;
+import org.onap.so.client.grm.GRMClient;
import org.onap.so.client.grm.beans.ServiceEndPoint;
import org.onap.so.client.grm.beans.ServiceEndPointList;
import org.onap.so.client.grm.beans.ServiceEndPointLookupRequest;
import org.onap.so.client.grm.beans.ServiceEndPointRequest;
import org.onap.so.client.grm.exceptions.GRMClientCallFailed;
-import org.onap.so.utils.TestAppender;
import org.slf4j.MDC;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.github.tomakehurst.wiremock.junit.WireMockRule;
-
import ch.qos.logback.classic.spi.ILoggingEvent;
-public class GRMClientTest {
+
+public class GRMClientTest extends BaseTest{
- @Rule
- public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(47389));
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -78,7 +75,7 @@ public class GRMClientTest {
public void testFind() throws Exception {
TestAppender.events.clear();
String endpoints = getFileContentsAsString("__files/grm/endpoints.json");
- wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning"))
+ stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", MediaType.APPLICATION_JSON)
@@ -94,7 +91,7 @@ public class GRMClientTest {
boolean foundInvokeReturn = false;
for(ILoggingEvent logEvent : TestAppender.events)
if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") &&
- logEvent.getMarker().getName().equals("INVOKE")
+ logEvent.getMarker() != null && logEvent.getMarker().getName().equals("INVOKE")
){
Map<String,String> mdc = logEvent.getMDCPropertyMap();
assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
@@ -124,9 +121,8 @@ public class GRMClientTest {
}
@Test
- public void testFindFail() throws Exception {
-
- wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning"))
+ public void testFindFail() throws Exception {
+ stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning"))
.willReturn(aResponse()
.withStatus(400)
.withHeader("Content-Type", MediaType.APPLICATION_JSON)
@@ -139,7 +135,7 @@ public class GRMClientTest {
@Test
public void testAddFail() throws Exception {
- wireMockRule.stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add"))
+ stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add"))
.willReturn(aResponse()
.withStatus(404)
.withHeader("Content-Type", MediaType.APPLICATION_JSON)
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json
new file mode 100644
index 0000000000..7e92c21c9e
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json
@@ -0,0 +1,145 @@
+{
+ "serviceEndPointList": [
+ {
+ "name": "dummy.pod.ns.dummy-pod3",
+ "version": {
+ "major": 1,
+ "minor": 0,
+ "patch": "0"
+ },
+ "hostAddress": "192.168.120.218",
+ "listenPort": "32004",
+ "latitude": "37.7022",
+ "longitude": "121.9358",
+ "registrationTime": "2017-07-18T15:39:17.367+0000",
+ "expirationTime": "9999-10-09T15:39:17.368+0000",
+ "contextPath": "/",
+ "routeOffer": "DEFAULT",
+ "statusInfo": {
+ "status": "RUNNING"
+ },
+ "eventStatusInfo": {
+ "status": "RUNNING"
+ },
+ "validatorStatusInfo": {
+ "status": "RUNNING"
+ },
+ "operationalInfo": {
+ "createdBy": "edge",
+ "updatedBy": "edge",
+ "createdTimestamp": "2017-07-18T15:39:17.367+0000",
+ "updatedTimestamp": "2017-07-18T15:39:17.367+0000"
+ },
+ "protocol": "dummypod-port",
+ "properties": [
+ {
+ "name": "Environment",
+ "value": "DEV"
+ },
+ {
+ "name": "Kubernetes Namespace",
+ "value": "dummy-pod-ns"
+ },
+ {
+ "name": "cpfrun_cluster_name",
+ "value": "CI-PDK1-TFINIT-CJ9125401"
+ }
+ ],
+ "disableType": []
+ },
+ {
+ "name": "dummy.pod.ns.dummy-pod3",
+ "version": {
+ "major": 1,
+ "minor": 0,
+ "patch": "0"
+ },
+ "hostAddress": "192.168.120.22",
+ "listenPort": "32004",
+ "latitude": "1.0",
+ "longitude": "1.0",
+ "registrationTime": "2017-07-18T15:39:17.816+0000",
+ "expirationTime": "9999-10-09T15:39:17.817+0000",
+ "contextPath": "/",
+ "routeOffer": "DEFAULT",
+ "statusInfo": {
+ "status": "RUNNING"
+ },
+ "eventStatusInfo": {
+ "status": "RUNNING"
+ },
+ "validatorStatusInfo": {
+ "status": "RUNNING"
+ },
+ "operationalInfo": {
+ "createdBy": "edge",
+ "updatedBy": "edge",
+ "createdTimestamp": "2017-07-18T15:39:17.816+0000",
+ "updatedTimestamp": "2017-07-18T15:39:17.816+0000"
+ },
+ "protocol": "dummypod-port",
+ "properties": [
+ {
+ "name": "Environment",
+ "value": "DEV"
+ },
+ {
+ "name": "Kubernetes Namespace",
+ "value": "dummy-pod-ns"
+ },
+ {
+ "name": "cpfrun_cluster_name",
+ "value": "CI-PDK1-TFINIT-CJ9125401"
+ }
+ ],
+ "disableType": []
+ },
+ {
+ "name": "dummy.pod.ns.dummy-pod1",
+ "version": {
+ "major": 1,
+ "minor": 0,
+ "patch": "0"
+ },
+ "hostAddress": "192.168.120.218",
+ "listenPort": "32002",
+ "latitude": "1.0",
+ "longitude": "1.0",
+ "registrationTime": "2017-07-18T15:39:14.443+0000",
+ "expirationTime": "9999-10-09T15:39:14.453+0000",
+ "contextPath": "/",
+ "routeOffer": "DEFAULT",
+ "statusInfo": {
+ "status": "RUNNING"
+ },
+ "eventStatusInfo": {
+ "status": "RUNNING"
+ },
+ "validatorStatusInfo": {
+ "status": "RUNNING"
+ },
+ "operationalInfo": {
+ "createdBy": "edge",
+ "updatedBy": "edge",
+ "createdTimestamp": "2017-07-18T15:39:14.443+0000",
+ "updatedTimestamp": "2017-07-18T15:39:14.443+0000"
+ },
+ "protocol": "dummypod-port",
+ "properties": [
+ {
+ "name": "Environment",
+ "value": "DEV"
+ },
+ {
+ "name": "Kubernetes Namespace",
+ "value": "dummy-pod-ns"
+ },
+ {
+ "name": "cpfrun_cluster_name",
+ "value": "CI-PDK1-TFINIT-CJ9125401"
+ }
+ ],
+ "disableType": []
+ }
+ ]
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
index 6e1d6f3376..63eb0534ea 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml
@@ -70,8 +70,7 @@ mso:
auth: 5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C
grm:
endpoint: http://localhost:${wiremock.server.port}
- username: gmruser
- password: test
+ auth: 6AAD26000E278148A0B987436D9696A5B2D99BBF0DC545F9E64D6DF05298FFA987A6CF565F6F274EBC085678
so:
operational-environment:
dmaap: