2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 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 Recursion
|
|
30 |
*/
|
|
31 |
|
|
32 |
import java.net.*;
|
|
33 |
import java.security.*;
|
|
34 |
|
|
35 |
public class Recursion {
|
|
36 |
|
|
37 |
public static void main(String[] args) throws Exception {
|
|
38 |
|
|
39 |
// trigger security check to make sure policy is set
|
|
40 |
try {
|
|
41 |
System.getProperty("foo.bar");
|
|
42 |
} catch (Exception e) {
|
|
43 |
// fall thru
|
|
44 |
}
|
|
45 |
|
|
46 |
// static perms
|
|
47 |
Permissions staticPerms = new Permissions();
|
|
48 |
staticPerms.add(new java.util.PropertyPermission("static.foo", "read"));
|
|
49 |
|
|
50 |
ProtectionDomain pd = new ProtectionDomain
|
|
51 |
(new CodeSource
|
|
52 |
(new URL("http://foo"),
|
|
53 |
(java.security.cert.Certificate[])null),
|
|
54 |
staticPerms,
|
|
55 |
null,
|
|
56 |
null);
|
|
57 |
|
|
58 |
// test with no SecurityManager
|
|
59 |
//
|
|
60 |
// merging should have occured - check for policy merged.foo permission
|
|
61 |
|
|
62 |
System.setSecurityManager(null);
|
|
63 |
if (pd.toString().indexOf("merged.foo") < 0) {
|
|
64 |
throw new Exception("Test without SecurityManager failed");
|
|
65 |
}
|
|
66 |
|
|
67 |
// test with SecurityManager on the bootclasspath, debug turned off,
|
|
68 |
// getPolicyPermission granted
|
|
69 |
//
|
|
70 |
// merging should have occured - check for policy merged.foo permission
|
|
71 |
|
|
72 |
ProtectionDomain pd2 = new ProtectionDomain
|
|
73 |
(new CodeSource
|
|
74 |
(new URL("http://bar"),
|
|
75 |
(java.security.cert.Certificate[])null),
|
|
76 |
staticPerms,
|
|
77 |
null,
|
|
78 |
null);
|
|
79 |
|
|
80 |
System.setSecurityManager(new SecurityManager());
|
|
81 |
if (pd2.toString().indexOf("merged.foo") < 0) {
|
|
82 |
throw new Exception("Test with bootclass SecurityManager failed");
|
|
83 |
}
|
|
84 |
}
|
|
85 |
}
|