Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java JMX client with SSL

I configured Apache Tomcat 8 using this tutorial https://tomcat.apache.org/tomcat-7.0-doc/monitoring.html and I generated SSL certificate.

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"));
            }

How I need to extend this JMX client in order to use it with SSL certificate? I can't find any good example on Internet.

like image 830
Peter Penzov Avatar asked Dec 22 '15 08:12

Peter Penzov


People also ask

Is JMX secure?

By default, JMX is only locally accessible and secure: It can be accessed through Unix sockets. This means you need to have access to the machine and run JMX tools with the same user as your application. It's usually enough for development but not for production.


1 Answers

You're almost there, your code is correct, you only need to start your JMX client with the following command-line after having added your SSL certificate to a trust store using the keytool command-line utility:

java -Djavax.net.ssl.trustStore=/your/path/to/truststore.jks \ 
  -Djavax.net.ssl.trustStorePassword=truststore_pwd \ 
  YourJMXClient
like image 175
Val Avatar answered Oct 05 '22 22:10

Val