db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r636319 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management: JMXTest.java MBeanTest.java
Date Wed, 12 Mar 2008 13:31:46 GMT
Author: djd
Date: Wed Mar 12 06:31:39 2008
New Revision: 636319

URL: http://svn.apache.org/viewvc?rev=636319&view=rev
Log:
DERBY-3506 add more privileged blocks to MBeanTest & JMXTest in anticipation of running
without a security manager for the platform tests.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java?rev=636319&r1=636318&r2=636319&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
Wed Mar 12 06:31:39 2008
@@ -21,11 +21,17 @@
 
 package org.apache.derbyTesting.functionTests.tests.management;
 
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
 import java.util.Set;
 
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
 import javax.management.MBeanInfo;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
+import javax.management.ReflectionException;
 
 import junit.framework.Test;
 
@@ -64,14 +70,20 @@
         assertTrue("Derby MBEan count:" + derbyMBeans.size(),
                 derbyMBeans.size() >= 2);
         
-        MBeanServerConnection jmx = getMBeanServerConnection();
-        for (ObjectName name : derbyMBeans)
+        final MBeanServerConnection jmx = getMBeanServerConnection();
+        for (final ObjectName name : derbyMBeans)
         {
             String type = name.getKeyProperty("type");
             // Every Derby MBean has a type.
             assertNotNull(type);
             
-            MBeanInfo mbeanInfo = jmx.getMBeanInfo(name);
+            MBeanInfo mbeanInfo = AccessController.doPrivileged(
+                    new PrivilegedExceptionAction<MBeanInfo>() {
+                        public MBeanInfo run() throws InstanceNotFoundException, IntrospectionException,
ReflectionException, IOException {
+                            return jmx.getMBeanInfo(name);
+                       }   
+                    }
+                );
             
             String mbeanClassName = mbeanInfo.getClassName();
             // Is the class name in the public api

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=636319&r1=636318&r2=636319&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
Wed Mar 12 06:31:39 2008
@@ -249,7 +249,7 @@
 
         // check the status of the management service
         Boolean active = (Boolean) 
-                serverConn.getAttribute(mgmtObjName, "ManagementActive");
+                getAttribute(mgmtObjName, "ManagementActive");
 
         if (!active.booleanValue()) {
             // JMX management is not active, so activate it by invoking the
@@ -259,7 +259,7 @@
                     "startManagement", 
                     new Object[0], new String[0]); // no arguments
             active = (Boolean) 
-                    serverConn.getAttribute(mgmtObjName, "ManagementActive");
+                    getAttribute(mgmtObjName, "ManagementActive");
         }
         
         assertTrue("Failed to activate Derby's JMX management", active);
@@ -273,9 +273,16 @@
     @SuppressWarnings("unchecked")
     protected Set<ObjectName> getDerbyDomainMBeans() throws Exception
     {
-        ObjectName derbyDomain = new ObjectName("org.apache.derby:*");
-        return  (Set<ObjectName>)
-            getMBeanServerConnection().queryNames(derbyDomain, null);
+        final ObjectName derbyDomain = new ObjectName("org.apache.derby:*");
+        final MBeanServerConnection serverConn = getMBeanServerConnection(); 
+        
+        return  (Set<ObjectName>) AccessController.doPrivileged(
+            new PrivilegedExceptionAction<Object>() {
+                public Object run() throws IOException {
+                    return serverConn.queryNames(derbyDomain, null);
+               }   
+            }
+        );   
     }
     
     /**
@@ -297,8 +304,7 @@
         final MBeanServerConnection serverConn = getMBeanServerConnection();
         
         if (!serverConn.isRegistered(mgmtObjName))
-        {
-        
+        {       
             AccessController.doPrivileged(
                 new PrivilegedExceptionAction<Object>() {
                     public Object run() throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException, ReflectionException, MBeanException, IOException {
@@ -357,16 +363,22 @@
      * @return the value returned by the operation being invoked, or 
      *         <code>null</code> if there is no return value.
      */
-    protected Object invokeOperation(ObjectName objName, 
-                                     String name, 
-                                     Object[] params, 
-                                     String[] sign)
+    protected Object invokeOperation(final ObjectName objName, 
+                                     final String name, 
+                                     final Object[] params, 
+                                     final String[] sign)
             throws Exception
     {
-        return getMBeanServerConnection().invoke(
-                objName, 
-                name, 
-                params, sign);
+        final MBeanServerConnection jmxConn = getMBeanServerConnection();
+        
+        return AccessController.doPrivileged(
+            new PrivilegedExceptionAction<Object>() {
+                public Object run() throws InstanceNotFoundException, MBeanException, ReflectionException,
IOException  {
+                    return jmxConn.invoke(objName, name,
+                            params, sign);
+                }
+            }
+        );
     }
     
     /**



Mime
View raw message