tests/libjava-mauve/src/gnu/testlet/java/security/ProtectionDomain/Security.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Copyright (C) 2006, 2007, 2010 Red Hat, Inc.
       
     2 // Original written by Gary Benson <gbenson@redhat.com>
       
     3 // Adapted for ProtectionDomain by Andrew John Hughes <ahughes@redhat.com>
       
     4 
       
     5 // This file is part of Mauve.
       
     6 
       
     7 // Mauve is free software; you can redistribute it and/or modify
       
     8 // it under the terms of the GNU General Public License as published by
       
     9 // the Free Software Foundation; either version 2, or (at your option)
       
    10 // any later version.
       
    11 
       
    12 // Mauve is distributed in the hope that it will be useful,
       
    13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 // GNU General Public License for more details.
       
    16 
       
    17 // You should have received a copy of the GNU General Public License
       
    18 // along with Mauve; see the file COPYING.  If not, write to
       
    19 // the Free Software Foundation, 59 Temple Place - Suite 330,
       
    20 // Boston, MA 02111-1307, USA.
       
    21 
       
    22 // Tags: JDK1.4
       
    23 
       
    24 package gnu.testlet.java.security.ProtectionDomain;
       
    25 
       
    26 import java.net.URL;
       
    27 
       
    28 import java.security.CodeSource;
       
    29 import java.security.Permission;
       
    30 import java.security.ProtectionDomain;
       
    31 import java.security.SecurityPermission;
       
    32 
       
    33 import gnu.testlet.Testlet;
       
    34 import gnu.testlet.TestHarness;
       
    35 import gnu.testlet.TestSecurityManager;
       
    36 
       
    37 public class Security implements Testlet
       
    38 {
       
    39   public void test(TestHarness harness)
       
    40   {
       
    41     try {
       
    42 
       
    43       Permission[] noPerms = new Permission[] {};
       
    44       Permission[] gpPerms =
       
    45         new Permission[] { new SecurityPermission("getPolicy") } ;
       
    46 
       
    47       String debug = System.getProperty("java.security.debug");
       
    48       ProtectionDomain pd = new ProtectionDomain(null, null, null, null);
       
    49       TestSecurityManager sm = new TestSecurityManager(harness);
       
    50       try {
       
    51         sm.install();
       
    52 
       
    53         harness.checkPoint("toString");
       
    54         try {
       
    55           if (debug != null &&
       
    56               (debug.contains("domain") || debug.contains("all")))
       
    57             sm.prepareChecks(noPerms);
       
    58           else
       
    59             sm.prepareChecks(gpPerms);
       
    60           harness.debug(pd.toString());
       
    61           sm.checkAllChecked();
       
    62         }
       
    63         catch (SecurityException ex) {
       
    64           harness.debug(ex);
       
    65           harness.check(false, "unexpected check");
       
    66         }
       
    67 
       
    68       }
       
    69       finally {
       
    70         sm.uninstall();
       
    71       }
       
    72     }
       
    73     catch (Exception ex) {
       
    74       harness.debug(ex);
       
    75       harness.check(false, "Unexpected exception");
       
    76     }
       
    77   }
       
    78 
       
    79 }