Commit af68e613 authored by hpi1's avatar hpi1

BDJSockets: reflection needs doPrivileged()

parent fe57c9ad
......@@ -24,6 +24,10 @@ import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedList;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.net.Socket;
import java.net.SocketImpl;
......@@ -73,11 +77,17 @@ class BDJSockets {
private Socket getSocket(SocketImpl socketImpl) {
try {
Method getSocket = SocketImpl.class.getDeclaredMethod("getSocket", new Class[0]);
getSocket.setAccessible(true);
return (Socket) getSocket.invoke(socketImpl, new Object[0]);
} catch (Exception e) {
logger.error("Failed to get Socket: " + e + " at " + Logger.dumpStack());
final SocketImpl si = socketImpl;
return (Socket)AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws Exception {
Method getSocket = SocketImpl.class.getDeclaredMethod("getSocket", new Class[0]);
getSocket.setAccessible(true);
return getSocket.invoke(si, new Object[0]);
}
});
} catch (PrivilegedActionException e) {
logger.error("Failed to get Socket: " + e.getException() + " at " + Logger.dumpStack());
return null;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment