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