diff options
author | Rob Daugherty <rd472p@att.com> | 2018-12-06 22:51:41 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-12-06 22:51:41 +0000 |
commit | baf3f278fce6bcc15b4db1219be66e091530b1ee (patch) | |
tree | e64f58040457339b5a99ca8ab0f0739678b35761 /common/src/main/java/org | |
parent | 3e54398897655230f1a524321ac4783f332a4bd4 (diff) | |
parent | 7882eaefffb7f4927f2bde9fb9ab91582004cc66 (diff) |
Merge "grm clients use encrypted auth loading"
Diffstat (limited to 'common/src/main/java/org')
5 files changed, 14 insertions, 87 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; } |