From 92d6e909a472ce3c8b5edad9106debee7d2bf28f Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 20 Aug 2009 17:21:33 +0200 Subject: [PATCH] java bindings: GenericJMX: Implement user/password authentication. --- .../java/GenericJMXConfConnection.java | 33 ++++++++++++++++++- contrib/GenericJMX.conf | 4 ++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/bindings/java/org/collectd/java/GenericJMXConfConnection.java b/bindings/java/org/collectd/java/GenericJMXConfConnection.java index 0108b53f..7214fd76 100644 --- a/bindings/java/org/collectd/java/GenericJMXConfConnection.java +++ b/bindings/java/org/collectd/java/GenericJMXConfConnection.java @@ -22,8 +22,10 @@ package org.collectd.java; import java.util.List; +import java.util.Map; import java.util.Iterator; import java.util.ArrayList; +import java.util.HashMap; import javax.management.MBeanServerConnection; import javax.management.ObjectName; @@ -40,6 +42,8 @@ import org.collectd.api.OConfigItem; class GenericJMXConfConnection { + private String _username = null; + private String _password = null; private String _host = null; private String _service_url = null; private MBeanServerConnection _jmx_connection = null; @@ -76,14 +80,29 @@ private void connect () /* {{{ */ { JMXServiceURL service_url; JMXConnector connector; + Map environment; if (_jmx_connection != null) return; + environment = null; + if (this._password != null) + { + String[] credentials; + + if (this._username == null) + this._username = new String ("monitorRole"); + + credentials = new String[] { this._username, this._password }; + + environment = new HashMap (); + environment.put (JMXConnector.CREDENTIALS, credentials); + } + try { service_url = new JMXServiceURL (this._service_url); - connector = JMXConnectorFactory.connect (service_url); + connector = JMXConnectorFactory.connect (service_url, environment); _jmx_connection = connector.getMBeanServerConnection (); } catch (Exception e) @@ -125,6 +144,18 @@ private void connect () /* {{{ */ if (tmp != null) this._host = tmp; } + else if (child.getKey ().equalsIgnoreCase ("User")) + { + String tmp = getConfigString (child); + if (tmp != null) + this._username = tmp; + } + else if (child.getKey ().equalsIgnoreCase ("Password")) + { + String tmp = getConfigString (child); + if (tmp != null) + this._password = tmp; + } else if (child.getKey ().equalsIgnoreCase ("ServiceURL")) { String tmp = getConfigString (child); diff --git a/contrib/GenericJMX.conf b/contrib/GenericJMX.conf index 394dd306..f4dd8f0e 100644 --- a/contrib/GenericJMX.conf +++ b/contrib/GenericJMX.conf @@ -224,8 +224,10 @@ # Connection blocks # ##################### - Host "localhost" ServiceURL "service:jmx:rmi:///jndi/rmi://localhost:17264/jmxrmi" + User "monitorRole" + Password "queeZie1" + Host "localhost" Collect "classes" Collect "compilation" Collect "garbage_collector" -- 2.30.2