blob: 42b757e0cc4005e6f64fd0903f1374628f242913 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 4947618
27 * @summary Recursion problem in security manager and policy code
28 *
29 * @run main/othervm/policy=Recursion.policy -Djava.security.debug=domain RecursionDebug
30 */
31
32import java.security.*;
33import java.net.*;
34
35public class RecursionDebug {
36
37 // non bootclasspath SecurityManager
38 public static class RecursionSM extends SecurityManager {
39 public void checkPermission(Permission p) {
40 super.checkPermission(p);
41 }
42 }
43
44 public static void main(String[] args) throws Exception {
45
46 // trigger security check to make sure policy is set
47 try {
48 System.getProperty("foo.bar");
49 } catch (Exception e) {
50 // fall thru
51 }
52
53 // static perms
54 Permissions staticPerms = new Permissions();
55 staticPerms.add(new java.util.PropertyPermission("static.foo", "read"));
56
57 ProtectionDomain pd = new ProtectionDomain
58 (new CodeSource
59 (new URL("http://foo"),
60 (java.security.cert.Certificate[])null),
61 staticPerms,
62 null,
63 null);
64
65 // test with SecurityManager on the bootclasspath, debug turned on
66 //
67 // merging should have occured - check for policy merged.foo permission
68
69 if (pd.toString().indexOf("merged.foo") < 0) {
70 throw new Exception("Test with bootclass SecurityManager failed");
71 }
72
73 // test with SecurityManager not on bootclasspath, debug turned on
74 //
75 // merging should not have occured, and there should be no recursion
76
77 ProtectionDomain pd2 = new ProtectionDomain
78 (new CodeSource
79 (new URL("http://bar"),
80 (java.security.cert.Certificate[])null),
81 staticPerms,
82 null,
83 null);
84
85 System.setSecurityManager(new RecursionDebug.RecursionSM());
86 if (pd2.toString().indexOf("merged.foo") >= 0) {
87 throw new Exception
88 ("Test with custom non-bootclass SecurityManager failed");
89 }
90
91 System.setSecurityManager(null);
92 }
93}