ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ExecutorsTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ExecutorsTest.java (file contents):
Revision 1.15 by dl, Thu Jan 22 14:07:50 2004 UTC vs.
Revision 1.18 by dl, Tue Aug 4 13:58:09 2009 UTC

# Line 12 | Line 12 | import java.util.*;
12   import java.util.concurrent.*;
13   import java.math.BigInteger;
14   import java.security.*;
15 + import sun.security.util.SecurityConstants;
16  
17   public class ExecutorsTest extends JSR166TestCase{
18      public static void main(String[] args) {
# Line 337 | Line 338 | public class ExecutorsTest extends JSR16
338                      try {
339                          Thread current = Thread.currentThread();
340                          threadAssertTrue(!current.isDaemon());
341 <                        threadAssertTrue(current.getPriority() == Thread.NORM_PRIORITY);
341 >                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
342                          ThreadGroup g = current.getThreadGroup();
343                          SecurityManager s = System.getSecurityManager();
344                          if (s != null)
# Line 392 | Line 393 | public class ExecutorsTest extends JSR16
393                      try {
394                          Thread current = Thread.currentThread();
395                          threadAssertTrue(!current.isDaemon());
396 <                        threadAssertTrue(current.getPriority() == Thread.NORM_PRIORITY);
396 >                        threadAssertTrue(current.getPriority() <= Thread.NORM_PRIORITY);
397                          ThreadGroup g = current.getThreadGroup();
398                          SecurityManager s = System.getSecurityManager();
399                          if (s != null)
# Line 426 | Line 427 | public class ExecutorsTest extends JSR16
427  
428      }
429  
430 <    static class CheckCCL implements Callable<Object> {
430 >    void checkCCL() {
431 >        SecurityManager sm = System.getSecurityManager();
432 >        if (sm != null) {
433 >            sm.checkPermission(new RuntimePermission("setContextClassLoader"));
434 >            sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
435 >        }
436 >    }
437 >
438 >    class CheckCCL implements Callable<Object> {
439          public Object call() {
440 <            AccessControlContext acc = AccessController.getContext();
432 <            acc.checkPermission(new RuntimePermission("getContextClassLoader"));
440 >            checkCCL();
441              return null;
442          }
443      }
# Line 449 | Line 457 | public class ExecutorsTest extends JSR16
457              return;
458          }
459  
460 +        // Check if program still has too many permissions to run test
461 +        try {
462 +            checkCCL();
463 +            // too many privileges to test; so return
464 +            Policy.setPolicy(savedPolicy);
465 +            return;
466 +        } catch(AccessControlException ok) {
467 +        }
468 +
469          try {
470              Callable task = Executors.privilegedCallableUsingCurrentClassLoader(new NoOpCallable());
471              shouldThrow();
# Line 462 | Line 479 | public class ExecutorsTest extends JSR16
479      }
480  
481      /**
482 <     * Without class loader permissions, calling
483 <     * privilegedCallableUsingCurrentClassLoader throws ACE
482 >     * With class loader permissions, calling
483 >     * privilegedCallableUsingCurrentClassLoader does not throw ACE
484       */
485      public void testprivilegedCallableUsingCCLWithPrivs() {
486          Policy savedPolicy = null;
# Line 488 | Line 505 | public class ExecutorsTest extends JSR16
505          }
506      }
507  
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
508      /**
509       * Without permissions, calling privilegedCallable throws ACE
510       */
511      public void testprivilegedCallableWithNoPrivs() {
512 <        Thread t1;
512 >        Callable task;
513 >        Policy savedPolicy = null;
514 >        AdjustablePolicy policy = null;
515 >        AccessControlContext noprivAcc = null;
516          try {
517 <            Policy savedPolicy = Policy.getPolicy();
518 <            AdjustablePolicy policy = new AdjustablePolicy();
517 >            savedPolicy = Policy.getPolicy();
518 >            policy = new AdjustablePolicy();
519              Policy.setPolicy(policy);
520 <            Callable task = Executors.privilegedCallable(new CheckCCL());
521 <            t1 = new Thread(new CallCCL(task));
520 >            noprivAcc = AccessController.getContext();
521 >            task = Executors.privilegedCallable(new CheckCCL());
522              Policy.setPolicy(savedPolicy);
523          } catch (AccessControlException ok) {
524 +            return; // program has too few permissions to set up test
525 +        }
526 +
527 +        // Make sure that program doesn't have too many permissions
528 +        try {
529 +            AccessController.doPrivileged(new PrivilegedAction() {
530 +                    public Object run() {
531 +                        checkCCL();
532 +                        return null;
533 +                    }}, noprivAcc);
534 +            // too many permssions; skip test
535              return;
536 +        } catch(AccessControlException ok) {
537          }
538  
539          try {
540 <            t1.start();
541 <            t1.join();
540 >            task.call();
541 >            shouldThrow();
542 >        } catch(AccessControlException success) {
543          } catch(Exception ex) {
544              unexpectedException();
545          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines