262 * @see #doPrivileged(PrivilegedExceptionAction) |
264 * @see #doPrivileged(PrivilegedExceptionAction) |
263 * @see #doPrivilegedWithCombiner(PrivilegedAction) |
265 * @see #doPrivilegedWithCombiner(PrivilegedAction) |
264 * @see java.security.DomainCombiner |
266 * @see java.security.DomainCombiner |
265 */ |
267 */ |
266 |
268 |
|
269 @CallerSensitive |
267 public static native <T> T doPrivileged(PrivilegedAction<T> action); |
270 public static native <T> T doPrivileged(PrivilegedAction<T> action); |
268 |
271 |
269 /** |
272 /** |
270 * Performs the specified <code>PrivilegedAction</code> with privileges |
273 * Performs the specified <code>PrivilegedAction</code> with privileges |
271 * enabled. The action is performed with <i>all</i> of the permissions |
274 * enabled. The action is performed with <i>all</i> of the permissions |
286 * @see #doPrivileged(PrivilegedAction) |
289 * @see #doPrivileged(PrivilegedAction) |
287 * @see java.security.DomainCombiner |
290 * @see java.security.DomainCombiner |
288 * |
291 * |
289 * @since 1.6 |
292 * @since 1.6 |
290 */ |
293 */ |
|
294 @CallerSensitive |
291 public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) { |
295 public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) { |
292 |
|
293 AccessControlContext acc = getStackAccessControlContext(); |
296 AccessControlContext acc = getStackAccessControlContext(); |
294 if (acc == null) { |
297 if (acc == null) { |
295 return AccessController.doPrivileged(action); |
298 return AccessController.doPrivileged(action); |
296 } |
299 } |
297 DomainCombiner dc = acc.getAssignedCombiner(); |
300 DomainCombiner dc = acc.getAssignedCombiner(); |
298 return AccessController.doPrivileged(action, preserveCombiner(dc)); |
301 return AccessController.doPrivileged(action, |
|
302 preserveCombiner(dc, Reflection.getCallerClass())); |
299 } |
303 } |
300 |
304 |
301 |
305 |
302 /** |
306 /** |
303 * Performs the specified <code>PrivilegedAction</code> with privileges |
307 * Performs the specified <code>PrivilegedAction</code> with privileges |
324 * @exception NullPointerException if the action is <code>null</code> |
328 * @exception NullPointerException if the action is <code>null</code> |
325 * |
329 * |
326 * @see #doPrivileged(PrivilegedAction) |
330 * @see #doPrivileged(PrivilegedAction) |
327 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
331 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
328 */ |
332 */ |
|
333 @CallerSensitive |
329 public static native <T> T doPrivileged(PrivilegedAction<T> action, |
334 public static native <T> T doPrivileged(PrivilegedAction<T> action, |
330 AccessControlContext context); |
335 AccessControlContext context); |
331 |
336 |
332 /** |
337 /** |
333 * Performs the specified <code>PrivilegedExceptionAction</code> with |
338 * Performs the specified <code>PrivilegedExceptionAction</code> with |
351 * @see #doPrivileged(PrivilegedAction) |
356 * @see #doPrivileged(PrivilegedAction) |
352 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
357 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
353 * @see #doPrivilegedWithCombiner(PrivilegedExceptionAction) |
358 * @see #doPrivilegedWithCombiner(PrivilegedExceptionAction) |
354 * @see java.security.DomainCombiner |
359 * @see java.security.DomainCombiner |
355 */ |
360 */ |
|
361 @CallerSensitive |
356 public static native <T> T |
362 public static native <T> T |
357 doPrivileged(PrivilegedExceptionAction<T> action) |
363 doPrivileged(PrivilegedExceptionAction<T> action) |
358 throws PrivilegedActionException; |
364 throws PrivilegedActionException; |
359 |
365 |
360 |
366 |
381 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
387 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
382 * @see java.security.DomainCombiner |
388 * @see java.security.DomainCombiner |
383 * |
389 * |
384 * @since 1.6 |
390 * @since 1.6 |
385 */ |
391 */ |
386 public static <T> T doPrivilegedWithCombiner |
392 @CallerSensitive |
387 (PrivilegedExceptionAction<T> action) throws PrivilegedActionException { |
393 public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action) |
388 |
394 throws PrivilegedActionException |
|
395 { |
389 AccessControlContext acc = getStackAccessControlContext(); |
396 AccessControlContext acc = getStackAccessControlContext(); |
390 if (acc == null) { |
397 if (acc == null) { |
391 return AccessController.doPrivileged(action); |
398 return AccessController.doPrivileged(action); |
392 } |
399 } |
393 DomainCombiner dc = acc.getAssignedCombiner(); |
400 DomainCombiner dc = acc.getAssignedCombiner(); |
394 return AccessController.doPrivileged(action, preserveCombiner(dc)); |
401 return AccessController.doPrivileged(action, |
|
402 preserveCombiner(dc, Reflection.getCallerClass())); |
395 } |
403 } |
396 |
404 |
397 /** |
405 /** |
398 * preserve the combiner across the doPrivileged call |
406 * preserve the combiner across the doPrivileged call |
399 */ |
407 */ |
400 private static AccessControlContext preserveCombiner |
408 private static AccessControlContext preserveCombiner(DomainCombiner combiner, |
401 (DomainCombiner combiner) { |
409 Class<?> caller) |
402 |
410 { |
403 /** |
|
404 * callerClass[0] = Reflection.getCallerClass |
|
405 * callerClass[1] = AccessController.preserveCombiner |
|
406 * callerClass[2] = AccessController.doPrivileged |
|
407 * callerClass[3] = caller |
|
408 */ |
|
409 final Class<?> callerClass = sun.reflect.Reflection.getCallerClass(3); |
|
410 ProtectionDomain callerPd = doPrivileged |
411 ProtectionDomain callerPd = doPrivileged |
411 (new PrivilegedAction<ProtectionDomain>() { |
412 (new PrivilegedAction<ProtectionDomain>() { |
412 public ProtectionDomain run() { |
413 public ProtectionDomain run() { |
413 return callerClass.getProtectionDomain(); |
414 return caller.getProtectionDomain(); |
414 } |
415 } |
415 }); |
416 }); |
416 |
417 |
417 // perform 'combine' on the caller of doPrivileged, |
418 // perform 'combine' on the caller of doPrivileged, |
418 // even if the caller is from the bootclasspath |
419 // even if the caller is from the bootclasspath |
453 * @exception NullPointerException if the action is <code>null</code> |
454 * @exception NullPointerException if the action is <code>null</code> |
454 * |
455 * |
455 * @see #doPrivileged(PrivilegedAction) |
456 * @see #doPrivileged(PrivilegedAction) |
456 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
457 * @see #doPrivileged(PrivilegedExceptionAction,AccessControlContext) |
457 */ |
458 */ |
|
459 @CallerSensitive |
458 public static native <T> T |
460 public static native <T> T |
459 doPrivileged(PrivilegedExceptionAction<T> action, |
461 doPrivileged(PrivilegedExceptionAction<T> action, |
460 AccessControlContext context) |
462 AccessControlContext context) |
461 throws PrivilegedActionException; |
463 throws PrivilegedActionException; |
462 |
464 |