V2.2.1 Allow jmx exchange in xmpp communication

master
Ng Yat Yan 1 month ago
parent f5c1b7000f
commit 5b7b4f6a1b

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.sshd</groupId>
<artifactId>echo-sshd-server</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
<name>ECHO SSH SERVER</name>
<description>Learning Apache Mina SSHD library</description>
<parent>

@ -27,6 +27,7 @@ public class EchoComponent extends AbstractComponent {
public static final String CONST_OPERATION_ADD_USER = "adduser";
public static final String CONST_OPERATION_CHANGE_USER_PASSWORD = "chgpasswd";
public static final String CONST_OPERATION_DELETE_USER = "deluser";
public static final String CONST_OPERATION_JMX_CLIENT = "jmx_client";
@Autowired
XmppComponentConfig xmppComponentConfig;
@ -34,6 +35,9 @@ public class EchoComponent extends AbstractComponent {
@Autowired
ReplyService replyService;
@Autowired
JmxClientService jmxClientService;
@Autowired
@Qualifier("userAdminCache")
private volatile Cache<String, Message> userAdminCache;
@ -93,7 +97,7 @@ public class EchoComponent extends AbstractComponent {
logger.info("[handleMessage] -- RECEIVED -- {}", inMsg);
try {
if (StringUtils.isNotBlank(inMsg.getBody())) {
String[] commandParts = StringUtils.split(inMsg.getBody(), ' ');
String[] commandParts = StringUtils.split(inMsg.getBody().trim(), ' ');
switch (commandParts[0]) {
case CONST_OPERATION_ADD_USER:
if (commandParts.length == 3)
@ -113,6 +117,9 @@ public class EchoComponent extends AbstractComponent {
else
doEcho(inMsg, "chgpasswd <username> <new_password>");
break;
case CONST_OPERATION_JMX_CLIENT:
doEcho(inMsg, jmxClientService.process(commandParts));
break;
default:
doEcho(inMsg, replyService.executeShellCommand(inMsg.getBody().trim()));
break;

@ -35,7 +35,6 @@ public class JmxClientService {
try {
if (args.length > 2) {
Runtime.getRuntime().freeMemory();
System.out.println("Connection to JMX kafka...");
JMXServiceURL url = new JMXServiceURL(args[1]);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

@ -128,7 +128,7 @@ public class ReplyService {
return false;
}
public String executeShellCommand(String command) throws IOException {
public String executeShellCommand(String command) {
String cmdHash = DigestUtils.md5Hex(command.trim()).toUpperCase();
logger.info("[{}] Execute cmd for real: {}", cmdHash, command.trim());
ByteArrayOutputStream tempOut = new ByteArrayOutputStream();
@ -142,6 +142,8 @@ public class ReplyService {
return new String(tempOut.toByteArray()).replace("\n", "\r\n");
} catch (ExecuteException e) {
logger.info("[{}] Execute cmd failed: {}", cmdHash, command.trim(), e);
} catch (IOException e) {
logger.info("[{}] Execute cmd failed: {}", cmdHash, command.trim(), e);
}
return null;
}

Loading…
Cancel
Save