Implementation of the JMXAuthenticator interface to be used on server side
to secure access to
JMXConnectorServer
s.
Usage:
JMXAuthenticator authenticator = new PasswordAuthenticator(new File("users.properties"));
Map environment = new HashMap();
environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator);
JMXServiceURL address = new JMXServiceURL("rmi", "localhost", 0);
MBeanServer server = ...;
JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(address, environment, server);
The format of the users.properties file is that of a standard properties file:
<user>=<password>
where <password> can be stored in 2 ways:
- Clear text: the password is written in clear text
- Obfuscated text: the password is obfuscated
The obfuscated form can be obtained running this class as a main class:
java -cp mx4j-remote.jar mx4j.tools.remote.PasswordAuthenticator
and following the instructions printed on the console. The output will be a string that should be
copy/pasted as the password into the properties file.
The obfuscated password is obtained by digesting the clear text password using a
java.security.MessageDigest
algorithm, and then by Base64-encoding the resulting bytes.
On client side, you are allowed to connect to a server side secured with the PasswordAuthenticator
only if you provide the correct credentials:
String[] credentials = new String[2];
// The user will travel as clear text
credentials[0] = "user";
// You may send the password in clear text, but it's better to obfuscate it
credentials[1] = PasswordAuthenticator.obfuscatePassword("password");
Map environment = new HashMap();
environment.put(JMXConnector.CREDENTIALS, credentials);
JMXServiceURL address = ...;
JMXConnector cntor = JMXConnectorFactory.connect(address, environment);
Note that
obfuscating
the passwords only works if the server side has been
setup with the PasswordAuthenticator.
However, the PasswordAuthenticator can be used with other JSR 160 implementations, such as Sun's reference
implementation.