Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:24:31 -0400 (Tue, 14 Apr 2009)
New Revision: 5020
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-04-14
10:23:07 UTC (rev 5019)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-04-14
10:24:31 UTC (rev 5020)
@@ -20,6 +20,7 @@
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
import org.jboss.util.propertyeditor.PropertyEditors;
+import java.beans.IntrospectionException;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -29,6 +30,10 @@
import java.net.Socket;
import java.net.InetSocketAddress;
import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -488,12 +493,12 @@
{
Properties props = new Properties();
props.putAll(configuration);
- SecurityUtility.mapJavaBeanProperties(MicroSocketClientInvoker.this, props,
false);
+ mapJavaBeanProperties(MicroSocketClientInvoker.this, props, false);
configureParameters();
if (!InvokerLocator.MULTIHOME.equals(locator.getHost()))
{
- addr = SecurityUtility.getAddressByName(locator.getHost());
+ addr = getAddressByName(locator.getHost());
port = locator.getPort();
address = createServerAddress(addr, port);
}
@@ -504,7 +509,7 @@
{
// Treat as in non MULTIHOME case.
Home home = (Home) homes.iterator().next();
- addr = SecurityUtility.getAddressByName(home.host);
+ addr = getAddressByName(home.host);
address = createServerAddress(addr, home.port);
}
}
@@ -650,7 +655,7 @@
try
{
home = (Home) it.next();
- addr = SecurityUtility.getAddressByName(home.host);
+ addr = getAddressByName(home.host);
address = createServerAddress(addr, home.port);
invoke(new InvocationRequest(null, null, ServerInvoker.ECHO, null, null,
null));
if (trace) log.trace(this + " able to contact server at: " +
home);
@@ -1140,7 +1145,7 @@
Socket s = new Socket();
configureSocket(s);
InetSocketAddress inetAddr = new InetSocketAddress(address, port);
- SecurityUtility.connect(s, inetAddr);
+ connect(s, inetAddr);
return s;
}
@@ -1266,7 +1271,81 @@
if (trace) { log.trace(this + " writing version " + version + " on
output stream"); }
outputStream.write(version);
}
+
+ static private void mapJavaBeanProperties(final Object o, final Properties props,
final boolean isStrict)
+ throws IntrospectionException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return;
+ }
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IntrospectionException
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IntrospectionException) e.getCause();
+ }
+ }
+
+ static private void connect(final Socket socket, final InetSocketAddress address)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ socket.connect(address);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ socket.connect(address);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private InetAddress getAddressByName(final String host) throws
UnknownHostException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return InetAddress.getByName(host);
+ }
+
+ try
+ {
+ return (InetAddress)AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return InetAddress.getByName(host);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
// Inner classes
--------------------------------------------------------------------------------
}
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-04-14
10:23:07 UTC (rev 5019)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-04-14
10:24:31 UTC (rev 5020)
@@ -52,6 +52,8 @@
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
@@ -99,7 +101,7 @@
return idGenerator++;
}
- private static ClassLoader classLoader =
SecurityUtility.getClassLoader(ServerThread.class);
+ private static ClassLoader classLoader = getClassLoader(ServerThread.class);
// Attributes
-----------------------------------------------------------------------------------
@@ -1087,4 +1089,20 @@
public static class EvictionException extends Exception
{
}
+
+ static private ClassLoader getClassLoader(final Class c)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return c.getClassLoader();
+ }
+
+ return (ClassLoader)AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ return c.getClassLoader();
+ }
+ });
+ }
}
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java 2009-04-14
10:23:07 UTC (rev 5019)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketClientInvoker.java 2009-04-14
10:24:31 UTC (rev 5020)
@@ -36,6 +36,9 @@
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.InetSocketAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Map;
/**
@@ -200,7 +203,7 @@
timeout = 0;
}
- SecurityUtility.connect(s, inetAddr, timeout);
+ connect(s, inetAddr, timeout);
return s;
}
@@ -277,4 +280,30 @@
return "SocketClientInvoker[" +
Integer.toHexString(System.identityHashCode(this)) + ", " +
locator.getProtocol() + "://" + locator.getHost() + ":" +
locator.getPort() + "]";
}
+
+ static private void connect(final Socket socket, final InetSocketAddress address,
final int timeout)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ socket.connect(address, timeout);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ socket.connect(address, timeout);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
}
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-04-14
10:23:07 UTC (rev 5019)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-04-14
10:24:31 UTC (rev 5020)
@@ -25,6 +25,7 @@
import org.jboss.remoting.Home;
import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.security.ServerSocketFactoryMBean;
import org.jboss.remoting.util.SecurityUtility;
import org.jboss.remoting.util.TimerUtil;
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
@@ -34,12 +35,18 @@
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLException;
+import java.beans.IntrospectionException;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.net.SocketAddress;
import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -201,7 +208,7 @@
protected void setup() throws Exception
{
props.putAll(getConfiguration());
- SecurityUtility.mapJavaBeanProperties(this, props, false);
+ mapJavaBeanProperties(this, props, false);
super.setup();
String ssclass = props.getProperty(SERVER_SOCKET_CLASS_FLAG);
if(ssclass != null)
@@ -321,7 +328,7 @@
ss.setReuseAddress(getReuseAddress());
configureServerSocket(ss);
InetSocketAddress address = new InetSocketAddress(bindAddress, serverBindPort);
- SecurityUtility.bind(ss, address, backlog);
+ bind(ss, address, backlog);
return ss;
}
@@ -333,7 +340,7 @@
while (it.hasNext())
{
Home home = (Home) it.next();
- InetAddress inetAddress = SecurityUtility.getAddressByName(home.host);
+ InetAddress inetAddress = getAddressByName(home.host);
ServerSocket ss = null;
try
@@ -342,7 +349,7 @@
ss.setReuseAddress(getReuseAddress());
configureServerSocket(ss);
InetSocketAddress address = new InetSocketAddress(inetAddress, home.port);
- SecurityUtility.bind(ss, address, backlog);
+ bind(ss, address, backlog);
if (log.isDebugEnabled()) log.debug(this + " created " + ss);
}
catch (SocketException e)
@@ -1010,7 +1017,7 @@
if(trace) { log.trace(this + " is going to wait on
serverSocket.accept()"); }
- Socket socket = SecurityUtility.accept(serverSocket);
+ Socket socket = accept(serverSocket);
if(trace) { log.trace(this + " accepted " + socket); }
// the acceptor thread should spend as little time as possbile doing any
kind of
@@ -1068,4 +1075,102 @@
this.serverSocket = serverSocket;
}
}
+
+ static private void mapJavaBeanProperties(final Object o, final Properties props,
final boolean isStrict)
+ throws IntrospectionException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IntrospectionException
+ {
+ PropertyEditors.mapJavaBeanProperties(o, props, isStrict);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IntrospectionException) e.getCause();
+ }
+ }
+
+ static private Socket accept(final ServerSocket ss) throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return ss.accept();
+ }
+
+ try
+ {
+ return (Socket)AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return ss.accept();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private void bind(final ServerSocket ss, final SocketAddress address,
+ final int backlog) throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ ss.bind(address, backlog);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ ss.bind(address, backlog);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
+
+ static private InetAddress getAddressByName(final String host) throws
UnknownHostException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return InetAddress.getByName(host);
+ }
+
+ try
+ {
+ return (InetAddress)AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+ public Object run() throws IOException
+ {
+ return InetAddress.getByName(host);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (UnknownHostException) e.getCause();
+ }
+ }
}
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java 2009-04-14
10:23:07 UTC (rev 5019)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketClientInvoker.java 2009-04-14
10:24:31 UTC (rev 5020)
@@ -26,6 +26,9 @@
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Map;
import javax.net.SocketFactory;
@@ -182,7 +185,7 @@
timeout = 0;
}
- SecurityUtility.connect(s, inetAddr, timeout);
+ connect(s, inetAddr, timeout);
if (s instanceof SSLSocket)
{
@@ -233,4 +236,30 @@
sslSocket.getSession();
repeater.waitForHandshake();
}
+
+ static private void connect(final Socket socket, final InetSocketAddress address,
final int timeout)
+ throws IOException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ socket.connect(address, timeout);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ socket.connect(address, timeout);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (IOException) e.getCause();
+ }
+ }
}
\ No newline at end of file