提交 d7e3d36a 编写于 作者: S smarks

8055309: RMI needs better transportation considerations

Reviewed-by: alanb, igerasim, skoivu, msheppar
上级 c12102a9
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,6 +37,10 @@ import java.rmi.server.RemoteCall; ...@@ -37,6 +37,10 @@ import java.rmi.server.RemoteCall;
import java.rmi.server.RemoteServer; import java.rmi.server.RemoteServer;
import java.rmi.server.ServerNotActiveException; import java.rmi.server.ServerNotActiveException;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.Permissions;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import sun.rmi.runtime.Log; import sun.rmi.runtime.Log;
import sun.rmi.server.Dispatcher; import sun.rmi.server.Dispatcher;
import sun.rmi.server.UnicastServerRef; import sun.rmi.server.UnicastServerRef;
...@@ -68,6 +72,15 @@ public abstract class Transport { ...@@ -68,6 +72,15 @@ public abstract class Transport {
/** ObjID for DGCImpl */ /** ObjID for DGCImpl */
private static final ObjID dgcID = new ObjID(ObjID.DGC_ID); private static final ObjID dgcID = new ObjID(ObjID.DGC_ID);
/** AccessControlContext for setting context ClassLoader */
private static final AccessControlContext SETCCL_ACC;
static {
Permissions perms = new Permissions();
perms.add(new RuntimePermission("setContextClassLoader"));
ProtectionDomain[] pd = { new ProtectionDomain(null, perms) };
SETCCL_ACC = new AccessControlContext(pd);
}
/** /**
* Returns a <I>Channel</I> that generates connections to the * Returns a <I>Channel</I> that generates connections to the
* endpoint <I>ep</I>. A Channel is an object that creates and * endpoint <I>ep</I>. A Channel is an object that creates and
...@@ -116,6 +129,16 @@ public abstract class Transport { ...@@ -116,6 +129,16 @@ public abstract class Transport {
*/ */
protected abstract void checkAcceptPermission(AccessControlContext acc); protected abstract void checkAcceptPermission(AccessControlContext acc);
/**
* Sets the context class loader for the current thread.
*/
private static void setContextClassLoader(ClassLoader ccl) {
AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
Thread.currentThread().setContextClassLoader(ccl);
return null;
}, SETCCL_ACC);
}
/** /**
* Service an incoming remote call. When a message arrives on the * Service an incoming remote call. When a message arrives on the
* connection indicating the beginning of a remote call, the * connection indicating the beginning of a remote call, the
...@@ -164,11 +187,10 @@ public abstract class Transport { ...@@ -164,11 +187,10 @@ public abstract class Transport {
target.getAccessControlContext(); target.getAccessControlContext();
ClassLoader ccl = target.getContextClassLoader(); ClassLoader ccl = target.getContextClassLoader();
Thread t = Thread.currentThread(); ClassLoader savedCcl = Thread.currentThread().getContextClassLoader();
ClassLoader savedCcl = t.getContextClassLoader();
try { try {
t.setContextClassLoader(ccl); setContextClassLoader(ccl);
currentTransport.set(this); currentTransport.set(this);
try { try {
java.security.AccessController.doPrivileged( java.security.AccessController.doPrivileged(
...@@ -183,7 +205,7 @@ public abstract class Transport { ...@@ -183,7 +205,7 @@ public abstract class Transport {
throw (IOException) pae.getException(); throw (IOException) pae.getException();
} }
} finally { } finally {
t.setContextClassLoader(savedCcl); setContextClassLoader(savedCcl);
currentTransport.set(null); currentTransport.set(null);
} }
......
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -49,6 +49,9 @@ import java.rmi.server.ServerNotActiveException; ...@@ -49,6 +49,9 @@ import java.rmi.server.ServerNotActiveException;
import java.rmi.server.UID; import java.rmi.server.UID;
import java.security.AccessControlContext; import java.security.AccessControlContext;
import java.security.AccessController; import java.security.AccessController;
import java.security.Permissions;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -123,6 +126,14 @@ public class TCPTransport extends Transport { ...@@ -123,6 +126,14 @@ public class TCPTransport extends Transport {
private static final ThreadLocal<ConnectionHandler> private static final ThreadLocal<ConnectionHandler>
threadConnectionHandler = new ThreadLocal<>(); threadConnectionHandler = new ThreadLocal<>();
/** an AccessControlContext with no permissions */
private static final AccessControlContext NOPERMS_ACC;
static {
Permissions perms = new Permissions();
ProtectionDomain[] pd = { new ProtectionDomain(null, perms) };
NOPERMS_ACC = new AccessControlContext(pd);
}
/** endpoints for this transport */ /** endpoints for this transport */
private final LinkedList<TCPEndpoint> epList; private final LinkedList<TCPEndpoint> epList;
/** number of objects exported on this transport */ /** number of objects exported on this transport */
...@@ -662,16 +673,19 @@ public class TCPTransport extends Transport { ...@@ -662,16 +673,19 @@ public class TCPTransport extends Transport {
} }
public void run() { public void run() {
Thread t = Thread.currentThread(); AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
String name = t.getName(); Thread t = Thread.currentThread();
try { String name = t.getName();
t.setName("RMI TCP Connection(" + try {
connectionCount.incrementAndGet() + t.setName("RMI TCP Connection(" +
")-" + remoteHost); connectionCount.incrementAndGet() +
run0(); ")-" + remoteHost);
} finally { run0();
t.setName(name); } finally {
} t.setName(name);
}
return null;
}, NOPERMS_ACC);
} }
private void run0() { private void run0() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册