[AMQ-8413] Add remoteUserName and remotePassword config fields to network connector (#725)

This commit is contained in:
Matt Pavlovich 2021-12-20 08:36:56 -06:00
parent 485d32fe40
commit c58e531584
4 changed files with 71 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import org.apache.activemq.network.NetworkConnector;
public class NetworkConnectorView implements NetworkConnectorViewMBean { public class NetworkConnectorView implements NetworkConnectorViewMBean {
private static final String PASSWORD_MASK = "****";
private final NetworkConnector connector; private final NetworkConnector connector;
public NetworkConnectorView(NetworkConnector connector) { public NetworkConnectorView(NetworkConnector connector) {
@ -158,12 +159,8 @@ public class NetworkConnectorView implements NetworkConnectorViewMBean {
@Override @Override
public String getPassword() { public String getPassword() {
String pw = connector.getPassword(); // Hide the password for security reasons
// Hide the password for security reasons. return PASSWORD_MASK;
if (pw != null) {
pw = pw.replaceAll(".", "*");
}
return pw;
} }
@Override @Override
@ -180,4 +177,26 @@ public class NetworkConnectorView implements NetworkConnectorViewMBean {
public void setSuppressDuplicateTopicSubscriptions(boolean val) { public void setSuppressDuplicateTopicSubscriptions(boolean val) {
connector.setSuppressDuplicateTopicSubscriptions(val); connector.setSuppressDuplicateTopicSubscriptions(val);
} }
@Override
public String getRemotePassword() {
// Hide the password for security reasons.
return PASSWORD_MASK;
}
@Override
public void setRemotePassword(String remotePassword) {
connector.setRemotePassword(remotePassword);
}
@Override
public String getRemoteUserName() {
return connector.getRemoteUserName();
}
@Override
public void setRemoteUserName(String remoteUserName) {
connector.setRemoteUserName(remoteUserName);
}
} }

View File

@ -81,4 +81,12 @@ public interface NetworkConnectorViewMBean extends Service {
void setSuppressDuplicateTopicSubscriptions(boolean val); void setSuppressDuplicateTopicSubscriptions(boolean val);
String getRemoteUserName();
void setRemoteUserName(String remoteUserName);
String getRemotePassword();
void setRemotePassword(String remotePassword);
} }

View File

@ -608,8 +608,14 @@ public abstract class DemandForwardingBridgeSupport implements NetworkBridge, Br
remoteConnectionInfo = new ConnectionInfo(); remoteConnectionInfo = new ConnectionInfo();
remoteConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId())); remoteConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId()));
remoteConnectionInfo.setClientId(configuration.getName() + configuration.getClientIdToken() + configuration.getBrokerName() + configuration.getClientIdToken() + "outbound"); remoteConnectionInfo.setClientId(configuration.getName() + configuration.getClientIdToken() + configuration.getBrokerName() + configuration.getClientIdToken() + "outbound");
remoteConnectionInfo.setUserName(configuration.getUserName());
remoteConnectionInfo.setPassword(configuration.getPassword()); if(configuration.getRemoteUserName() != null) {
remoteConnectionInfo.setUserName(configuration.getRemoteUserName());
remoteConnectionInfo.setPassword(configuration.getRemotePassword());
} else {
remoteConnectionInfo.setUserName(configuration.getUserName());
remoteConnectionInfo.setPassword(configuration.getPassword());
}
remoteBroker.oneway(remoteConnectionInfo); remoteBroker.oneway(remoteConnectionInfo);
SessionInfo remoteSessionInfo = new SessionInfo(remoteConnectionInfo, 1); SessionInfo remoteSessionInfo = new SessionInfo(remoteConnectionInfo, 1);

View File

@ -58,6 +58,8 @@ public class NetworkBridgeConfiguration {
private String brokerURL = ""; private String brokerURL = "";
private String userName; private String userName;
private String password; private String password;
private String remoteUserName;
private String remotePassword;
private String destinationFilter = null; private String destinationFilter = null;
private String name = "NC"; private String name = "NC";
private String clientIdToken = "_"; private String clientIdToken = "_";
@ -300,6 +302,34 @@ public class NetworkBridgeConfiguration {
this.userName = userName; this.userName = userName;
} }
/**
* @return the remoteUserName
*/
public String getRemoteUserName() {
return this.remoteUserName;
}
/**
* @param remoteUserName the remoteUserName to set
*/
public void setRemoteUserName(String remoteUserName) {
this.remoteUserName = remoteUserName;
}
/**
* @return the remotePassword
*/
public String getRemotePassword() {
return this.remotePassword;
}
/**
* @param userName the userName to set
*/
public void setRemotePassword(String remotePassword) {
this.remotePassword = remotePassword;
}
/** /**
* @return the destinationFilter * @return the destinationFilter
*/ */