From e2adda890c31d852231f7a38c6419dda0c32fdb2 Mon Sep 17 00:00:00 2001 From: jinrongluo Date: Wed, 13 Oct 2021 07:50:15 -0400 Subject: [PATCH] [Issue #554] Removing hardcoded username and password in the project code (#555) * [Issue #337] Fix HttpSubscriber startup issue * [Issue #337] test commit * [Issue #337] revert test commit * [Issue #337] Enhance Http Demo Subscriber by using ExecutorService, CountDownLatch and PreDestroy hook * [Issue #337] Enhance Http Demo Subscriber by using ExecutorService, CountDownLatch and PreDestroy hook * [Issue #337] Address code review comment for Subscriber Demo App * [Issue #554] Removing hardcoded username and password in the project code Co-authored-by: j00441484 --- .../common/protocol/http/common/ProtocolKey.java | 4 ++-- .../http/header/client/RegRequestHeader.java | 10 +++++----- .../header/client/SubscribeRequestHeader.java | 10 +++++----- .../header/client/UnSubscribeRequestHeader.java | 10 +++++----- .../message/PushMessageResponseHeader.java | 10 +++++----- .../message/ReplyMessageRequestHeader.java | 10 +++++----- .../message/SendMessageBatchRequestHeader.java | 10 +++++----- .../message/SendMessageBatchV2RequestHeader.java | 10 +++++----- .../header/message/SendMessageRequestHeader.java | 10 +++++----- .../message/PushMessageResponseHeaderTest.java | 5 ----- .../message/ReplyMessageRequestHeaderTest.java | 4 ---- .../client/http/conf/LiteClientConfig.java | 4 ++-- .../client/http/ssl/MyX509TrustManager.java | 16 ++++++++-------- .../client/tcp/common/EventMeshCommon.java | 4 ++-- 14 files changed, 54 insertions(+), 63 deletions(-) diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java index 28e944ea30..f599ea29c6 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/common/ProtocolKey.java @@ -30,8 +30,8 @@ public static class ClientInstanceKey { public static final String SYS = "Sys"; public static final String PID = "Pid"; public static final String IP = "Ip"; - public static final String USERNAME = "Username"; - public static final String PASSWD = "Passwd"; + public static final String USERNAME = ""; + public static final String PASSWD = ""; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java index 0ee7cab899..3b831a0f79 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -27,6 +24,9 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class RegRequestHeader extends Header { private String code; @@ -45,9 +45,9 @@ public class RegRequestHeader extends Header { private String ip; - private String username = "username"; + private String username; - private String passwd = "user@123"; + private String passwd; public static RegRequestHeader buildHeader(Map headerParam) { RegRequestHeader header = new RegRequestHeader(); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java index 6143e4b4bc..e6ba1b79fe 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -27,6 +24,9 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SubscribeRequestHeader extends Header { private String code; @@ -45,9 +45,9 @@ public class SubscribeRequestHeader extends Header { private String ip; - private String username = "username"; + private String username; - private String passwd = "user@123"; + private String passwd; public static SubscribeRequestHeader buildHeader(Map headerParam) { SubscribeRequestHeader header = new SubscribeRequestHeader(); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java index f5b34564ac..d58e8c8499 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -27,6 +24,9 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class UnSubscribeRequestHeader extends Header { private String code; @@ -45,9 +45,9 @@ public class UnSubscribeRequestHeader extends Header { private String ip; - private String username = "username"; + private String username; - private String passwd = "user@123"; + private String passwd; public static UnSubscribeRequestHeader buildHeader(Map headerParam) { UnSubscribeRequestHeader header = new UnSubscribeRequestHeader(); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java index 6d61b8262e..c5b727111d 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeader.java @@ -18,14 +18,14 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class PushMessageResponseHeader extends Header { //response code @@ -53,10 +53,10 @@ public class PushMessageResponseHeader extends Header { private String ip; //USERNAME of the requester - private String username = "username"; + private String username; //PASSWD of the requester - private String passwd = "user@123"; + private String passwd; public String getUsername() { return username; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java index 769fe4a470..d25936e279 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -27,6 +24,9 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class ReplyMessageRequestHeader extends Header { //request code @@ -54,10 +54,10 @@ public class ReplyMessageRequestHeader extends Header { private String ip; //USERNAME of the requester - private String username = "username"; + private String username; //PASSWD of the requester - private String passwd = "user@123"; + private String passwd; public String getUsername() { return username; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java index 88d3c006ce..62cafa4226 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java @@ -18,9 +18,6 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -28,6 +25,9 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SendMessageBatchRequestHeader extends Header { //request code @@ -55,10 +55,10 @@ public class SendMessageBatchRequestHeader extends Header { private String ip; //USERNAME of the requester - private String username = "username"; + private String username; //PASSWD of the requester - private String passwd = "user@123"; + private String passwd; public String getUsername() { return username; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java index aabc2d68e5..b5d2e145e3 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -27,6 +24,9 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SendMessageBatchV2RequestHeader extends Header { //request code @@ -54,10 +54,10 @@ public class SendMessageBatchV2RequestHeader extends Header { private String ip; //USERNAME of the requester - private String username = "username"; + private String username; //PASSWD of the requester - private String passwd = "user@123"; + private String passwd; public String getUsername() { return username; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java index 8745fe157c..0eeea9afc2 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; @@ -27,6 +24,9 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SendMessageRequestHeader extends Header { //request code @@ -54,10 +54,10 @@ public class SendMessageRequestHeader extends Header { private String ip; //USERNAME of the requester - private String username = "username"; + private String username; //PASSWD of the requester - private String passwd = "user@123"; + private String passwd; public String getUsername() { return username; diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java index 728a5a47b5..174d57b881 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java @@ -23,9 +23,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.HashMap; -import java.util.Map; - import static org.hamcrest.CoreMatchers.is; public class PushMessageResponseHeaderTest { @@ -42,7 +39,5 @@ public void testToMap() { Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.SYS), is("SYSID")); Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PID), is("PID")); Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.IP), is("127.0.0.1")); - Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.USERNAME), is("username")); - Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PASSWD), is("user@123")); } } diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java index e54b641b66..f8625c0e76 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java @@ -44,8 +44,6 @@ public void before() { headerParam.put(ProtocolKey.ClientInstanceKey.SYS, "SYS"); headerParam.put(ProtocolKey.ClientInstanceKey.PID, "PID"); headerParam.put(ProtocolKey.ClientInstanceKey.IP, "127.0.0.1"); - headerParam.put(ProtocolKey.ClientInstanceKey.USERNAME, "username"); - headerParam.put(ProtocolKey.ClientInstanceKey.PASSWD, "user@123"); header = ReplyMessageRequestHeader.buildHeader(headerParam); } @@ -59,7 +57,5 @@ public void testToMap() { Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.SYS), is("SYS")); Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PID), is("PID")); Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.IP), is("127.0.0.1")); - Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.USERNAME), is("username")); - Assert.assertThat(header.toMap().get(ProtocolKey.ClientInstanceKey.PASSWD), is("user@123")); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java index 2749816c73..c302523fa6 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/conf/LiteClientConfig.java @@ -52,9 +52,9 @@ public class LiteClientConfig { private String sys; - private String userName = "userName"; + private String userName; - private String password = "password"; + private String password; private boolean useTls = false; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java index 6128b38fd0..000f13b8fa 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java @@ -17,6 +17,12 @@ package org.apache.eventmesh.client.http.ssl; +import org.apache.commons.lang3.StringUtils; + +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; @@ -24,20 +30,14 @@ import java.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509TrustManager; - -import org.apache.commons.lang3.StringUtils; public class MyX509TrustManager implements X509TrustManager { X509TrustManager myTrustManager; public MyX509TrustManager() throws Exception { KeyStore keyStore = KeyStore.getInstance("JKS"); - String fileName = System.getProperty("ssl.client.cer", "sChat2.jks"); - String pass = System.getProperty("ssl.client.pass", "sNetty"); + String fileName = System.getProperty("ssl.client.cer", ""); + String pass = System.getProperty("ssl.client.pass", ""); char[] filePass = null; if (StringUtils.isNotBlank(pass)) { filePass = pass.toCharArray(); diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/EventMeshCommon.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/EventMeshCommon.java index 44ff49f8b3..a3f89e8a82 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/EventMeshCommon.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/EventMeshCommon.java @@ -52,12 +52,12 @@ public class EventMeshCommon { /** * Username used for EventMesh verification */ - public static String EventMesh_USER = "EventMesh"; + public static String EventMesh_USER = ""; /** * Password used for EventMesh verification */ - public static String EventMesh_PASS = "EventMesh@123"; + public static String EventMesh_PASS = ""; /** * Timeout time shared by the server