0

There are security reasons that I cannot add my MBeans to the existing JBoss 7 platform MBeanServer. So I create my own mBeanServer and JMXConnectorServer with a customAuthenticator.

Here are my Spring Bean definition for new MBeanServer and JMXConnectorServer. This code works when I run my application in Jetty. I was able to connect via URL service:jmx:rmi://localhost/jndi/rmi://localhost:17999/sample in jconsole and it only shows the custom MBeans which is what I expect.

But the same code does not work in JBoss 7. When I deploy to JBoss and try to connect with the same JMX URL, it gives a dialog with this error: "The connection to myuser@service:jmx:rmi://localhost/jndi/rmi://localhost:17999/trm did not succeed. Would you like to try again?"

I put a break point in my customAuthenticator and JBoss doesn't stop at my break point when I attempt to connect JMX. It seems my JMXConnectorServer is not being used by JBoss. Can anyone help? Note that I cannot change the existing JBoss MBeanServer or JMX Connector Server configuration because they are used for other purpose.

Thanks in advance.

@Bean
public Object rmiRegistry() throws Exception {
            RmiRegistryFactoryBean factory = new RmiRegistryFactoryBean();
            factory.setPort(17999);
            factory.afterPropertiesSet();
            return factory.getObject();
}

@Bean
@DependsOn("rmiRegistry")
public MBeanServer mBeanServer() {
    MBeanServerFactoryBean factory = new MBeanServerFactoryBean();
    factory.afterPropertiesSet();
    return factory.getObject();
}

@Bean
@DependsOn("rmiRegistry")
public JMXConnectorServer jmxConnectorServer() throws IOException, JMException {
    ConnectorServerFactoryBean factory = new ConnectorServerFactoryBean();
    factory.setServer(mBeanServer());
    factory.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:17999/sample");
    factory.setRegistrationPolicy(RegistrationPolicy.FAIL_ON_EXISTING);
    Map<String, Object> props = new HashMap<>();
    props.put(JMXConnectorServer.AUTHENTICATOR, customAuthenticator);
    factory.setEnvironmentMap(props);
    factory.afterPropertiesSet();

    return factory.getObject();
}

@Bean
@DependsOn("rmiRegistry")
public AnnotationMBeanExporter annotationMBeanExporter() {
    AnnotationMBeanExporter result = null;
    result = new AnnotationMBeanExporter();
    result.setServer(mBeanServer());
    return result;
}
James H
  • 531
  • 6
  • 15

1 Answers1

0

I suspect the JBoss environment is influencing how the JMX Connector server is configured. I would try taking the extra step of specifying the service listening port (e.g. 17998) rather than leaving it as an ephemeral by using this JMXServiceURL:

service:jmx:rmi://localhost:17998/jndi/rmi://localhost:17999/sample
Nicholas
  • 15,916
  • 4
  • 42
  • 66