author | jdn |
Tue, 04 Jun 2013 15:33:42 -0700 | |
changeset 17946 | 7791613dcbfd |
parent 16906 | 44dfee24cb71 |
child 18253 | 4323a5fe8bc4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14208 | 2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.security; |
|
27 |
||
28 |
import sun.security.util.Debug; |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
29 |
import sun.reflect.CallerSensitive; |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
30 |
import sun.reflect.Reflection; |
2 | 31 |
|
32 |
/** |
|
33 |
* <p> The AccessController class is used for access control operations |
|
34 |
* and decisions. |
|
35 |
* |
|
36 |
* <p> More specifically, the AccessController class is used for |
|
37 |
* three purposes: |
|
38 |
* |
|
39 |
* <ul> |
|
40 |
* <li> to decide whether an access to a critical system |
|
41 |
* resource is to be allowed or denied, based on the security policy |
|
42 |
* currently in effect,<p> |
|
43 |
* <li>to mark code as being "privileged", thus affecting subsequent |
|
44 |
* access determinations, and<p> |
|
45 |
* <li>to obtain a "snapshot" of the current calling context so |
|
46 |
* access-control decisions from a different context can be made with |
|
47 |
* respect to the saved context. </ul> |
|
48 |
* |
|
49 |
* <p> The {@link #checkPermission(Permission) checkPermission} method |
|
50 |
* determines whether the access request indicated by a specified |
|
51 |
* permission should be granted or denied. A sample call appears |
|
52 |
* below. In this example, <code>checkPermission</code> will determine |
|
53 |
* whether or not to grant "read" access to the file named "testFile" in |
|
54 |
* the "/temp" directory. |
|
55 |
* |
|
56 |
* <pre> |
|
57 |
* |
|
58 |
* FilePermission perm = new FilePermission("/temp/testFile", "read"); |
|
59 |
* AccessController.checkPermission(perm); |
|
60 |
* |
|
61 |
* </pre> |
|
62 |
* |
|
63 |
* <p> If a requested access is allowed, |
|
64 |
* <code>checkPermission</code> returns quietly. If denied, an |
|
65 |
* AccessControlException is |
|
66 |
* thrown. AccessControlException can also be thrown if the requested |
|
67 |
* permission is of an incorrect type or contains an invalid value. |
|
68 |
* Such information is given whenever possible. |
|
69 |
* |
|
70 |
* Suppose the current thread traversed m callers, in the order of caller 1 |
|
71 |
* to caller 2 to caller m. Then caller m invoked the |
|
72 |
* <code>checkPermission</code> method. |
|
73 |
* The <code>checkPermission </code>method determines whether access |
|
74 |
* is granted or denied based on the following algorithm: |
|
75 |
* |
|
76 |
* <pre> {@code |
|
77 |
* for (int i = m; i > 0; i--) { |
|
78 |
* |
|
79 |
* if (caller i's domain does not have the permission) |
|
80 |
* throw AccessControlException |
|
81 |
* |
|
82 |
* else if (caller i is marked as privileged) { |
|
83 |
* if (a context was specified in the call to doPrivileged) |
|
84 |
* context.checkPermission(permission) |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
85 |
* if (limited permissions were specified in the call to doPrivileged) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
86 |
* for (each limited permission) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
87 |
* if (the limited permission implies the requested permission) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
88 |
* return; |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
89 |
* } |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
90 |
* } else |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
91 |
* return; |
2 | 92 |
* } |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
93 |
* } |
2 | 94 |
* |
95 |
* // Next, check the context inherited when the thread was created. |
|
96 |
* // Whenever a new thread is created, the AccessControlContext at |
|
97 |
* // that time is stored and associated with the new thread, as the |
|
98 |
* // "inherited" context. |
|
99 |
* |
|
100 |
* inheritedContext.checkPermission(permission); |
|
101 |
* }</pre> |
|
102 |
* |
|
103 |
* <p> A caller can be marked as being "privileged" |
|
104 |
* (see {@link #doPrivileged(PrivilegedAction) doPrivileged} and below). |
|
105 |
* When making access control decisions, the <code>checkPermission</code> |
|
106 |
* method stops checking if it reaches a caller that |
|
107 |
* was marked as "privileged" via a <code>doPrivileged</code> |
|
108 |
* call without a context argument (see below for information about a |
|
109 |
* context argument). If that caller's domain has the |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
110 |
* specified permission and at least one limiting permission argument (if any) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
111 |
* implies the requested permission, no further checking is done and |
2 | 112 |
* <code>checkPermission</code> |
113 |
* returns quietly, indicating that the requested access is allowed. |
|
114 |
* If that domain does not have the specified permission, an exception |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
115 |
* is thrown, as usual. If the caller's domain had the specified permission |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
116 |
* but it was not implied by any limiting permission arguments given in the call |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
117 |
* to <code>doPrivileged</code> then the permission checking continues |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
118 |
* until there are no more callers or another <code>doPrivileged</code> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
119 |
* call matches the requested permission and returns normally. |
2 | 120 |
* |
121 |
* <p> The normal use of the "privileged" feature is as follows. If you |
|
122 |
* don't need to return a value from within the "privileged" block, do |
|
123 |
* the following: |
|
124 |
* |
|
125 |
* <pre> {@code |
|
126 |
* somemethod() { |
|
127 |
* ...normal code here... |
|
128 |
* AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
129 |
* public Void run() { |
|
130 |
* // privileged code goes here, for example: |
|
131 |
* System.loadLibrary("awt"); |
|
132 |
* return null; // nothing to return |
|
133 |
* } |
|
134 |
* }); |
|
135 |
* ...normal code here... |
|
136 |
* }}</pre> |
|
137 |
* |
|
138 |
* <p> |
|
139 |
* PrivilegedAction is an interface with a single method, named |
|
140 |
* <code>run</code>. |
|
141 |
* The above example shows creation of an implementation |
|
142 |
* of that interface; a concrete implementation of the |
|
143 |
* <code>run</code> method is supplied. |
|
144 |
* When the call to <code>doPrivileged</code> is made, an |
|
145 |
* instance of the PrivilegedAction implementation is passed |
|
146 |
* to it. The <code>doPrivileged</code> method calls the |
|
147 |
* <code>run</code> method from the PrivilegedAction |
|
148 |
* implementation after enabling privileges, and returns the |
|
149 |
* <code>run</code> method's return value as the |
|
150 |
* <code>doPrivileged</code> return value (which is |
|
151 |
* ignored in this example). |
|
152 |
* |
|
153 |
* <p> If you need to return a value, you can do something like the following: |
|
154 |
* |
|
155 |
* <pre> {@code |
|
156 |
* somemethod() { |
|
157 |
* ...normal code here... |
|
158 |
* String user = AccessController.doPrivileged( |
|
159 |
* new PrivilegedAction<String>() { |
|
160 |
* public String run() { |
|
161 |
* return System.getProperty("user.name"); |
|
162 |
* } |
|
163 |
* }); |
|
164 |
* ...normal code here... |
|
165 |
* }}</pre> |
|
166 |
* |
|
167 |
* <p>If the action performed in your <code>run</code> method could |
|
168 |
* throw a "checked" exception (those listed in the <code>throws</code> clause |
|
169 |
* of a method), then you need to use the |
|
170 |
* <code>PrivilegedExceptionAction</code> interface instead of the |
|
171 |
* <code>PrivilegedAction</code> interface: |
|
172 |
* |
|
173 |
* <pre> {@code |
|
174 |
* somemethod() throws FileNotFoundException { |
|
175 |
* ...normal code here... |
|
176 |
* try { |
|
177 |
* FileInputStream fis = AccessController.doPrivileged( |
|
178 |
* new PrivilegedExceptionAction<FileInputStream>() { |
|
179 |
* public FileInputStream run() throws FileNotFoundException { |
|
180 |
* return new FileInputStream("someFile"); |
|
181 |
* } |
|
182 |
* }); |
|
183 |
* } catch (PrivilegedActionException e) { |
|
184 |
* // e.getException() should be an instance of FileNotFoundException, |
|
185 |
* // as only "checked" exceptions will be "wrapped" in a |
|
186 |
* // PrivilegedActionException. |
|
187 |
* throw (FileNotFoundException) e.getException(); |
|
188 |
* } |
|
189 |
* ...normal code here... |
|
190 |
* }}</pre> |
|
191 |
* |
|
192 |
* <p> Be *very* careful in your use of the "privileged" construct, and |
|
193 |
* always remember to make the privileged code section as small as possible. |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
194 |
* You can pass <code>Permission</code> arguments to further limit the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
195 |
* scope of the "privilege" (see below). |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
196 |
* |
2 | 197 |
* |
198 |
* <p> Note that <code>checkPermission</code> always performs security checks |
|
199 |
* within the context of the currently executing thread. |
|
200 |
* Sometimes a security check that should be made within a given context |
|
201 |
* will actually need to be done from within a |
|
202 |
* <i>different</i> context (for example, from within a worker thread). |
|
203 |
* The {@link #getContext() getContext} method and |
|
204 |
* AccessControlContext class are provided |
|
205 |
* for this situation. The <code>getContext</code> method takes a "snapshot" |
|
206 |
* of the current calling context, and places |
|
207 |
* it in an AccessControlContext object, which it returns. A sample call is |
|
208 |
* the following: |
|
209 |
* |
|
210 |
* <pre> |
|
211 |
* |
|
212 |
* AccessControlContext acc = AccessController.getContext() |
|
213 |
* |
|
214 |
* </pre> |
|
215 |
* |
|
216 |
* <p> |
|
217 |
* AccessControlContext itself has a <code>checkPermission</code> method |
|
218 |
* that makes access decisions based on the context <i>it</i> encapsulates, |
|
219 |
* rather than that of the current execution thread. |
|
220 |
* Code within a different context can thus call that method on the |
|
221 |
* previously-saved AccessControlContext object. A sample call is the |
|
222 |
* following: |
|
223 |
* |
|
224 |
* <pre> |
|
225 |
* |
|
226 |
* acc.checkPermission(permission) |
|
227 |
* |
|
228 |
* </pre> |
|
229 |
* |
|
230 |
* <p> There are also times where you don't know a priori which permissions |
|
231 |
* to check the context against. In these cases you can use the |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
232 |
* doPrivileged method that takes a context. You can also limit the scope |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
233 |
* of the privileged code by passing additional <code>Permission</code> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
234 |
* parameters. |
2 | 235 |
* |
236 |
* <pre> {@code |
|
237 |
* somemethod() { |
|
238 |
* AccessController.doPrivileged(new PrivilegedAction<Object>() { |
|
239 |
* public Object run() { |
|
240 |
* // Code goes here. Any permission checks within this |
|
241 |
* // run method will require that the intersection of the |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
242 |
* // caller's protection domain and the snapshot's |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
243 |
* // context have the desired permission. If a requested |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
244 |
* // permission is not implied by the limiting FilePermission |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
245 |
* // argument then checking of the thread continues beyond the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
246 |
* // caller of doPrivileged. |
2 | 247 |
* } |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
248 |
* }, acc, new FilePermission("/temp/*", read)); |
2 | 249 |
* ...normal code here... |
250 |
* }}</pre> |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
251 |
* <p> Passing a limiting <code>Permission</code> argument of an instance of |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
252 |
* <code>AllPermission</code> is equivalent to calling the equivalent |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
253 |
* <code>doPrivileged</code> method without limiting <code>Permission</code> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
254 |
* arguments. Passing a zero length array of <code>Permission</code> disables |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
255 |
* the code privileges so that checking always continues beyond the caller of |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
256 |
* that <code>doPrivileged</code> method. |
2 | 257 |
* |
258 |
* @see AccessControlContext |
|
259 |
* |
|
260 |
* @author Li Gong |
|
261 |
* @author Roland Schemers |
|
262 |
*/ |
|
263 |
||
264 |
public final class AccessController { |
|
265 |
||
266 |
/** |
|
267 |
* Don't allow anyone to instantiate an AccessController |
|
268 |
*/ |
|
269 |
private AccessController() { } |
|
270 |
||
271 |
/** |
|
272 |
* Performs the specified <code>PrivilegedAction</code> with privileges |
|
273 |
* enabled. The action is performed with <i>all</i> of the permissions |
|
274 |
* possessed by the caller's protection domain. |
|
275 |
* |
|
276 |
* <p> If the action's <code>run</code> method throws an (unchecked) |
|
277 |
* exception, it will propagate through this method. |
|
278 |
* |
|
279 |
* <p> Note that any DomainCombiner associated with the current |
|
280 |
* AccessControlContext will be ignored while the action is performed. |
|
281 |
* |
|
282 |
* @param action the action to be performed. |
|
283 |
* |
|
284 |
* @return the value returned by the action's <code>run</code> method. |
|
285 |
* |
|
286 |
* @exception NullPointerException if the action is <code>null</code> |
|
287 |
* |
|
288 |
* @see #doPrivileged(PrivilegedAction,AccessControlContext) |
|
289 |
* @see #doPrivileged(PrivilegedExceptionAction) |
|
290 |
* @see #doPrivilegedWithCombiner(PrivilegedAction) |
|
291 |
* @see java.security.DomainCombiner |
|
292 |
*/ |
|
293 |
||
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
294 |
@CallerSensitive |
2 | 295 |
public static native <T> T doPrivileged(PrivilegedAction<T> action); |
296 |
||
297 |
/** |
|
298 |
* Performs the specified <code>PrivilegedAction</code> with privileges |
|
299 |
* enabled. The action is performed with <i>all</i> of the permissions |
|
300 |
* possessed by the caller's protection domain. |
|
301 |
* |
|
302 |
* <p> If the action's <code>run</code> method throws an (unchecked) |
|
303 |
* exception, it will propagate through this method. |
|
304 |
* |
|
305 |
* <p> This method preserves the current AccessControlContext's |
|
306 |
* DomainCombiner (which may be null) while the action is performed. |
|
307 |
* |
|
308 |
* @param action the action to be performed. |
|
309 |
* |
|
310 |
* @return the value returned by the action's <code>run</code> method. |
|
311 |
* |
|
312 |
* @exception NullPointerException if the action is <code>null</code> |
|
313 |
* |
|
314 |
* @see #doPrivileged(PrivilegedAction) |
|
315 |
* @see java.security.DomainCombiner |
|
316 |
* |
|
317 |
* @since 1.6 |
|
318 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
319 |
@CallerSensitive |
2 | 320 |
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) { |
321 |
AccessControlContext acc = getStackAccessControlContext(); |
|
14213
91ba926457c6
7189490: More improvements to DomainCombiner checking
mullan
parents:
14208
diff
changeset
|
322 |
if (acc == null) { |
91ba926457c6
7189490: More improvements to DomainCombiner checking
mullan
parents:
14208
diff
changeset
|
323 |
return AccessController.doPrivileged(action); |
2 | 324 |
} |
14213
91ba926457c6
7189490: More improvements to DomainCombiner checking
mullan
parents:
14208
diff
changeset
|
325 |
DomainCombiner dc = acc.getAssignedCombiner(); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
326 |
return AccessController.doPrivileged(action, |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
327 |
preserveCombiner(dc, Reflection.getCallerClass())); |
2 | 328 |
} |
329 |
||
330 |
||
331 |
/** |
|
332 |
* Performs the specified <code>PrivilegedAction</code> with privileges |
|
333 |
* enabled and restricted by the specified |
|
334 |
* <code>AccessControlContext</code>. |
|
335 |
* The action is performed with the intersection of the permissions |
|
336 |
* possessed by the caller's protection domain, and those possessed |
|
337 |
* by the domains represented by the specified |
|
338 |
* <code>AccessControlContext</code>. |
|
339 |
* <p> |
|
340 |
* If the action's <code>run</code> method throws an (unchecked) exception, |
|
341 |
* it will propagate through this method. |
|
342 |
* |
|
343 |
* @param action the action to be performed. |
|
344 |
* @param context an <i>access control context</i> |
|
345 |
* representing the restriction to be applied to the |
|
346 |
* caller's domain's privileges before performing |
|
347 |
* the specified action. If the context is |
|
348 |
* <code>null</code>, |
|
349 |
* then no additional restriction is applied. |
|
350 |
* |
|
351 |
* @return the value returned by the action's <code>run</code> method. |
|
352 |
* |
|
353 |
* @exception NullPointerException if the action is <code>null</code> |
|
354 |
* |
|
355 |
* @see #doPrivileged(PrivilegedAction) |
|
356 |
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
|
357 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
358 |
@CallerSensitive |
2 | 359 |
public static native <T> T doPrivileged(PrivilegedAction<T> action, |
360 |
AccessControlContext context); |
|
361 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
362 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
363 |
/** |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
364 |
* Performs the specified <code>PrivilegedAction</code> with privileges |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
365 |
* enabled and restricted by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
366 |
* <code>AccessControlContext</code> and with a privilege scope limited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
367 |
* by specified <code>Permission</code> arguments. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
368 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
369 |
* The action is performed with the intersection of the permissions |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
370 |
* possessed by the caller's protection domain, and those possessed |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
371 |
* by the domains represented by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
372 |
* <code>AccessControlContext</code>. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
373 |
* <p> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
374 |
* If the action's <code>run</code> method throws an (unchecked) exception, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
375 |
* it will propagate through this method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
376 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
377 |
* @param action the action to be performed. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
378 |
* @param context an <i>access control context</i> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
379 |
* representing the restriction to be applied to the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
380 |
* caller's domain's privileges before performing |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
381 |
* the specified action. If the context is |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
382 |
* <code>null</code>, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
383 |
* then no additional restriction is applied. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
384 |
* @param perms the <code>Permission</code> arguments which limit the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
385 |
* scope of the caller's privileges. The number of arguments |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
386 |
* is variable. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
387 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
388 |
* @return the value returned by the action's <code>run</code> method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
389 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
390 |
* @throws NullPointerException if action or perms or any element of |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
391 |
* perms is <code>null</code> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
392 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
393 |
* @see #doPrivileged(PrivilegedAction) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
394 |
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
395 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
396 |
* @since 1.8 |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
397 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
398 |
@CallerSensitive |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
399 |
public static <T> T doPrivileged(PrivilegedAction<T> action, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
400 |
AccessControlContext context, Permission... perms) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
401 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
402 |
AccessControlContext parent = getContext(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
403 |
if (perms == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
404 |
throw new NullPointerException("null permissions parameter"); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
405 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
406 |
Class <?> caller = Reflection.getCallerClass(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
407 |
return AccessController.doPrivileged(action, createWrapper(null, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
408 |
caller, parent, context, perms)); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
409 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
410 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
411 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
412 |
/** |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
413 |
* Performs the specified <code>PrivilegedAction</code> with privileges |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
414 |
* enabled and restricted by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
415 |
* <code>AccessControlContext</code> and with a privilege scope limited |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
416 |
* by specified <code>Permission</code> arguments. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
417 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
418 |
* The action is performed with the intersection of the permissions |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
419 |
* possessed by the caller's protection domain, and those possessed |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
420 |
* by the domains represented by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
421 |
* <code>AccessControlContext</code>. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
422 |
* <p> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
423 |
* If the action's <code>run</code> method throws an (unchecked) exception, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
424 |
* it will propagate through this method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
425 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
426 |
* <p> This method preserves the current AccessControlContext's |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
427 |
* DomainCombiner (which may be null) while the action is performed. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
428 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
429 |
* @param action the action to be performed. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
430 |
* @param context an <i>access control context</i> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
431 |
* representing the restriction to be applied to the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
432 |
* caller's domain's privileges before performing |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
433 |
* the specified action. If the context is |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
434 |
* <code>null</code>, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
435 |
* then no additional restriction is applied. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
436 |
* @param perms the <code>Permission</code> arguments which limit the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
437 |
* scope of the caller's privileges. The number of arguments |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
438 |
* is variable. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
439 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
440 |
* @return the value returned by the action's <code>run</code> method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
441 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
442 |
* @throws NullPointerException if action or perms or any element of |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
443 |
* perms is <code>null</code> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
444 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
445 |
* @see #doPrivileged(PrivilegedAction) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
446 |
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
447 |
* @see java.security.DomainCombiner |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
448 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
449 |
* @since 1.8 |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
450 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
451 |
@CallerSensitive |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
452 |
public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
453 |
AccessControlContext context, Permission... perms) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
454 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
455 |
AccessControlContext parent = getContext(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
456 |
DomainCombiner dc = parent.getCombiner(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
457 |
if (dc == null && context != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
458 |
dc = context.getCombiner(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
459 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
460 |
if (perms == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
461 |
throw new NullPointerException("null permissions parameter"); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
462 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
463 |
Class <?> caller = Reflection.getCallerClass(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
464 |
return AccessController.doPrivileged(action, createWrapper(dc, caller, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
465 |
parent, context, perms)); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
466 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
467 |
|
2 | 468 |
/** |
469 |
* Performs the specified <code>PrivilegedExceptionAction</code> with |
|
470 |
* privileges enabled. The action is performed with <i>all</i> of the |
|
471 |
* permissions possessed by the caller's protection domain. |
|
472 |
* |
|
473 |
* <p> If the action's <code>run</code> method throws an <i>unchecked</i> |
|
474 |
* exception, it will propagate through this method. |
|
475 |
* |
|
476 |
* <p> Note that any DomainCombiner associated with the current |
|
477 |
* AccessControlContext will be ignored while the action is performed. |
|
478 |
* |
|
479 |
* @param action the action to be performed |
|
480 |
* |
|
481 |
* @return the value returned by the action's <code>run</code> method |
|
482 |
* |
|
483 |
* @exception PrivilegedActionException if the specified action's |
|
484 |
* <code>run</code> method threw a <i>checked</i> exception |
|
485 |
* @exception NullPointerException if the action is <code>null</code> |
|
486 |
* |
|
487 |
* @see #doPrivileged(PrivilegedAction) |
|
488 |
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
|
489 |
* @see #doPrivilegedWithCombiner(PrivilegedExceptionAction) |
|
490 |
* @see java.security.DomainCombiner |
|
491 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
492 |
@CallerSensitive |
2 | 493 |
public static native <T> T |
494 |
doPrivileged(PrivilegedExceptionAction<T> action) |
|
495 |
throws PrivilegedActionException; |
|
496 |
||
497 |
||
498 |
/** |
|
499 |
* Performs the specified <code>PrivilegedExceptionAction</code> with |
|
500 |
* privileges enabled. The action is performed with <i>all</i> of the |
|
501 |
* permissions possessed by the caller's protection domain. |
|
502 |
* |
|
503 |
* <p> If the action's <code>run</code> method throws an <i>unchecked</i> |
|
504 |
* exception, it will propagate through this method. |
|
505 |
* |
|
506 |
* <p> This method preserves the current AccessControlContext's |
|
507 |
* DomainCombiner (which may be null) while the action is performed. |
|
508 |
* |
|
509 |
* @param action the action to be performed. |
|
510 |
* |
|
511 |
* @return the value returned by the action's <code>run</code> method |
|
512 |
* |
|
513 |
* @exception PrivilegedActionException if the specified action's |
|
514 |
* <code>run</code> method threw a <i>checked</i> exception |
|
515 |
* @exception NullPointerException if the action is <code>null</code> |
|
516 |
* |
|
517 |
* @see #doPrivileged(PrivilegedAction) |
|
518 |
* @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
|
519 |
* @see java.security.DomainCombiner |
|
520 |
* |
|
521 |
* @since 1.6 |
|
522 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
523 |
@CallerSensitive |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
524 |
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action) |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
525 |
throws PrivilegedActionException |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
526 |
{ |
2 | 527 |
AccessControlContext acc = getStackAccessControlContext(); |
14213
91ba926457c6
7189490: More improvements to DomainCombiner checking
mullan
parents:
14208
diff
changeset
|
528 |
if (acc == null) { |
91ba926457c6
7189490: More improvements to DomainCombiner checking
mullan
parents:
14208
diff
changeset
|
529 |
return AccessController.doPrivileged(action); |
2 | 530 |
} |
14213
91ba926457c6
7189490: More improvements to DomainCombiner checking
mullan
parents:
14208
diff
changeset
|
531 |
DomainCombiner dc = acc.getAssignedCombiner(); |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
532 |
return AccessController.doPrivileged(action, |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
533 |
preserveCombiner(dc, Reflection.getCallerClass())); |
2 | 534 |
} |
535 |
||
536 |
/** |
|
537 |
* preserve the combiner across the doPrivileged call |
|
538 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
539 |
private static AccessControlContext preserveCombiner(DomainCombiner combiner, |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
540 |
Class<?> caller) |
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
541 |
{ |
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
542 |
return createWrapper(combiner, caller, null, null, null); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
543 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
544 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
545 |
/** |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
546 |
* Create a wrapper to contain the limited privilege scope data. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
547 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
548 |
private static AccessControlContext |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
549 |
createWrapper(DomainCombiner combiner, Class<?> caller, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
550 |
AccessControlContext parent, AccessControlContext context, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
551 |
Permission[] perms) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
552 |
{ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
553 |
return new AccessControlContext(getCallerPD(caller), combiner, parent, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
554 |
context, perms); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
555 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
556 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
557 |
private static ProtectionDomain getCallerPD(final Class <?> caller) { |
2 | 558 |
ProtectionDomain callerPd = doPrivileged |
559 |
(new PrivilegedAction<ProtectionDomain>() { |
|
560 |
public ProtectionDomain run() { |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
561 |
return caller.getProtectionDomain(); |
2 | 562 |
} |
563 |
}); |
|
564 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
565 |
return callerPd; |
2 | 566 |
} |
567 |
||
568 |
/** |
|
569 |
* Performs the specified <code>PrivilegedExceptionAction</code> with |
|
570 |
* privileges enabled and restricted by the specified |
|
571 |
* <code>AccessControlContext</code>. The action is performed with the |
|
2589 | 572 |
* intersection of the permissions possessed by the caller's |
2 | 573 |
* protection domain, and those possessed by the domains represented by the |
574 |
* specified <code>AccessControlContext</code>. |
|
575 |
* <p> |
|
576 |
* If the action's <code>run</code> method throws an <i>unchecked</i> |
|
577 |
* exception, it will propagate through this method. |
|
578 |
* |
|
579 |
* @param action the action to be performed |
|
580 |
* @param context an <i>access control context</i> |
|
581 |
* representing the restriction to be applied to the |
|
582 |
* caller's domain's privileges before performing |
|
583 |
* the specified action. If the context is |
|
584 |
* <code>null</code>, |
|
585 |
* then no additional restriction is applied. |
|
586 |
* |
|
587 |
* @return the value returned by the action's <code>run</code> method |
|
588 |
* |
|
589 |
* @exception PrivilegedActionException if the specified action's |
|
590 |
* <code>run</code> method |
|
591 |
* threw a <i>checked</i> exception |
|
592 |
* @exception NullPointerException if the action is <code>null</code> |
|
593 |
* |
|
594 |
* @see #doPrivileged(PrivilegedAction) |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
595 |
* @see #doPrivileged(PrivilegedAction,AccessControlContext) |
2 | 596 |
*/ |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
14213
diff
changeset
|
597 |
@CallerSensitive |
2 | 598 |
public static native <T> T |
599 |
doPrivileged(PrivilegedExceptionAction<T> action, |
|
600 |
AccessControlContext context) |
|
601 |
throws PrivilegedActionException; |
|
602 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
603 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
604 |
/** |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
605 |
* Performs the specified <code>PrivilegedExceptionAction</code> with |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
606 |
* privileges enabled and restricted by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
607 |
* <code>AccessControlContext</code> and with a privilege scope limited by |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
608 |
* specified <code>Permission</code> arguments. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
609 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
610 |
* The action is performed with the intersection of the permissions |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
611 |
* possessed by the caller's protection domain, and those possessed |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
612 |
* by the domains represented by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
613 |
* <code>AccessControlContext</code>. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
614 |
* <p> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
615 |
* If the action's <code>run</code> method throws an (unchecked) exception, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
616 |
* it will propagate through this method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
617 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
618 |
* @param action the action to be performed. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
619 |
* @param context an <i>access control context</i> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
620 |
* representing the restriction to be applied to the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
621 |
* caller's domain's privileges before performing |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
622 |
* the specified action. If the context is |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
623 |
* <code>null</code>, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
624 |
* then no additional restriction is applied. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
625 |
* @param perms the <code>Permission</code> arguments which limit the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
626 |
* scope of the caller's privileges. The number of arguments |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
627 |
* is variable. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
628 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
629 |
* @return the value returned by the action's <code>run</code> method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
630 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
631 |
* @throws PrivilegedActionException if the specified action's |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
632 |
* <code>run</code> method threw a <i>checked</i> exception |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
633 |
* @throws NullPointerException if action or perms or any element of |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
634 |
* perms is <code>null</code> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
635 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
636 |
* @see #doPrivileged(PrivilegedAction) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
637 |
* @see #doPrivileged(PrivilegedAction,AccessControlContext) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
638 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
639 |
* @since 1.8 |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
640 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
641 |
@CallerSensitive |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
642 |
public static <T> T doPrivileged(PrivilegedExceptionAction<T> action, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
643 |
AccessControlContext context, Permission... perms) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
644 |
throws PrivilegedActionException |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
645 |
{ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
646 |
AccessControlContext parent = getContext(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
647 |
if (perms == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
648 |
throw new NullPointerException("null permissions parameter"); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
649 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
650 |
Class <?> caller = Reflection.getCallerClass(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
651 |
return AccessController.doPrivileged(action, createWrapper(null, caller, parent, context, perms)); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
652 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
653 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
654 |
|
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
655 |
/** |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
656 |
* Performs the specified <code>PrivilegedExceptionAction</code> with |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
657 |
* privileges enabled and restricted by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
658 |
* <code>AccessControlContext</code> and with a privilege scope limited by |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
659 |
* specified <code>Permission</code> arguments. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
660 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
661 |
* The action is performed with the intersection of the permissions |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
662 |
* possessed by the caller's protection domain, and those possessed |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
663 |
* by the domains represented by the specified |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
664 |
* <code>AccessControlContext</code>. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
665 |
* <p> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
666 |
* If the action's <code>run</code> method throws an (unchecked) exception, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
667 |
* it will propagate through this method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
668 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
669 |
* <p> This method preserves the current AccessControlContext's |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
670 |
* DomainCombiner (which may be null) while the action is performed. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
671 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
672 |
* @param action the action to be performed. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
673 |
* @param context an <i>access control context</i> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
674 |
* representing the restriction to be applied to the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
675 |
* caller's domain's privileges before performing |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
676 |
* the specified action. If the context is |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
677 |
* <code>null</code>, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
678 |
* then no additional restriction is applied. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
679 |
* @param perms the <code>Permission</code> arguments which limit the |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
680 |
* scope of the caller's privileges. The number of arguments |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
681 |
* is variable. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
682 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
683 |
* @return the value returned by the action's <code>run</code> method. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
684 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
685 |
* @throws PrivilegedActionException if the specified action's |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
686 |
* <code>run</code> method threw a <i>checked</i> exception |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
687 |
* @throws NullPointerException if action or perms or any element of |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
688 |
* perms is <code>null</code> |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
689 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
690 |
* @see #doPrivileged(PrivilegedAction) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
691 |
* @see #doPrivileged(PrivilegedAction,AccessControlContext) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
692 |
* @see java.security.DomainCombiner |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
693 |
* |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
694 |
* @since 1.8 |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
695 |
*/ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
696 |
@CallerSensitive |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
697 |
public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
698 |
AccessControlContext context, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
699 |
Permission... perms) |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
700 |
throws PrivilegedActionException |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
701 |
{ |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
702 |
AccessControlContext parent = getContext(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
703 |
DomainCombiner dc = parent.getCombiner(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
704 |
if (dc == null && context != null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
705 |
dc = context.getCombiner(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
706 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
707 |
if (perms == null) { |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
708 |
throw new NullPointerException("null permissions parameter"); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
709 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
710 |
Class <?> caller = Reflection.getCallerClass(); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
711 |
return AccessController.doPrivileged(action, createWrapper(dc, caller, |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
712 |
parent, context, perms)); |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
713 |
} |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
714 |
|
2 | 715 |
/** |
716 |
* Returns the AccessControl context. i.e., it gets |
|
717 |
* the protection domains of all the callers on the stack, |
|
718 |
* starting at the first class with a non-null |
|
719 |
* ProtectionDomain. |
|
720 |
* |
|
721 |
* @return the access control context based on the current stack or |
|
722 |
* null if there was only privileged system code. |
|
723 |
*/ |
|
724 |
||
725 |
private static native AccessControlContext getStackAccessControlContext(); |
|
726 |
||
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
727 |
|
2 | 728 |
/** |
729 |
* Returns the "inherited" AccessControl context. This is the context |
|
730 |
* that existed when the thread was created. Package private so |
|
731 |
* AccessControlContext can use it. |
|
732 |
*/ |
|
733 |
||
734 |
static native AccessControlContext getInheritedAccessControlContext(); |
|
735 |
||
736 |
/** |
|
737 |
* This method takes a "snapshot" of the current calling context, which |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
738 |
* includes the current Thread's inherited AccessControlContext and any |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
739 |
* limited privilege scope, and places it in an AccessControlContext object. |
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
740 |
* This context may then be checked at a later point, possibly in another thread. |
2 | 741 |
* |
742 |
* @see AccessControlContext |
|
743 |
* |
|
744 |
* @return the AccessControlContext based on the current context. |
|
745 |
*/ |
|
746 |
||
747 |
public static AccessControlContext getContext() |
|
748 |
{ |
|
749 |
AccessControlContext acc = getStackAccessControlContext(); |
|
750 |
if (acc == null) { |
|
751 |
// all we had was privileged system code. We don't want |
|
752 |
// to return null though, so we construct a real ACC. |
|
753 |
return new AccessControlContext(null, true); |
|
754 |
} else { |
|
755 |
return acc.optimize(); |
|
756 |
} |
|
757 |
} |
|
758 |
||
759 |
/** |
|
760 |
* Determines whether the access request indicated by the |
|
761 |
* specified permission should be allowed or denied, based on |
|
762 |
* the current AccessControlContext and security policy. |
|
763 |
* This method quietly returns if the access request |
|
764 |
* is permitted, or throws an AccessControlException otherwise. The |
|
765 |
* getPermission method of the AccessControlException returns the |
|
766 |
* <code>perm</code> Permission object instance. |
|
767 |
* |
|
768 |
* @param perm the requested permission. |
|
769 |
* |
|
770 |
* @exception AccessControlException if the specified permission |
|
771 |
* is not permitted, based on the current security policy. |
|
772 |
* @exception NullPointerException if the specified permission |
|
773 |
* is <code>null</code> and is checked based on the |
|
774 |
* security policy currently in effect. |
|
775 |
*/ |
|
776 |
||
777 |
public static void checkPermission(Permission perm) |
|
17946
7791613dcbfd
8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
16906
diff
changeset
|
778 |
throws AccessControlException |
2 | 779 |
{ |
780 |
//System.err.println("checkPermission "+perm); |
|
781 |
//Thread.currentThread().dumpStack(); |
|
782 |
||
783 |
if (perm == null) { |
|
784 |
throw new NullPointerException("permission can't be null"); |
|
785 |
} |
|
786 |
||
787 |
AccessControlContext stack = getStackAccessControlContext(); |
|
788 |
// if context is null, we had privileged system code on the stack. |
|
789 |
if (stack == null) { |
|
790 |
Debug debug = AccessControlContext.getDebug(); |
|
791 |
boolean dumpDebug = false; |
|
792 |
if (debug != null) { |
|
793 |
dumpDebug = !Debug.isOn("codebase="); |
|
794 |
dumpDebug &= !Debug.isOn("permission=") || |
|
795 |
Debug.isOn("permission=" + perm.getClass().getCanonicalName()); |
|
796 |
} |
|
797 |
||
798 |
if (dumpDebug && Debug.isOn("stack")) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
5506
diff
changeset
|
799 |
Thread.dumpStack(); |
2 | 800 |
} |
801 |
||
802 |
if (dumpDebug && Debug.isOn("domain")) { |
|
803 |
debug.println("domain (context is null)"); |
|
804 |
} |
|
805 |
||
806 |
if (dumpDebug) { |
|
807 |
debug.println("access allowed "+perm); |
|
808 |
} |
|
809 |
return; |
|
810 |
} |
|
811 |
||
812 |
AccessControlContext acc = stack.optimize(); |
|
813 |
acc.checkPermission(perm); |
|
814 |
} |
|
815 |
} |