426 |
|
|
427 |
|
} |
428 |
|
|
429 |
< |
static class CheckCCL implements Callable<Object> { |
429 |
> |
void checkCCL() { |
430 |
> |
AccessController.getContext().checkPermission(new RuntimePermission("getContextClassLoader")); |
431 |
> |
} |
432 |
> |
|
433 |
> |
class CheckCCL implements Callable<Object> { |
434 |
|
public Object call() { |
435 |
< |
AccessControlContext acc = AccessController.getContext(); |
432 |
< |
acc.checkPermission(new RuntimePermission("getContextClassLoader")); |
435 |
> |
checkCCL(); |
436 |
|
return null; |
437 |
|
} |
438 |
|
} |
452 |
|
return; |
453 |
|
} |
454 |
|
|
455 |
+ |
// Check if program still has too many permissions to run test |
456 |
+ |
try { |
457 |
+ |
checkCCL(); |
458 |
+ |
// too many privileges to test; so return |
459 |
+ |
Policy.setPolicy(savedPolicy); |
460 |
+ |
return; |
461 |
+ |
} catch(AccessControlException ok) { |
462 |
+ |
} |
463 |
+ |
|
464 |
|
try { |
465 |
|
Callable task = Executors.privilegedCallableUsingCurrentClassLoader(new NoOpCallable()); |
466 |
|
shouldThrow(); |
474 |
|
} |
475 |
|
|
476 |
|
/** |
477 |
< |
* Without class loader permissions, calling |
478 |
< |
* privilegedCallableUsingCurrentClassLoader throws ACE |
477 |
> |
* With class loader permissions, calling |
478 |
> |
* privilegedCallableUsingCurrentClassLoader does not throw ACE |
479 |
|
*/ |
480 |
|
public void testprivilegedCallableUsingCCLWithPrivs() { |
481 |
|
Policy savedPolicy = null; |
504 |
|
* Without permissions, calling privilegedCallable throws ACE |
505 |
|
*/ |
506 |
|
public void testprivilegedCallableWithNoPrivs() { |
507 |
< |
Policy savedPolicy = null; |
507 |
> |
Callable task; |
508 |
> |
Policy savedPolicy = null; |
509 |
> |
AdjustablePolicy policy = null; |
510 |
> |
AccessControlContext noprivAcc = null; |
511 |
|
try { |
512 |
|
savedPolicy = Policy.getPolicy(); |
513 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
513 |
> |
policy = new AdjustablePolicy(); |
514 |
|
Policy.setPolicy(policy); |
515 |
+ |
noprivAcc = AccessController.getContext(); |
516 |
+ |
task = Executors.privilegedCallable(new CheckCCL()); |
517 |
+ |
Policy.setPolicy(savedPolicy); |
518 |
|
} catch (AccessControlException ok) { |
519 |
+ |
return; // program has too few permissions to set up test |
520 |
+ |
} |
521 |
+ |
|
522 |
+ |
// Make sure that program doesn't have too many permissions |
523 |
+ |
try { |
524 |
+ |
AccessController.doPrivileged(new PrivilegedAction() { |
525 |
+ |
public Object run() { |
526 |
+ |
checkCCL(); |
527 |
+ |
return null; |
528 |
+ |
}}, noprivAcc); |
529 |
+ |
// too many permssions; skip test |
530 |
|
return; |
531 |
+ |
} catch(AccessControlException ok) { |
532 |
|
} |
533 |
|
|
504 |
– |
Callable task = Executors.privilegedCallable(new CheckCCL()); |
505 |
– |
Policy.setPolicy(savedPolicy); |
534 |
|
try { |
535 |
|
task.call(); |
536 |
|
shouldThrow(); |
537 |
|
} catch(AccessControlException success) { |
538 |
|
} catch(Exception ex) { |
539 |
|
unexpectedException(); |
540 |
< |
} finally { |
513 |
< |
} |
540 |
> |
} |
541 |
|
} |
542 |
|
|
543 |
|
/** |