[jboss-remoting-commits] JBoss Remoting SVN: r5026 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Tue Apr 14 06:30:40 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-04-14 06:30:40 -0400 (Tue, 14 Apr 2009)
New Revision: 5026

Modified:
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java
   remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.

Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java	2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java	2009-04-14 10:30:40 UTC (rev 5026)
@@ -25,6 +25,9 @@
 import java.io.OutputStream;
 import java.net.InetAddress;
 import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.Properties;
 
 import javax.naming.Binding;
@@ -98,7 +101,7 @@
          
          // Get detection message from JNDI server.
          createContext();
-         NamingEnumeration enumeration = SecurityUtility.listBindings(context, "");
+         NamingEnumeration enumeration = listBindings(context, "");
          assertTrue(enumeration.hasMore());
          Binding binding = (Binding) enumeration.next();
          assertFalse(enumeration.hasMore());
@@ -117,7 +120,7 @@
          Thread.sleep(4000);
 
          // Get new detection message from JNDI server.
-         enumeration = SecurityUtility.listBindings(context, "");
+         enumeration = listBindings(context, "");
          assertTrue(enumeration.hasMore());
          binding = (Binding) enumeration.next();
          log.info(binding);
@@ -158,20 +161,91 @@
       String subContextName = JNDIDetector.DETECTION_SUBCONTEXT_NAME;
       try
       {
-         context = SecurityUtility.initialContextLookup(initialContext, subContextName);
+         context = initialContextLookup(initialContext, subContextName);
       }
       catch(NamingException e)
       {
          try
          {
-            context = SecurityUtility.createSubcontext(initialContext, subContextName);
+            context = createSubcontext(initialContext, subContextName);
          }
          catch(NameAlreadyBoundException e1)
          {
             log.debug("The sub context " + subContextName + " was created before we could.");
-            context = SecurityUtility.initialContextLookup(initialContext, subContextName);
+            context = initialContextLookup(initialContext, subContextName);
          }
       }
    }
+   
+   static private Context createSubcontext(final InitialContext initialContext, final String subContextName)
+   throws NamingException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return initialContext.createSubcontext(subContextName);
+      }
 
+      try
+      {
+         return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction() 
+         {
+            public Object run() throws NamingException
+            {
+               return initialContext.createSubcontext(subContextName);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (NamingException) e.getCause();
+      }
+   }
+   
+   static private Context initialContextLookup(final InitialContext initialContext, final String subContextName)
+   throws NamingException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return (Context) initialContext.lookup(subContextName);
+      }
+
+      try
+      {
+         return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction() 
+         {
+            public Object run() throws NamingException
+            {
+               return initialContext.lookup(subContextName);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (NamingException) e.getCause();
+      }
+   }
+   
+   static private NamingEnumeration listBindings(final Context context, final String bindName)
+   throws NamingException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         return context.listBindings(bindName);
+      }
+
+      try
+      {
+         return (NamingEnumeration) AccessController.doPrivileged( new PrivilegedExceptionAction() 
+         {
+            public Object run() throws NamingException
+            {
+               return context.listBindings(bindName);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (NamingException) e.getCause();
+      }
+   }
 }

Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java	2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java	2009-04-14 10:30:40 UTC (rev 5026)
@@ -43,10 +43,14 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Timer;
@@ -135,8 +139,8 @@
          namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
          namingBean = namingBeanImplClass.newInstance();
          Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
-         SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
-         SecurityUtility.namingBeanImplStart(namingBean, startMethod);
+         setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+         namingBeanImplStart(namingBean, startMethod);
       }
       catch (Exception e)
       {
@@ -331,4 +335,58 @@
          // NO OP as we do not need a reference back to the server invoker
       }
    }
+   
+   static private void setSystemProperty(final String name, final String value)
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         System.setProperty(name, value);
+         return;
+      }
+      
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.setProperty(name, value);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+   }
+   
+   static private void namingBeanImplStart(final Object namingBean, final Method startMethod)
+   throws IllegalAccessException, InvocationTargetException
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         startMethod.invoke(namingBean, new Object[] {});
+         return;
+      }
+
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction() 
+         {
+            public Object run() throws IllegalAccessException, InvocationTargetException
+            {
+               startMethod.invoke(namingBean, new Object[] {});
+               return null;
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         Throwable cause = e.getCause();
+         if (cause instanceof IllegalAccessException)
+            throw (IllegalAccessException) cause;
+         else
+            throw (InvocationTargetException) cause;
+      }
+   }
 }

Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java	2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java	2009-04-14 10:30:40 UTC (rev 5026)
@@ -8,6 +8,9 @@
 
 import java.lang.reflect.Method;
 import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * This should be used as the main test case for JNDI detector.
@@ -36,7 +39,7 @@
             namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
             namingBean = namingBeanImplClass.newInstance();
             Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
-            SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+            setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
             startMethod.invoke(namingBean, new Object[] {});
          }
          catch (Exception e)
@@ -109,4 +112,28 @@
    {
       return 300000;
    }
+   
+   static private void setSystemProperty(final String name, final String value)
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         System.setProperty(name, value);
+         return;
+      }
+      
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.setProperty(name, value);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+   }
 }

Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java	2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java	2009-04-14 10:30:40 UTC (rev 5026)
@@ -24,6 +24,10 @@
 
 import java.lang.reflect.Method;
 import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
 import javax.management.ObjectName;
@@ -176,7 +180,7 @@
             namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
             namingBean = namingBeanImplClass.newInstance();
             Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
-            SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+            setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
             startMethod.invoke(namingBean, new Object[] {});
          }
          catch (Exception e)
@@ -218,5 +222,28 @@
          return new JNDIDetectorTest1.TestNetworkRegistry();
       }
    }
-
+   
+   static private void setSystemProperty(final String name, final String value)
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         System.setProperty(name, value);
+         return;
+      }
+      
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.setProperty(name, value);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+   }
 }
\ No newline at end of file

Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java	2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java	2009-04-14 10:30:40 UTC (rev 5026)
@@ -24,6 +24,10 @@
 
 import java.lang.reflect.Method;
 import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
 import org.apache.log4j.Level;
 import org.jboss.jrunit.harness.TestDriver;
 import org.jboss.remoting.samples.detection.jndi.SimpleJNDIServer;
@@ -58,7 +62,7 @@
             namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
             namingBean = namingBeanImplClass.newInstance();
             Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
-            SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+            setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
             startMethod.invoke(namingBean, new Object[] {});
          }
          catch (Exception e)
@@ -130,4 +134,28 @@
    {
       return 300000;
    }
+   
+   static private void setSystemProperty(final String name, final String value)
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         System.setProperty(name, value);
+         return;
+      }
+      
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.setProperty(name, value);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+   }
 }
\ No newline at end of file

Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java	2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java	2009-04-14 10:30:40 UTC (rev 5026)
@@ -44,6 +44,9 @@
 import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -132,7 +135,7 @@
          namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
          namingBean = namingBeanImplClass.newInstance();
          Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
-         SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+         setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
          startMethod.invoke(namingBean, new Object[] {});
       }
       catch (Exception e)
@@ -313,4 +316,28 @@
          // NO OP as we do not need a reference back to the server invoker
       }
    }
+   
+   static private void setSystemProperty(final String name, final String value)
+   {
+      if (SecurityUtility.skipAccessControl())
+      {
+         System.setProperty(name, value);
+         return;
+      }
+      
+      try
+      {
+         AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws Exception
+            {
+               return System.setProperty(name, value);
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (RuntimeException) e.getCause();
+      }
+   }
 }




More information about the jboss-remoting-commits mailing list