![]() |
|||
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
| |||||||
The SampleClient class is an extension of the SaslClient interface, and calls the standard SaslClient methods one by one, to perform the following operations that are expected by the SampleServer:
With these SASL server and client mechanisms defined, they can then be instantiated by their respective factories. Example 11-13 A Custom SASL Server Factory
This basic implementation of the SaslServerFactory interface creates SampleServer instances when it is called with the SASL mechanism parameter set to SAMPLE. None of the other parameters are used by this mechanism. The SampleClientFactory creates SampleClient instances in exactly the same way as the SampleServerFactory creates SampleServer instances. Example 11-14 SASL SAMPLE Provider Class
The SASL SAMPLE Provider constructor shown above specifies the name of the provider (SampleSasl), the version of this provider (in this case, 1.0) and a description of the provider. It then defines the server and client factories that are used to create SASL servers and clients implementing this SASL mechanism. With the mechanisms above thus defined, all the Server and Client classes used in this example require the correct Provider to be installed in the environment. Example 11-15 Adding a Provider to a JMX Connector Server
The SAMPLE SASL mechanism is passed into the Client in the same way.
|
$ javac -classpath classpath \ mbeans/SimpleStandard.java \ mbeans/SimpleStandardMBean.java \ server/Server.java \ client/Client.java \ client/ClientListener.java \ sample/Provider.java \ sample/ClientFactory.java \ sample/ServerFactory.java \ sample/SampleClient.java \ sample/SampleServer.java |
Start the Server.
$ java -classpath server:sample:mbeans:classpath Server & |
You will see confirmation of the creation of the MBean server, the initialization of the environment map and the launching of the JMXMP connector and its registration in the MBean server.
Start the Client.
$ java -classpath client:sample:mbeans:classpath Client |
You will see confirmation of the creation of the JMXMP connector client, the initialization of the environment map, the connection to the MBean server and the performance of the various MBean operations followed by the closure of the connection.
Your JMXMP connections can also be secured using an implementation of Transport Layer Security (TLS) sockets, as shown in the following example. This example is taken from the sub-directories of examplesDir/current/Security/jmxmp/tls_factory. The example shows how to provide a custom configured TLS factory for use by the client and the server.
Example 11-16 Securing a JMXMP Connector Server Using TLS Socket Factories
public class Server { public static void main(String[] args) { try { MBeanServer mbs = MBeanServerFactory.createMBeanServer(); HashMap env = new HashMap(); String keystore = "config" + File.separator + "keystore"; char keystorepass[] = "password".toCharArray(); char keypassword[] = "password".toCharArray(); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(new FileInputStream(keystore), keystorepass); KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(ks, keypassword); SSLContext ctx = SSLContext.getInstance("TLSv1"); ctx.init(kmf.getKeyManagers(), null, null); SSLSocketFactory ssf = ctx.getSocketFactory(); env.put("jmx.remote.profiles", "TLS"); env.put("jmx.remote.tls.socket.factory", ssf); env.put("jmx.remote.tls.enabled.protocols", "TLSv1"); env.put("jmx.remote.tls.enabled.cipher.suites", "SSL_RSA_WITH_NULL_MD5"); JMXServiceURL url = new JMXServiceURL("jmxmp", null, 5555); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); cs.start(); } catch (Exception e) { e.printStackTrace(); } } } |
![]() ![]() |