Failed to connect to Tomcat JMX server

Failed to connect to Tomcat JMX instance

Ok, I'm stuck now - I'm trying to configure JMX with Tomcat as follows

$CATALINA_BASE/setenv.sh :

 CATALINA_OPTS="-Dcom.sun.management.jmxremote.port=18070 -Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access" export CATALINA_OPTS 

$CATALINA_BASE/conf/jmxremote.password

  monitorRole monitorpass controlRole controlpass 

$CATALINA_BASE/conf/jmxremote.access

  monitorRole readonly controlRole readwrite 

The client tool that I use to access the Tomcat JMX server runs on the same computer as the Tomcat instance. when I start tomcat, I see that there is something listening on port 18070, but when I try to connect, I get the following error.

  Exception in thread "main" java.lang.SecurityException: Authentication failed! Credentials required at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticationFailure(JMXPluggableAuthenticator.java:193) at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticate(JMXPluggableAuthenticator.java:145) at sun.management.jmxremote.ConnectorBootstrap$AccessFileCheckerAuthenticator.authenticate(ConnectorBootstrap.java:185) at javax.management.remote.rmi.RMIServerImpl.doNewClient(RMIServerImpl.java:213) 

I connect using the next bit of code

  try { url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:18070/jmxrmi"); jmxc = JMXConnectorFactory.connect(url,null); mbsc = jmxc.getMBeanServerConnection(); } catch (MalformedURLException e) { throw new Exception(methodName + ":" + e); } catch (IOException e) { throw new Exception(methodName + ":" + "Failed to connect to the Tomcat Server " + e); } 

It works fine if I set com.sun.management.jmxremote.authenticate = true to false. Also, it just fails. The client tool runs on the same computer as the tomcat instance, so there should not be any problems with the firewall. Any hints

+4
source share
1 answer

it

 JMXServiceURL url = ...; Map env = ...; String[] creds = {"monitorRole", "mrpasswd"}; env.put(JMXConnector.CREDENTIALS, creds); JMXConnector cc = JMXConnectorFactory.connect(url, env); MBeanServerConnection mbsc = cc.getMBeanServerConnection(); 

from http://blogs.oracle.com/lmalventosa/entry/jmx_authentication_authorization

should help

+3
source

Source: https://habr.com/ru/post/1335404/


All Articles