Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:23:07 -0400 (Tue, 14 Apr 2009)
New Revision: 5019
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility and ServletSecurityUtility.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java 2009-04-14
10:22:29 UTC (rev 5018)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/web/ServerInvokerServlet.java 2009-04-14
10:23:07 UTC (rev 5019)
@@ -28,9 +28,8 @@
import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.transport.servlet.ServletServerInvokerMBean;
import org.jboss.remoting.util.SecurityUtility;
-import org.jboss.remoting.util.ServletSecurityUtility;
-
import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -43,7 +42,14 @@
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
import java.util.Iterator;
/**
@@ -133,7 +139,7 @@
}
byteOutputStream.flush();
byte[] totalByteArray = byteOutputStream.toByteArray();
- byte[] out = ServletSecurityUtility.processRequest(servletInvoker, request,
totalByteArray, response);
+ byte[] out = processRequest(servletInvoker, request, totalByteArray, response);
ServletOutputStream outStream = response.getOutputStream();
outStream.write(out);
outStream.flush();
@@ -287,7 +293,7 @@
{
try
{
- MBeanServer s = SecurityUtility.getPlatformMBeanServer();
+ MBeanServer s = getPlatformMBeanServer();
log.debug("Using platform MBeanServer");
return s;
}
@@ -297,7 +303,7 @@
}
}
- Iterator i = SecurityUtility.findMBeanServer(null).iterator();
+ Iterator i = findMBeanServer(null).iterator();
while(i.hasNext())
{
MBeanServer server = (MBeanServer) i.next();
@@ -315,4 +321,106 @@
return null;
}
+
+ static private ArrayList findMBeanServer(final String agentId)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return MBeanServerFactory.findMBeanServer(agentId);
+ }
+
+ return (ArrayList)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return MBeanServerFactory.findMBeanServer(agentId);
+ }
+ });
+ }
+
+ static private MBeanServer getPlatformMBeanServer()
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ Class c = null;
+ try
+ {
+ c = Class.forName("java.lang.management.ManagementFactory");
+ }
+ catch (Exception e)
+ {
+ System.out.println("Unable to access
java.lang.management.ManagementFactory: must be using jdk 1.4");
+ return null;
+ }
+ Method m = c.getMethod("getPlatformMBeanServer", new Class[] {});
+ MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
+ return s;
+ }
+
+ try
+ {
+ return (MBeanServer) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run()
+ throws NoSuchMethodException, IllegalAccessException,
InvocationTargetException
+ {
+ Class c = null;
+ try
+ {
+ c = Class.forName("java.lang.management.ManagementFactory");
+ }
+ catch (Exception e)
+ {
+ System.out.println("Unable to access
java.lang.management.ManagementFactory: must be using jdk 1.4");
+ return null;
+ }
+ Method m = c.getMethod("getPlatformMBeanServer", new Class[]
{});
+ MBeanServer s = (MBeanServer) m.invoke(null, new Object[] {});
+ return s;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof NoSuchMethodException)
+ throw (NoSuchMethodException) cause;
+ else if (cause instanceof IllegalAccessException)
+ throw (IllegalAccessException) cause;
+ else
+ throw (InvocationTargetException) cause;
+ }
+ }
+
+ static private byte[] processRequest(final ServletServerInvokerMBean invoker,
+ final HttpServletRequest request,
+ final byte[] byteArray,
+ final HttpServletResponse response)
+ throws ServletException, IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return invoker.processRequest(request, byteArray, response);
+ }
+
+ try
+ {
+ return (byte[]) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws ServletException, IOException
+ {
+ return invoker.processRequest(request, byteArray, response);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof ServletException)
+ throw (ServletException) cause;
+ else
+ throw (IOException) e.getCause();
+ }
+ }
}
\ No newline at end of file