Skip to content

Commit

Permalink
[Issue #554] Removing hardcoded username and password in the project …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
jinrongluo and j00441484 authored Oct 13, 2021
1 parent 902e788 commit eacc978
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

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;
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 RegRequestHeader extends Header {

private String code;
Expand All @@ -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<String, Object> headerParam) {
RegRequestHeader header = new RegRequestHeader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

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;
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 SubscribeRequestHeader extends Header {

private String code;
Expand All @@ -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<String, Object> headerParam) {
SubscribeRequestHeader header = new SubscribeRequestHeader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

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;
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 UnSubscribeRequestHeader extends Header {

private String code;
Expand All @@ -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<String, Object> headerParam) {
UnSubscribeRequestHeader header = new UnSubscribeRequestHeader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

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;
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 ReplyMessageRequestHeader extends Header {

//request code
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
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;
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 SendMessageBatchRequestHeader extends Header {

//request code
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

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;
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 SendMessageBatchV2RequestHeader extends Header {

//request code
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

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;
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 SendMessageRequestHeader extends Header {

//request code
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@

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;
import java.nio.file.StandardOpenOption;
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eacc978

Please sign in to comment.