Java 使用 SSL 的 JMX 客户端

Java JMX client with SSL

我使用本教程配置了 Apache Tomcat 8 https://tomcat.apache.org/tomcat-7.0-doc/monitoring.html 并生成了 SSL 证书。

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://10.16.70.161:9999/jmxrmi");

            HashMap environment = new HashMap();
            String[] credentials = new String[]
            {
                "user", "passw"
            };
            environment.put(JMXConnector.CREDENTIALS, credentials);

            JMXConnector jmxc = JMXConnectorFactory.connect(url, environment);
            MBeanServerConnection server = jmxc.getMBeanServerConnection();

            Set<ObjectName> s2 = server.queryNames(new ObjectName("Catalina:type=Server,*"), null);
            for (ObjectName obj : s2)
            {
                ObjectName objname = new ObjectName(obj.getCanonicalName());
                System.out.println("serverInfo " + server.getAttribute(objname, "serverInfo"));
                System.out.println("address " + server.getAttribute(objname, "address"));
                System.out.println("stateName " + server.getAttribute(objname, "stateName"));
            }

我需要如何扩展此 JMX 客户端才能将其与 SSL 证书一起使用?我在 Internet 上找不到任何好的示例。

你就快完成了,你的代码是正确的,你只需要在将你的 SSL 证书添加到 trust store using the keytool 命令行实用程序后使用以下命令行启动你的 JMX 客户端:

java -Djavax.net.ssl.trustStore=/your/path/to/truststore.jks \ 
  -Djavax.net.ssl.trustStorePassword=truststore_pwd \ 
  YourJMXClient