Author: ron.sigal(a)jboss.com
Date: 2008-05-13 00:55:52 -0400 (Tue, 13 May 2008)
New Revision: 4180
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-978: Added several new methods, many of them related to RMI.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-05-13
04:54:55 UTC (rev 4179)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-05-13
04:55:52 UTC (rev 4180)
@@ -28,13 +28,24 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.OutputStream;
import java.lang.reflect.Method;
+import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;
+import java.rmi.AccessException;
+import java.rmi.NotBoundException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.UnicastRemoteObject;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
@@ -49,6 +60,9 @@
import org.jboss.remoting.Remoting;
import org.jboss.remoting.security.ServerSocketFactoryMBean;
+import org.jboss.remoting.transport.rmi.RMIServerInvoker;
+import org.jboss.remoting.transport.rmi.RMIServerInvokerInf;
+import org.jboss.remoting.transport.rmi.RemotingRMIClientSocketFactory;
import org.jboss.serial.io.JBossObjectInputStream;
import org.jboss.serial.io.JBossObjectOutputStream;
@@ -693,7 +707,9 @@
{
if (skipAccessControl)
{
- return c.getDeclaredMethod(name, parameterTypes);
+ Method m = c.getDeclaredMethod(name, parameterTypes);
+ m.setAccessible(true);
+ return m;
}
try
@@ -702,7 +718,9 @@
{
public Object run() throws NoSuchMethodException
{
- return c.getDeclaredMethod(name, parameterTypes);
+ Method m = c.getDeclaredMethod(name, parameterTypes);
+ m.setAccessible(true);
+ return m;
}
});
}
@@ -854,6 +872,32 @@
}
+ static public void connect(final HttpURLConnection conn) throws IOException
+ {
+ if (skipAccessControl)
+ {
+ conn.connect();
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ conn.connect();
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
static public ServerSocket createServerSocket(final ServerSocketFactoryMBean ssf)
throws IOException
{
if (skipAccessControl)
@@ -1276,4 +1320,244 @@
throw (UnknownHostException) e.getCause();
}
}
+
+
+ static public OutputStream getOutputStream(final HttpURLConnection conn)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return conn.getOutputStream();
+ }
+
+ try
+ {
+ return (OutputStream)AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return conn.getOutputStream();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public int getResponseCode(final HttpURLConnection conn)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return conn.getResponseCode();
+ }
+
+ try
+ {
+ return ((Integer) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return new Integer(conn.getResponseCode());
+ }
+ })).intValue();
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public Object callTransport(final RMIServerInvokerInf server, final Object
payload)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ return server.transport(payload);
+ }
+
+ try
+ {
+ return AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return server.transport(payload);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public Registry createRegistry(final int port) throws RemoteException
+ {
+ if (skipAccessControl)
+ {
+ return LocateRegistry.createRegistry(port);
+ }
+
+ try
+ {
+ return (Registry) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws RemoteException
+ {
+ return LocateRegistry.createRegistry(port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RemoteException) e.getCause();
+ }
+ }
+
+
+ static public Remote exportObject(final Remote object,
+ final int port,
+ final RMIClientSocketFactory csf,
+ final RMIServerSocketFactory ssf)
+ throws RemoteException
+ {
+ if (skipAccessControl)
+ {
+ return UnicastRemoteObject.exportObject(object, port, csf, ssf);
+ }
+
+ try
+ {
+ return (Remote) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws RemoteException
+ {
+ return UnicastRemoteObject.exportObject(object, port, csf, ssf);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RemoteException) e.getCause();
+ }
+ }
+
+
+ static public Registry getRegistry(final int port) throws RemoteException
+ {
+ if (skipAccessControl)
+ {
+ return LocateRegistry.getRegistry(port);
+ }
+
+ try
+ {
+ return (Registry) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws RemoteException
+ {
+ return LocateRegistry.getRegistry(port);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RemoteException) e.getCause();
+ }
+ }
+
+
+ static public Remote lookup(final Registry registry, final String name)
+ throws RemoteException, NotBoundException
+ {
+ if (skipAccessControl)
+ {
+ return registry.lookup(name);
+ }
+
+ try
+ {
+ return (Remote) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return registry.lookup(name);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof RemoteException)
+ throw (RemoteException) cause;
+ else
+ throw (NotBoundException) cause;
+ }
+ }
+
+
+ static public void rebind(final Registry registry, final String name, final Remote
object)
+ throws IOException
+ {
+ if (skipAccessControl)
+ {
+ registry.rebind(name, object);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ registry.rebind(name, object);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+
+ static public void unbind(final Registry registry, final String name)
+ throws AccessException, RemoteException, NotBoundException
+ {
+ if (skipAccessControl)
+ {
+ registry.unbind(name);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws AccessException, RemoteException,
NotBoundException
+ {
+ registry.unbind(name);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof AccessException)
+ throw (AccessException) cause;
+ else if (cause instanceof RemoteException)
+ throw (RemoteException) cause;
+ else
+ throw (NotBoundException) cause;
+ }
+ }
}
\ No newline at end of file