How to use custom JMXAuthenticator

I have to authenticate JMX clients against database entries. So I wrote a custom implementation of JMXAuthenticator.

When the application starts, I can access MBeans using JConsole through the "Local Process". But when I try to access it as a remote process, using the service url: jmx: rmi: /// jndi / rmi: // localhost: 10999 / jmxrmi 'JConsole shows a message complaining that "Connection to the service: jmx : rmi: /// jndi / rmi: // localhost: 10999 / jmxrmi failed. '

Below is the server code for running MBeanServer and JMXConnectorServer. Does anyone know what I'm doing wrong?

Thanks in advance,

Thomas

final MBeanServer mbs = MBeanServerFactory.createMBeanServer("MyDomain");
final HashMap<String, Object> environment = new HashMap<String, Object>();
final JMXAuthenticator authenticator = new JMXAuthenticatorImpl();
environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator);

final JMXServiceURL serviceURL = new JMXServiceURL("rmi", "localhost", 10999);

final JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, environment, mbs);

connectorServer.start();
+3
source share
1 answer

The problem seems to be that I did not create the RMI registry before creating the new JMXConnectorServer.

Insert

LocateRegistry.createRegistry(port);

before creating JMXConnectorServer solved the problem.

+2
source

All Articles