equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
35 import java.rmi.server.ObjID; |
35 import java.rmi.server.ObjID; |
36 import java.rmi.server.RemoteCall; |
36 import java.rmi.server.RemoteCall; |
37 import java.rmi.server.RemoteServer; |
37 import java.rmi.server.RemoteServer; |
38 import java.rmi.server.ServerNotActiveException; |
38 import java.rmi.server.ServerNotActiveException; |
39 import java.security.AccessControlContext; |
39 import java.security.AccessControlContext; |
|
40 import java.security.AccessController; |
|
41 import java.security.Permissions; |
40 import java.security.PrivilegedAction; |
42 import java.security.PrivilegedAction; |
|
43 import java.security.ProtectionDomain; |
41 import sun.rmi.runtime.Log; |
44 import sun.rmi.runtime.Log; |
42 import sun.rmi.server.Dispatcher; |
45 import sun.rmi.server.Dispatcher; |
43 import sun.rmi.server.UnicastServerRef; |
46 import sun.rmi.server.UnicastServerRef; |
44 |
47 |
45 /** |
48 /** |
66 /** References the current transport when a call is being serviced */ |
69 /** References the current transport when a call is being serviced */ |
67 private static final ThreadLocal<Transport> currentTransport = new ThreadLocal<>(); |
70 private static final ThreadLocal<Transport> currentTransport = new ThreadLocal<>(); |
68 |
71 |
69 /** ObjID for DGCImpl */ |
72 /** ObjID for DGCImpl */ |
70 private static final ObjID dgcID = new ObjID(ObjID.DGC_ID); |
73 private static final ObjID dgcID = new ObjID(ObjID.DGC_ID); |
|
74 |
|
75 /** AccessControlContext for setting context ClassLoader */ |
|
76 private static final AccessControlContext SETCCL_ACC; |
|
77 static { |
|
78 Permissions perms = new Permissions(); |
|
79 perms.add(new RuntimePermission("setContextClassLoader")); |
|
80 ProtectionDomain[] pd = { new ProtectionDomain(null, perms) }; |
|
81 SETCCL_ACC = new AccessControlContext(pd); |
|
82 } |
71 |
83 |
72 /** |
84 /** |
73 * Returns a <I>Channel</I> that generates connections to the |
85 * Returns a <I>Channel</I> that generates connections to the |
74 * endpoint <I>ep</I>. A Channel is an object that creates and |
86 * endpoint <I>ep</I>. A Channel is an object that creates and |
75 * manages connections of a particular type to some particular |
87 * manages connections of a particular type to some particular |
114 * the connection being dispatched by the current thread. The current |
126 * the connection being dispatched by the current thread. The current |
115 * access control context is passed as a parameter to avoid the overhead of |
127 * access control context is passed as a parameter to avoid the overhead of |
116 * an additional call to AccessController.getContext. |
128 * an additional call to AccessController.getContext. |
117 */ |
129 */ |
118 protected abstract void checkAcceptPermission(AccessControlContext acc); |
130 protected abstract void checkAcceptPermission(AccessControlContext acc); |
|
131 |
|
132 /** |
|
133 * Sets the context class loader for the current thread. |
|
134 */ |
|
135 private static void setContextClassLoader(ClassLoader ccl) { |
|
136 AccessController.doPrivileged((PrivilegedAction<Void>)() -> { |
|
137 Thread.currentThread().setContextClassLoader(ccl); |
|
138 return null; |
|
139 }, SETCCL_ACC); |
|
140 } |
119 |
141 |
120 /** |
142 /** |
121 * Service an incoming remote call. When a message arrives on the |
143 * Service an incoming remote call. When a message arrives on the |
122 * connection indicating the beginning of a remote call, the |
144 * connection indicating the beginning of a remote call, the |
123 * threads are required to call the <I>serviceCall</I> method of |
145 * threads are required to call the <I>serviceCall</I> method of |
163 |
185 |
164 final AccessControlContext acc = |
186 final AccessControlContext acc = |
165 target.getAccessControlContext(); |
187 target.getAccessControlContext(); |
166 ClassLoader ccl = target.getContextClassLoader(); |
188 ClassLoader ccl = target.getContextClassLoader(); |
167 |
189 |
168 Thread t = Thread.currentThread(); |
190 ClassLoader savedCcl = Thread.currentThread().getContextClassLoader(); |
169 ClassLoader savedCcl = t.getContextClassLoader(); |
|
170 |
191 |
171 try { |
192 try { |
172 t.setContextClassLoader(ccl); |
193 setContextClassLoader(ccl); |
173 currentTransport.set(this); |
194 currentTransport.set(this); |
174 try { |
195 try { |
175 java.security.AccessController.doPrivileged( |
196 java.security.AccessController.doPrivileged( |
176 new java.security.PrivilegedExceptionAction<Void>() { |
197 new java.security.PrivilegedExceptionAction<Void>() { |
177 public Void run() throws IOException { |
198 public Void run() throws IOException { |
182 }, acc); |
203 }, acc); |
183 } catch (java.security.PrivilegedActionException pae) { |
204 } catch (java.security.PrivilegedActionException pae) { |
184 throw (IOException) pae.getException(); |
205 throw (IOException) pae.getException(); |
185 } |
206 } |
186 } finally { |
207 } finally { |
187 t.setContextClassLoader(savedCcl); |
208 setContextClassLoader(savedCcl); |
188 currentTransport.set(null); |
209 currentTransport.set(null); |
189 } |
210 } |
190 |
211 |
191 } catch (IOException ex) { |
212 } catch (IOException ex) { |
192 transportLog.log(Log.BRIEF, |
213 transportLog.log(Log.BRIEF, |