aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-02-13 14:01:02 +0000
committerGerrit Code Review <gerrit@onap.org>2019-02-13 14:01:02 +0000
commit5b575deb4de10d9520ac7a117702e526e8872c95 (patch)
tree8b1045fb4c808e956bc117f415da054568c39625 /common/src/main
parent1ffa4a397fb51acb09273e2b04b47281f7eb4840 (diff)
parentc8b4ff6dfea3e28ec4d505022453f0730f707a66 (diff)
Merge "use encrypted auth for dmaap"
Diffstat (limited to 'common/src/main')
-rw-r--r--common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java39
-rw-r--r--common/src/main/java/org/onap/so/client/dmaap/rest/DMaaPRestClient.java27
-rw-r--r--common/src/main/java/org/onap/so/client/dmaap/rest/PropertiesBean.java32
-rw-r--r--common/src/main/java/org/onap/so/client/dmaap/rest/RestConsumer.java2
-rw-r--r--common/src/main/java/org/onap/so/client/dmaap/rest/RestPublisher.java2
-rw-r--r--common/src/main/java/org/onap/so/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java8
-rw-r--r--common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java8
-rw-r--r--common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java8
8 files changed, 69 insertions, 57 deletions
diff --git a/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java b/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java
index dde0b31c90..dea00dd08f 100644
--- a/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java
+++ b/common/src/main/java/org/onap/so/client/dmaap/DmaapClient.java
@@ -17,10 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
+
package org.onap.so.client.dmaap;
import java.io.IOException;
+import java.security.GeneralSecurityException;
import java.util.Base64;
import java.util.Map;
import java.util.Optional;
@@ -31,13 +32,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
-
+import org.onap.so.utils.CryptoUtils;
public abstract class DmaapClient {
-
+
protected static Logger logger = LoggerFactory.getLogger(DmaapClient.class);
protected final Map<String, String> msoProperties;
protected final Properties properties;
+
public DmaapClient(String filepath) throws IOException {
Resource resource = new ClassPathResource(filepath);
DmaapProperties dmaapProperties = DmaapPropertiesLoader.getInstance().getNewImpl();
@@ -48,27 +50,34 @@ public abstract class DmaapClient {
this.msoProperties = dmaapProperties.getProperties();
this.properties = new Properties();
this.properties.load(resource.getInputStream());
- this.properties.put("password", this.deobfuscatePassword(this.getPassword()));
- this.properties.put("username", this.getUserName());
+ try {
+ this.properties.put("auth", CryptoUtils.decrypt(this.getAuth(), this.getKey()).getBytes());
+ } catch (GeneralSecurityException e) {
+ logger.error(e.getMessage(), e);
+ }
+ this.properties.put("key", this.getKey());
this.properties.put("topic", this.getTopic());
Optional<String> host = this.getHost();
if (host.isPresent()) {
this.properties.put("host", host.get());
}
}
- protected String deobfuscatePassword(String password) {
-
+
+ protected String deobfuscatePassword(String decrypted_key) {
+
try {
- return new String(Base64.getDecoder().decode(password.getBytes()));
- } catch(IllegalArgumentException iae) {
- logger.error("llegal Arguments",iae);
- return password;
+ return new String(Base64.getDecoder().decode(decrypted_key.getBytes()));
+ } catch (IllegalArgumentException iae) {
+ logger.error("llegal Arguments", iae);
+ return decrypted_key;
}
}
-
-
- public abstract String getUserName();
- public abstract String getPassword();
+
+ public abstract String getKey();
+
+ public abstract String getAuth();
+
public abstract String getTopic();
+
public abstract Optional<String> getHost();
}
diff --git a/common/src/main/java/org/onap/so/client/dmaap/rest/DMaaPRestClient.java b/common/src/main/java/org/onap/so/client/dmaap/rest/DMaaPRestClient.java
index 0438ff237a..9fd8c05cb5 100644
--- a/common/src/main/java/org/onap/so/client/dmaap/rest/DMaaPRestClient.java
+++ b/common/src/main/java/org/onap/so/client/dmaap/rest/DMaaPRestClient.java
@@ -17,34 +17,37 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
+
package org.onap.so.client.dmaap.rest;
import java.net.URL;
-import java.util.Base64;
import java.util.Map;
import org.onap.so.client.RestClient;
+import org.onap.so.utils.CryptoUtils;
import org.onap.so.utils.TargetEntity;
public class DMaaPRestClient extends RestClient {
- private final String username;
- private final String password;
- public DMaaPRestClient(URL url, String contentType, String username, String password) {
+ private final String auth;
+ private final String key;
+
+ public DMaaPRestClient(URL url, String contentType, String auth, String key) {
super(url, contentType);
- this.username = username;
- this.password = password;
+ this.auth = auth;
+ this.key = key;
}
- @Override
- public TargetEntity getTargetEntity(){
- return TargetEntity.DMAAP;
- }
+ @Override
+ public TargetEntity getTargetEntity() {
+ return TargetEntity.DMAAP;
+ }
@Override
protected void initializeHeaderMap(Map<String, String> headerMap) {
- headerMap.put("Authorization", "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes()));
+ if (auth != null && !auth.isEmpty() && key != null && !key.isEmpty()) {
+ addBasicAuthHeader(auth, key);
+ }
}
}
diff --git a/common/src/main/java/org/onap/so/client/dmaap/rest/PropertiesBean.java b/common/src/main/java/org/onap/so/client/dmaap/rest/PropertiesBean.java
index f43c65808a..18849217f8 100644
--- a/common/src/main/java/org/onap/so/client/dmaap/rest/PropertiesBean.java
+++ b/common/src/main/java/org/onap/so/client/dmaap/rest/PropertiesBean.java
@@ -24,8 +24,8 @@ import java.util.Properties;
public class PropertiesBean {
- private String username;
- private String password;
+ private String auth;
+ private String key;
private String environment;
private String partition;
private String contentType;
@@ -35,8 +35,8 @@ public class PropertiesBean {
public PropertiesBean(Properties properties) {
- this.withUsername(properties.getProperty("username"))
- .withPassword(properties.getProperty("password"))
+ this.withAuth(properties.getProperty("auth"))
+ .withKey(properties.getProperty("key"))
.withTopic(properties.getProperty("topic"))
.withEnvironment(properties.getProperty("environment"))
.withHost(properties.getProperty("host"))
@@ -44,24 +44,24 @@ public class PropertiesBean {
.withPartition(properties.getProperty("partition"))
.withContentType(properties.getProperty("contentType", "application/json"));
}
- public String getUsername() {
- return username;
+ public String getAuth() {
+ return auth;
}
- public void setUsername(String username) {
- this.username = username;
+ public void setAuth(String auth) {
+ this.auth = auth;
}
- public PropertiesBean withUsername(String username) {
- this.username = username;
+ public PropertiesBean withAuth(String auth) {
+ this.auth = auth;
return this;
}
- public String getPassword() {
- return password;
+ public String getKey() {
+ return key;
}
- public void setPassword(String password) {
- this.password = password;
+ public void setKey(String key) {
+ this.key = key;
}
- public PropertiesBean withPassword(String password) {
- this.password = password;
+ public PropertiesBean withKey(String key) {
+ this.key = key;
return this;
}
public String getEnvironment() {
diff --git a/common/src/main/java/org/onap/so/client/dmaap/rest/RestConsumer.java b/common/src/main/java/org/onap/so/client/dmaap/rest/RestConsumer.java
index 39af15635a..bee5a0c2ca 100644
--- a/common/src/main/java/org/onap/so/client/dmaap/rest/RestConsumer.java
+++ b/common/src/main/java/org/onap/so/client/dmaap/rest/RestConsumer.java
@@ -37,7 +37,7 @@ public class RestConsumer implements Consumer {
private final RestClient client;
public RestConsumer(Properties properties) {
PropertiesBean bean = new PropertiesBean(properties);
- client = new DMaaPRestClient(this.createURL(bean), bean.getContentType(), bean.getUsername(), bean.getPassword());
+ client = new DMaaPRestClient(this.createURL(bean), bean.getContentType(), bean.getAuth(), bean.getKey());
}
private URL createURL(PropertiesBean properties) {
diff --git a/common/src/main/java/org/onap/so/client/dmaap/rest/RestPublisher.java b/common/src/main/java/org/onap/so/client/dmaap/rest/RestPublisher.java
index 090e50543b..af660c2aa4 100644
--- a/common/src/main/java/org/onap/so/client/dmaap/rest/RestPublisher.java
+++ b/common/src/main/java/org/onap/so/client/dmaap/rest/RestPublisher.java
@@ -35,7 +35,7 @@ public class RestPublisher implements Publisher {
public RestPublisher(Properties properties) {
PropertiesBean bean = new PropertiesBean(properties);
- client = new DMaaPRestClient(this.createURL(bean), bean.getContentType(), bean.getUsername(), bean.getPassword());
+ client = new DMaaPRestClient(this.createURL(bean), bean.getContentType(), bean.getAuth(), bean.getKey());
}
private URL createURL(PropertiesBean properties) {
diff --git a/common/src/main/java/org/onap/so/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java b/common/src/main/java/org/onap/so/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java
index 1d4e014300..93a2d96c5e 100644
--- a/common/src/main/java/org/onap/so/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java
+++ b/common/src/main/java/org/onap/so/client/ruby/dmaap/RubyCreateTicketRequestPublisher.java
@@ -32,13 +32,13 @@ public class RubyCreateTicketRequestPublisher extends DmaapPublisher{
}
@Override
- public String getUserName() {
- return msoProperties.get("ruby.create-ticket-request.dmaap.username");
+ public String getAuth() {
+ return msoProperties.get("ruby.create-ticket-request.dmaap.auth");
}
@Override
- public String getPassword() {
- return msoProperties.get("ruby.create-ticket-request.dmaap.password");
+ public String getKey() {
+ return msoProperties.get("mso.msoKey");
}
@Override
diff --git a/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java b/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java
index 8154b9137d..a76c47c805 100644
--- a/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java
+++ b/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java
@@ -42,13 +42,13 @@ public class SDNOHealthCheckDmaapConsumer extends DmaapConsumer {
}
@Override
- public String getUserName() {
- return msoProperties.get("sdno.health-check.dmaap.username");
+ public String getAuth() {
+ return msoProperties.get("sdno.health-check.dmaap.auth");
}
@Override
- public String getPassword() {
- return msoProperties.get("sdno.health-check.dmaap.password");
+ public String getKey() {
+ return msoProperties.get("mso.msoKey");
}
@Override
diff --git a/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java b/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java
index 2556e67e3c..f4af2052ac 100644
--- a/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java
+++ b/common/src/main/java/org/onap/so/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java
@@ -33,13 +33,13 @@ public class SDNOHealthCheckDmaapPublisher extends DmaapPublisher {
}
@Override
- public String getUserName() {
- return msoProperties.get("sdno.health-check.dmaap.username");
+ public String getAuth() {
+ return msoProperties.get("sdno.health-check.dmaap.auth");
}
@Override
- public String getPassword() {
- return msoProperties.get("sdno.health-check.dmaap.password");
+ public String getKey() {
+ return msoProperties.get("sdno.health-check.dmaap.msoKey");
}
@Override