db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
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 GMT
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<? extends MBeanTest> 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<String> list = new ArrayList<String>();
         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 <code>getInfo</code> 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<MBeanServerConnection>()
{
 

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<String,String[]> env = new HashMap<String,String[]>();
+        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<MBeanServerConnection,JMXConnector> conns = connections.get();



Mime
View raw message