Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 12100 invoked from network); 11 Mar 2008 00:27:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Mar 2008 00:27:26 -0000 Received: (qmail 77728 invoked by uid 500); 11 Mar 2008 00:27:23 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 77694 invoked by uid 500); 11 Mar 2008 00:27:23 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 77683 invoked by uid 99); 11 Mar 2008 00:27:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Mar 2008 17:27:23 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Mar 2008 00:26:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E168A1A9832; Mon, 10 Mar 2008 17:27:04 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r635766 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management: JMXConnectionGetter.java MBeanTest.java PlatformConnectionGetter.java RemoteConnectionGetter.java Date: Tue, 11 Mar 2008 00:27:03 -0000 To: derby-commits@db.apache.org From: djd@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080311002704.E168A1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: djd Date: Mon Mar 10 17:27:00 2008 New Revision: 635766 URL: http://svn.apache.org/viewvc?rev=635766&view=rev Log: DERBY-3506 Add some framework to get jmx connections with a user name and password when using jmx authenication. Not used yet by any test. Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java?rev=635766&r1=635765&r2=635766&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXConnectionGetter.java Mon Mar 10 17:27:00 2008 @@ -40,7 +40,8 @@ /** * Get a connection to the platform MBean Server. */ - MBeanServerConnection getMBeanServerConnection() throws Exception; + MBeanServerConnection getMBeanServerConnection(String user, + String password) throws Exception; void close(MBeanServerConnection jmxConnection) throws Exception; } Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java?rev=635766&r1=635765&r2=635766&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java Mon Mar 10 17:27:00 2008 @@ -51,7 +51,7 @@ * BaseTestCase. */ abstract class MBeanTest extends BaseJDBCTestCase { - + /** * JMX connection to use throughout the instance. */ @@ -61,7 +61,7 @@ super(name); } - protected static Test suite(Class testClass, String suiteName) { + protected static Test suite(Class testClass, String suiteName) { // TODO - // Check for J2SE 5.0 or better? Or java.lang.management.ManagementFactory? @@ -106,7 +106,7 @@ NetworkServerTestSetup networkServerTestSetup = new NetworkServerTestSetup ( suite, // run all tests in this class in the same setup - getCommandLineProperties(), // need to set up JMX in JVM + getCommandLineProperties(false), // need to set up JMX in JVM new String[0], // no server arguments needed true // wait for the server to start properly ); @@ -117,13 +117,15 @@ * JMX specific policy file later. Or use the property trick reported * on derby-dev 2008-02-26 and add the permission to the generic * policy. + * Note that the remote server will be running with a security + * manager (by default) if testing with jars. */ Test testSetup = SecurityManagerSetup.noSecurityManager(networkServerTestSetup); // this decorator makes sure the suite is empty if this configration // does not support the network server: outerSuite.addTest(TestConfiguration.defaultServerDecorator(testSetup)); - + return outerSuite; } @@ -138,13 +140,21 @@ * @return a set of Java system properties to be set on the command line * when starting a new JVM in order to enable remote JMX. */ - private static String[] getCommandLineProperties() + private static String[] getCommandLineProperties(boolean authentication) { ArrayList list = new ArrayList(); list.add("com.sun.management.jmxremote.port=" + TestConfiguration.getCurrent().getJmxPort()); - list.add("com.sun.management.jmxremote.authenticate=false"); + list.add("com.sun.management.jmxremote.authenticate=" + + Boolean.toString(authentication)); list.add("com.sun.management.jmxremote.ssl=false"); + + if (authentication) { + list.add("com.sun.management.jmxremote.password.file=" + + "extin/jmx.password"); + list.add("com.sun.management.jmxremote.access.file=" + + "extin/jmx.access"); + } String[] result = new String[list.size()]; list.toArray(result); return result; @@ -175,7 +185,10 @@ } /** - * Obtains a connection to an MBean server. Assumes th + * Obtains a connection to an MBean server with + * no user name or password, + * opens a single connection for the lifetime + * of the fixture * * @return a plain connection to an MBean server */ @@ -184,11 +197,24 @@ if (jmxConnection == null) jmxConnection = - JMXConnectionGetter.mbeanServerConnector.get().getMBeanServerConnection(); + JMXConnectionGetter.mbeanServerConnector.get() + .getMBeanServerConnection(null, null); return jmxConnection; } /** + * Obtains a connection to an MBean server with + * a user name or password. A new connection is + * returned for each call. + */ + protected MBeanServerConnection getMBeanServerConnection( + String user, String password) throws Exception { + + return JMXConnectionGetter.mbeanServerConnector.get() + .getMBeanServerConnection(user, password); + } + + /** * Is the JMX connecting using platform JMX. * @return True jmx connections via the platform server, false remote connections. */ @@ -434,6 +460,7 @@ String value = (String)getAttribute(objName, name); println(name + " = " + value); // for debugging } + /** * Calls the public method getInfo of the sysinfo tool within Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java?rev=635766&r1=635765&r2=635766&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/PlatformConnectionGetter.java Mon Mar 10 17:27:00 2008 @@ -35,7 +35,11 @@ PlatformConnectionGetter() { } - public MBeanServerConnection getMBeanServerConnection() throws Exception { + /** + * User name ignored, only applicable for remote connections. + */ + public MBeanServerConnection getMBeanServerConnection(String user, + String password) throws Exception { return AccessController.doPrivileged(new PrivilegedAction() { Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java?rev=635766&r1=635765&r2=635766&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java (original) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/RemoteConnectionGetter.java Mon Mar 10 17:27:00 2008 @@ -44,9 +44,17 @@ this.url = url; } - public MBeanServerConnection getMBeanServerConnection() throws Exception { - // assumes that JMX authentication and SSL is not required (hence null) - JMXConnector jmxc = JMXConnectorFactory.connect(url, null); + public MBeanServerConnection getMBeanServerConnection(String user, + String password) throws Exception { + + HashMap env = new HashMap(); + if (user != null) { + String[] credentials = new String[] { + user, password }; + env.put("jmx.remote.credentials", credentials); + } + + JMXConnector jmxc = JMXConnectorFactory.connect(url, env); MBeanServerConnection jmxConn = jmxc.getMBeanServerConnection(); Map conns = connections.get();