You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It'd be nice if there were out of the box support for JMXRP in addition to RMI. TLS / SASL support might be annoying to work in, but it looks like the RMI server has mostly the same code as this example JMXRP code:
packagecom.example;
importjavax.management.MBeanServerConnection;
importjavax.management.ObjectName;
importjavax.management.remote.JMXConnector;
importjavax.management.remote.JMXConnectorFactory;
importjavax.management.remote.JMXServiceURL;
importjavax.net.ssl.*;
importjava.io.File;
importjava.io.FileInputStream;
importjava.security.KeyStore;
importjava.util.Arrays;
importjava.util.HashMap;
importjava.util.Map;
/** * Dumps info about the specified MBean from the JMXConnectorServer at * the specified URL. */publicclassConnectorClient {
staticKeyStoretrustStore(Stringtype, Stringname, char[] password) throwsException {
KeyStoreanchors = KeyStore.getInstance(type);
anchors.load(newFileInputStream(name), password);
returnanchors;
}
staticKeyStore.Builderkeystore(Stringtype, Stringfilename, char[] password) {
returnKeyStore.Builder.newInstance(type, null, newFile(filename), newKeyStore.PasswordProtection(password));
}
staticKeyManagerFactorykeyManagerFactory(KeyStore.Builder... keystores) throwsException {
KeyStoreBuilderParametersksParams = newKeyStoreBuilderParameters(Arrays.asList(keystores));
KeyManagerFactoryfactory = KeyManagerFactory.getInstance("NewSunX509");
factory.init(ksParams);
returnfactory;
}
staticTrustManagerFactorytrustManagerFactory(KeyStoreanckors) throwsException {
TrustManagerFactorytmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(anckors);
returntmf;
}
staticSSLSocketFactorysocketFactory(KeyManagerFactorykmf, TrustManagerFactorytmf) throwsException {
SSLParameterssslParams = newSSLParameters();
sslParams.setEndpointIdentificationAlgorithm("HTTPS");
SSLContextctx = SSLContext.getInstance("TLSv1.2");
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
SSLSocketFactoryssf = ctx.getSocketFactory();
returnssf;
}
staticMBeanServerConnectionmbsc = null;
staticpublicvoidmain(String[] sa) throwsException {
StringurlString = "service:jmx:jmxmp://localhost:9999";
StringbeanId = "com.example:type=Hello";
KeyManagerFactorykmf = keyManagerFactory(keystore("JKS", "src/universal/conf/certs/client.jks", "changeit".toCharArray()));
TrustManagerFactorytmf = trustManagerFactory(trustStore("JKS", "src/universal/conf/certs/exampletrust.jks", "changeit".toCharArray()));
SSLSocketFactorysocketFactory = socketFactory(kmf, tmf);
Mapenv = newHashMap();
env.put("jmx.remote.profiles", "TLS");
env.put("jmx.remote.tls.enabled.protocols", "TLSv1.2");
env.put("jmx.remote.tls.enabled.cipher.suites", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256");
env.put("jmx.remote.tls.socket.factory", socketFactory);
JMXConnectorc =
JMXConnectorFactory.connect(newJMXServiceURL(urlString), env);
// If you aren't setting a profile or any other options, you can use// null for the second connect() parameter, instead of an empty list.try {
mbsc = c.getMBeanServerConnection();
// For this example, I chose to not expose the Adaptor as an// MBean, which is sometimes a good thing to do for security.// Therefore, I use it as a normal Java Object.System.err.println("Info on '" + beanId + "' is:");
javax.management.MBeanAttributeInfo[] aa =
mbsc.getMBeanInfo(newObjectName(beanId)).getAttributes();
for (inti = 0; i < aa.length; i++)
System.err.println(aa[i].getName());
} finally {
if (c != null) c.close();
}
System.exit(0);
}
}
It'd be nice if there were out of the box support for JMXRP in addition to RMI. TLS / SASL support might be annoying to work in, but it looks like the RMI server has mostly the same code as this example JMXRP code:
https://www.javaworld.com/article/2072256/remote-jmx--connectors-and-adapters.html?page=2
The text was updated successfully, but these errors were encountered: