Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:13:51 -0400 (Tue, 14 Apr 2009)
New Revision: 5001
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java 2009-04-14
10:13:24 UTC (rev 5000)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/util/DetectorUtil.java 2009-04-14
10:13:51 UTC (rev 5001)
@@ -21,7 +21,12 @@
*/
package org.jboss.remoting.detection.util;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import org.apache.log4j.Level;
import org.jboss.logging.Logger;
@@ -99,11 +104,11 @@
org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
Logger log = Logger.getLogger(getClass());
- SecurityUtility.setSystemProperty("jboss.identity",
String.valueOf(System.currentTimeMillis()));
+ setSystemProperty("jboss.identity",
String.valueOf(System.currentTimeMillis()));
- MBeanServer server = SecurityUtility.createMBeanServer();
+ MBeanServer server = createMBeanServer();
NetworkRegistry registry = NetworkRegistry.getInstance();
- SecurityUtility.registerMBean(server, registry, new
ObjectName("remoting:type=NetworkRegistry"));
+ registerMBean(server, registry, new
ObjectName("remoting:type=NetworkRegistry"));
InvokerLocator locator = new InvokerLocator("socket://localhost");
//ClassLoader clsLoader = Thread.currentThread().getContextClassLoader();
@@ -115,7 +120,7 @@
Connector connector = new Connector();
connector.setInvokerLocator(locator.getLocatorURI());
ObjectName obj = new
ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
- SecurityUtility.registerMBean(server, connector, obj);
+ registerMBean(server, connector, obj);
//connector.create();
connector.start();
@@ -140,7 +145,7 @@
objName = new ObjectName("remoting:type=Detector,transport=jndi");
}
- SecurityUtility.registerMBean(server, detector, objName);
+ registerMBean(server, detector, objName);
detector.start();
System.err.println("Starting Detector");
@@ -214,5 +219,76 @@
return type;
}
-
+ static private MBeanServer createMBeanServer() throws Exception
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return MBeanServerFactory.createMBeanServer();
+ }
+
+ try
+ {
+ return (MBeanServer) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return MBeanServerFactory.createMBeanServer();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+
+ static private void registerMBean(final MBeanServer server, final Object o, final
ObjectName name)
+ throws Exception
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ server.registerMBean(o, name);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ server.registerMBean(o, name);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (Exception) e.getCause();
+ }
+ }
+
+ 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();
+ }
+ }
}
Show replies by date