jdk/test/java/security/Policy/GetInstance/GetInstance.java
author mchung
Thu, 28 May 2015 10:54:48 -0700
changeset 30820 0d4717a011d3
parent 5506 202f599c92aa
permissions -rw-r--r--
8081347: Add @modules to jdk_core tests Reviewed-by: alanb, joehw, lancea Contributed-by: alexander.kulyakhtin@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 5100561
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 6273812
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Can not explicitly create a java.security.Policy object from a file
30820
0d4717a011d3 8081347: Add @modules to jdk_core tests
mchung
parents: 5506
diff changeset
    29
 * @modules java.base/sun.security.provider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @build GetInstancePolicySpi GetInstanceProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run main/othervm/policy=GetInstance.policy GetInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class GetInstance {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static final String JAVA_POLICY = "JavaPolicy";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private static class BadParam implements Policy.Parameters { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        int testnum = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        GetInstance gi = new GetInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        testnum = gi.testDefault(testnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        testnum = gi.testStringProvider(testnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        testnum = gi.testProvider(testnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        testnum = gi.testCustomImpl(testnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        testnum = gi.testBadParam(testnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        // make this go last because we don't want to leave its policy set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        // for other tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        testnum = gi.testURIParam(testnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private int testDefault(int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // get an instance of the default PolicySpiFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Policy p = Policy.getInstance(JAVA_POLICY, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        doTest(p, testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        Policy.setPolicy(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        doTestSM(testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // get an instance of FooPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            p = Policy.getInstance("FooPolicy", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            throw new SecurityException("test " + testnum++ + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            System.out.println("test " + testnum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return testnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private int testStringProvider(int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        // get an instance of JavaPolicy from SUN
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        Policy p = Policy.getInstance(JAVA_POLICY, null, "SUN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        doTest(p, testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Policy.setPolicy(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        doTestSM(testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // get an instance of JavaPolicy from SunRsaSign
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            p = Policy.getInstance(JAVA_POLICY, null, "SunRsaSign");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            throw new SecurityException("test " + testnum++ + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.out.println("test " + testnum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // get an instance of JavaPolicy from FOO
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            p = Policy.getInstance(JAVA_POLICY, null, "FOO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new SecurityException("test " + testnum++ + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } catch (NoSuchProviderException nspe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            System.out.println("test " + testnum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return testnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private int testProvider(int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // get an instance of JavaPolicy from SUN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        Policy p = Policy.getInstance(JAVA_POLICY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                Security.getProvider("SUN"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        doTest(p, testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Policy.setPolicy(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        doTestSM(testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        // get an instance of JavaPolicy from SunRsaSign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            p = Policy.getInstance(JAVA_POLICY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                Security.getProvider("SunRsaSign"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new SecurityException("test " + testnum++ + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } catch (NoSuchAlgorithmException nsae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            System.out.println("test " + testnum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return testnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private int testBadParam(int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // pass bad param
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            Policy p = Policy.getInstance(JAVA_POLICY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                new BadParam());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            throw new SecurityException("test " + testnum++ + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            System.out.println("test " + testnum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            Policy p = Policy.getInstance(JAVA_POLICY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                new BadParam(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                "SUN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throw new SecurityException("test " + testnum++ + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            System.out.println("test " + testnum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            Policy p = Policy.getInstance(JAVA_POLICY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                new BadParam(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                Security.getProvider("SUN"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new SecurityException("test " + testnum++ + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // good
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            System.out.println("test " + testnum++ + " passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return testnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private int testURIParam(int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // get an instance of JavaPolicy from SUN and have it read from the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        File file = new File(System.getProperty("test.src", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                "GetInstance.policyURL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        URI uri = file.toURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Policy p = Policy.getInstance(JAVA_POLICY, new URIParameter(uri));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        doTest(p, testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        Policy.setPolicy(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        doTestSM(testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return testnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private int testCustomImpl(int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        Provider customProvider = new GetInstanceProvider();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        Policy p = Policy.getInstance("GetInstancePolicySpi",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                customProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // doTest has a case that will not work with custom policies,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // so do not call it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        // doTest(p, testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Policy.setPolicy(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        doTestSM(testnum++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return testnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private void doTest(Policy p, int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // check granted perm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (p.implies(this.getClass().getProtectionDomain(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                        new SecurityPermission("GetInstanceTest"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            System.out.println("test " + testnum + ".1 passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throw new SecurityException("test " + testnum + ".1 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // check perm not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (p.implies(this.getClass().getProtectionDomain(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                        new SecurityPermission("NotGranted"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new SecurityException("test " + testnum + ".2 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            System.out.println("test " + testnum + ".2 passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // test getProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if ("SUN".equals(p.getProvider().getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            System.out.println("test " + testnum + ".3 passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw new SecurityException("test " + testnum + ".3 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        // test getType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (JAVA_POLICY.equals(p.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            System.out.println("test " + testnum + ".4 passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            throw new SecurityException("test " + testnum + ".4 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private void doTestSM(int testnum) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        // check granted perm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        System.getSecurityManager().checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                        (new SecurityPermission("GetInstanceTest"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        System.out.println("test " + testnum + ".1 passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // check perm not granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            System.getSecurityManager().checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        (new SecurityPermission("NotGranted"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            throw new RuntimeException("test " + testnum + ".2 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            System.out.println("test " + testnum + ".2 passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
}