337 |
|
try { |
338 |
|
Thread current = Thread.currentThread(); |
339 |
|
threadAssertTrue(!current.isDaemon()); |
340 |
< |
threadAssertTrue(current.getPriority() == Thread.NORM_PRIORITY); |
340 |
> |
threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
341 |
|
ThreadGroup g = current.getThreadGroup(); |
342 |
|
SecurityManager s = System.getSecurityManager(); |
343 |
|
if (s != null) |
392 |
|
try { |
393 |
|
Thread current = Thread.currentThread(); |
394 |
|
threadAssertTrue(!current.isDaemon()); |
395 |
< |
threadAssertTrue(current.getPriority() == Thread.NORM_PRIORITY); |
395 |
> |
threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY); |
396 |
|
ThreadGroup g = current.getThreadGroup(); |
397 |
|
SecurityManager s = System.getSecurityManager(); |
398 |
|
if (s != null) |
426 |
|
|
427 |
|
} |
428 |
|
|
429 |
< |
static class CheckCCL implements Callable<Object> { |
429 |
> |
void checkCCL() { |
430 |
> |
SecurityManager sm = System.getSecurityManager(); |
431 |
> |
if (sm != null) { |
432 |
> |
sm.checkPermission(new RuntimePermission("setContextClassLoader")); |
433 |
> |
sm.checkPermission(new RuntimePermission("getClassLoader")); |
434 |
> |
} |
435 |
> |
} |
436 |
> |
|
437 |
> |
class CheckCCL implements Callable<Object> { |
438 |
|
public Object call() { |
439 |
< |
AccessControlContext acc = AccessController.getContext(); |
432 |
< |
acc.checkPermission(new RuntimePermission("getContextClassLoader")); |
439 |
> |
checkCCL(); |
440 |
|
return null; |
441 |
|
} |
442 |
|
} |
456 |
|
return; |
457 |
|
} |
458 |
|
|
459 |
+ |
// Check if program still has too many permissions to run test |
460 |
+ |
try { |
461 |
+ |
checkCCL(); |
462 |
+ |
// too many privileges to test; so return |
463 |
+ |
Policy.setPolicy(savedPolicy); |
464 |
+ |
return; |
465 |
+ |
} catch(AccessControlException ok) { |
466 |
+ |
} |
467 |
+ |
|
468 |
|
try { |
469 |
|
Callable task = Executors.privilegedCallableUsingCurrentClassLoader(new NoOpCallable()); |
470 |
|
shouldThrow(); |
478 |
|
} |
479 |
|
|
480 |
|
/** |
481 |
< |
* Without class loader permissions, calling |
482 |
< |
* privilegedCallableUsingCurrentClassLoader throws ACE |
481 |
> |
* With class loader permissions, calling |
482 |
> |
* privilegedCallableUsingCurrentClassLoader does not throw ACE |
483 |
|
*/ |
484 |
|
public void testprivilegedCallableUsingCCLWithPrivs() { |
485 |
|
Policy savedPolicy = null; |
504 |
|
} |
505 |
|
} |
506 |
|
|
491 |
– |
class CallCCL implements Runnable { |
492 |
– |
final Callable task; |
493 |
– |
CallCCL(Callable t) { task = t; } |
494 |
– |
public void run() { |
495 |
– |
try { |
496 |
– |
task.call(); |
497 |
– |
threadShouldThrow(); |
498 |
– |
} catch(AccessControlException success) { |
499 |
– |
} catch(Exception ex) { |
500 |
– |
threadUnexpectedException(); |
501 |
– |
} |
502 |
– |
} |
503 |
– |
} |
504 |
– |
|
507 |
|
/** |
508 |
|
* Without permissions, calling privilegedCallable throws ACE |
509 |
|
*/ |
510 |
|
public void testprivilegedCallableWithNoPrivs() { |
511 |
< |
Thread t1; |
511 |
> |
Callable task; |
512 |
> |
Policy savedPolicy = null; |
513 |
> |
AdjustablePolicy policy = null; |
514 |
> |
AccessControlContext noprivAcc = null; |
515 |
|
try { |
516 |
< |
Policy savedPolicy = Policy.getPolicy(); |
517 |
< |
AdjustablePolicy policy = new AdjustablePolicy(); |
516 |
> |
savedPolicy = Policy.getPolicy(); |
517 |
> |
policy = new AdjustablePolicy(); |
518 |
|
Policy.setPolicy(policy); |
519 |
< |
Callable task = Executors.privilegedCallable(new CheckCCL()); |
520 |
< |
t1 = new Thread(new CallCCL(task)); |
519 |
> |
noprivAcc = AccessController.getContext(); |
520 |
> |
task = Executors.privilegedCallable(new CheckCCL()); |
521 |
|
Policy.setPolicy(savedPolicy); |
522 |
|
} catch (AccessControlException ok) { |
523 |
+ |
return; // program has too few permissions to set up test |
524 |
+ |
} |
525 |
+ |
|
526 |
+ |
// Make sure that program doesn't have too many permissions |
527 |
+ |
try { |
528 |
+ |
AccessController.doPrivileged(new PrivilegedAction() { |
529 |
+ |
public Object run() { |
530 |
+ |
checkCCL(); |
531 |
+ |
return null; |
532 |
+ |
}}, noprivAcc); |
533 |
+ |
// too many permssions; skip test |
534 |
|
return; |
535 |
+ |
} catch(AccessControlException ok) { |
536 |
|
} |
537 |
|
|
538 |
|
try { |
539 |
< |
t1.start(); |
540 |
< |
t1.join(); |
539 |
> |
task.call(); |
540 |
> |
shouldThrow(); |
541 |
> |
} catch(AccessControlException success) { |
542 |
|
} catch(Exception ex) { |
543 |
|
unexpectedException(); |
544 |
|
} |