From e13014323cee3a882da222294a629bb873d9bbef Mon Sep 17 00:00:00 2001 From: mike_xwm Date: Sun, 17 Oct 2021 00:08:23 +0800 Subject: [PATCH] Revert "[Issue #554] Removing hardcoded username and password in the project code (#555)" (#559) This reverts commit e2adda890c31d852231f7a38c6419dda0c32fdb2. --- .../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, 63 insertions(+), 54 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 f599ea29c6..28e944ea30 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 = ""; - public static final String PASSWD = ""; + public static final String USERNAME = "Username"; + public static final String PASSWD = "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 3b831a0f79..0ee7cab899 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,6 +17,9 @@ 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; @@ -24,9 +27,6 @@ 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; + private String username = "username"; - private String passwd; + private String passwd = "user@123"; 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 e6ba1b79fe..6143e4b4bc 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,6 +17,9 @@ 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; @@ -24,9 +27,6 @@ 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; + private String username = "username"; - private String passwd; + private String passwd = "user@123"; 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 d58e8c8499..f5b34564ac 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,6 +17,9 @@ 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; @@ -24,9 +27,6 @@ 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; + private String username = "username"; - private String passwd; + private String passwd = "user@123"; 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 c5b727111d..6d61b8262e 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; + private String username = "username"; //PASSWD of the requester - private String passwd; + private String passwd = "user@123"; 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 d25936e279..769fe4a470 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,6 +17,9 @@ 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; @@ -24,9 +27,6 @@ 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; + private String username = "username"; //PASSWD of the requester - private String passwd; + private String passwd = "user@123"; 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 62cafa4226..88d3c006ce 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,6 +18,9 @@ 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; @@ -25,9 +28,6 @@ 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; + private String username = "username"; //PASSWD of the requester - private String passwd; + private String passwd = "user@123"; 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 b5d2e145e3..aabc2d68e5 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,6 +17,9 @@ 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; @@ -24,9 +27,6 @@ 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; + private String username = "username"; //PASSWD of the requester - private String passwd; + private String passwd = "user@123"; 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 0eeea9afc2..8745fe157c 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,6 +17,9 @@ 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; @@ -24,9 +27,6 @@ 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; + private String username = "username"; //PASSWD of the requester - private String passwd; + private String passwd = "user@123"; 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 174d57b881..728a5a47b5 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,6 +23,9 @@ 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 { @@ -39,5 +42,7 @@ 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 f8625c0e76..e54b641b66 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,6 +44,8 @@ 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); } @@ -57,5 +59,7 @@ 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 c302523fa6..2749816c73 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; + private String userName = "userName"; - private String password; + private String password = "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 000f13b8fa..6128b38fd0 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,12 +17,6 @@ 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; @@ -30,14 +24,20 @@ 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", ""); - String pass = System.getProperty("ssl.client.pass", ""); + String fileName = System.getProperty("ssl.client.cer", "sChat2.jks"); + String pass = System.getProperty("ssl.client.pass", "sNetty"); 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 a3f89e8a82..44ff49f8b3 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 = ""; + public static String EventMesh_USER = "EventMesh"; /** * Password used for EventMesh verification */ - public static String EventMesh_PASS = ""; + public static String EventMesh_PASS = "EventMesh@123"; /** * Timeout time shared by the server