2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
2
|
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 |
|
|
32 |
import java.security.*;
|
|
33 |
import java.net.*;
|
|
34 |
|
|
35 |
public 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 |
}
|