add RMI authentication options to nodetool

patch by mck; reviewed by jbellis for CASSANDRA-1921

git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1054137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2010-12-31 17:22:04 +00:00
parent 37ec7d326d
commit f7f069f340
3 changed files with 38 additions and 2 deletions

View File

@ -4,6 +4,7 @@ dev
* upgrade to TFastFramedTransport (CASSANDRA-1743)
* avoid polluting page cache with commitlog or sstable writes
and seq scan operations (CASSANDRA-1470)
* add RMI authentication options to nodetool (CASSANDRA-1921)
0.7.0-rc4

View File

@ -45,6 +45,10 @@ public class NodeCmd {
private static final String HOST_OPT_SHORT = "h";
private static final String PORT_OPT_LONG = "port";
private static final String PORT_OPT_SHORT = "p";
private static final String USERNAME_OPT_LONG = "username";
private static final String USERNAME_OPT_SHORT = "u";
private static final String PASSWORD_OPT_LONG = "password";
private static final String PASSWORD_OPT_SHORT = "pw";
private static final int defaultPort = 8080;
private static Options options = null;
@ -57,6 +61,8 @@ public class NodeCmd {
optHost.setRequired(true);
options.addOption(optHost);
options.addOption(PORT_OPT_SHORT, PORT_OPT_LONG, true, "remote jmx agent port number");
options.addOption(USERNAME_OPT_SHORT, USERNAME_OPT_LONG, true, "remote jmx agent username");
options.addOption(PASSWORD_OPT_SHORT, PASSWORD_OPT_LONG, true, "remote jmx agent password");
}
public NodeCmd(NodeProbe probe)
@ -469,11 +475,13 @@ public class NodeCmd {
throw new ParseException("Port must be a number");
}
}
String username = cmd.getOptionValue(USERNAME_OPT_LONG);
String password = cmd.getOptionValue(PASSWORD_OPT_LONG);
NodeProbe probe = null;
try
{
probe = new NodeProbe(host, port);
probe = username == null ? new NodeProbe(host, port) : new NodeProbe(host, port, username, password);
}
catch (IOException ioe)
{

View File

@ -63,6 +63,8 @@ public class NodeProbe
private static final int defaultPort = 8080;
final String host;
final int port;
private String username;
private String password;
private JMXConnector jmxc;
private MBeanServerConnection mbeanServerConn;
@ -72,6 +74,25 @@ public class NodeProbe
private RuntimeMXBean runtimeProxy;
private StreamingServiceMBean streamProxy;
/**
* Creates a NodeProbe using the specified JMX host, port, username, and password.
*
* @param host hostname or IP address of the JMX agent
* @param port TCP port of the remote JMX agent
* @throws IOException on connection failures
*/
public NodeProbe(String host, int port, String username, String password) throws IOException, InterruptedException
{
assert username != null && !username.isEmpty() && null != password && !password.isEmpty()
: "neither username nor password can be blank";
this.host = host;
this.port = port;
this.username = username;
this.password = password;
connect();
}
/**
* Creates a NodeProbe using the specified JMX host and port.
*
@ -107,7 +128,13 @@ public class NodeProbe
private void connect() throws IOException
{
JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
jmxc = JMXConnectorFactory.connect(jmxUrl, null);
Map<String,Object> env = new HashMap<String,Object>();
if (username != null)
{
String[] creds = { username, password };
env.put(JMXConnector.CREDENTIALS, creds);
}
jmxc = JMXConnectorFactory.connect(jmxUrl, env);
mbeanServerConn = jmxc.getMBeanServerConnection();
try