author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 43733 | 25b25148d346 |
permissions | -rw-r--r-- |
12446 | 1 |
/* |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
2 |
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
12446 | 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 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. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
25 |
* @test |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
26 |
* @bug 6741606 7146431 8000450 8019830 8022945 8027144 8041633 8078427 8055206 |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
27 |
* @summary Check that various restricted packages that are supposed to be |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
28 |
* restricted by default or are listed in the package.access |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
29 |
* property in the java.security file are blocked |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
30 |
* @modules java.xml.ws java.corba |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
31 |
* @run main/othervm CheckPackageAccess |
12446 | 32 |
*/ |
33 |
||
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
34 |
import java.lang.module.ModuleFinder; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
35 |
import java.lang.module.ModuleReference; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
36 |
import java.util.Arrays; |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
37 |
import java.util.List; |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
38 |
import java.util.Optional; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
39 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
40 |
public class CheckPackageAccess { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
41 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
42 |
private static final SecurityManager sm = new SecurityManager(); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
43 |
private static final ModuleFinder mf = ModuleFinder.ofSystem(); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
44 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
45 |
/* |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
46 |
* The expected list of restricted packages of the package.access property. |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
47 |
* |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
48 |
* This array should be updated whenever new packages are added to the |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
49 |
* package.access property in the java.security file |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
50 |
* NOTE: it should be in the same order as the java.security file |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
51 |
*/ |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
52 |
private static final String[] EXPECTED = { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
53 |
"sun.misc.", |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
54 |
"sun.reflect.", |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
55 |
}; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
56 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
57 |
/** |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
58 |
* Tests access to various packages of a module. |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
59 |
*/ |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
60 |
private static class Test { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
61 |
String moduleName; // name of module |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
62 |
ModuleReference moduleRef; // module reference |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
63 |
String exports; // exported pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
64 |
Optional<String> opens; // opened pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
65 |
String conceals; // concealed pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
66 |
Optional<String> qualExports; // qualified export pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
67 |
Optional<String> qualOpens; // qualified open pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
68 |
// qual open and non-qualified export pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
69 |
Optional<String> qualOpensAndExports; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
70 |
Test(String module, String exports, String opens, String conceals, |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
71 |
String qualExports, String qualOpens, String qualOpensAndExports) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
72 |
this.moduleName = module; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
73 |
this.moduleRef = mf.find(moduleName).get(); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
74 |
this.exports = exports; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
75 |
this.opens = Optional.ofNullable(opens); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
76 |
this.conceals = conceals; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
77 |
this.qualExports = Optional.ofNullable(qualExports); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
78 |
this.qualOpens = Optional.ofNullable(qualOpens); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
79 |
this.qualOpensAndExports = Optional.ofNullable(qualOpensAndExports); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
80 |
} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
81 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
82 |
void test() { |
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
83 |
final boolean isModulePresent = |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
43733
diff
changeset
|
84 |
ModuleLayer.boot().findModule(moduleName).isPresent(); |
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
85 |
System.out.format("Testing module: %1$s. Module is%2$s present.\n", |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
86 |
moduleName, isModulePresent ? "" : " NOT"); |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
87 |
|
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
88 |
if (isModulePresent) { |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
89 |
|
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
90 |
// access to exported pkg should pass |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
91 |
testNonRestricted(exports); |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
92 |
|
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
93 |
// access to opened pkg should pass |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
94 |
opens.ifPresent(Test::testNonRestricted); |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
95 |
|
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
96 |
// access to concealed pkg should fail |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
97 |
testRestricted(conceals); |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
98 |
|
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
99 |
// access to qualified export pkg should fail |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
100 |
qualExports.ifPresent(Test::testRestricted); |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
101 |
|
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
102 |
// access to qualified open pkg should fail |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
103 |
qualOpens.ifPresent(Test::testRestricted); |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
104 |
|
43733
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
105 |
// access to qualified opened pkg that is also exported should pass |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
106 |
qualOpensAndExports.ifPresent(Test::testNonRestricted); |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
107 |
} else { |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
108 |
System.out.println("Skipping tests for module."); |
25b25148d346
8174194: Several java/lang tests failing due to undeclared module dependencies
skovalev
parents:
43245
diff
changeset
|
109 |
} |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
110 |
} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
111 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
112 |
private static void testRestricted(String pkg) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
113 |
try { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
114 |
sm.checkPackageAccess(pkg); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
115 |
throw new RuntimeException("Able to access restricted package: " |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
116 |
+ pkg); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
117 |
} catch (SecurityException se) {} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
118 |
try { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
119 |
sm.checkPackageDefinition(pkg); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
120 |
throw new RuntimeException("Able to access restricted package: " |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
121 |
+ pkg); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
122 |
} catch (SecurityException se) {} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
123 |
} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
124 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
125 |
private static void testNonRestricted(String pkg) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
126 |
try { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
127 |
sm.checkPackageAccess(pkg); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
128 |
} catch (SecurityException se) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
129 |
throw new RuntimeException("Unable to access exported package: " |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
130 |
+ pkg, se); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
131 |
} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
132 |
try { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
133 |
sm.checkPackageDefinition(pkg); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
134 |
} catch (SecurityException se) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
135 |
throw new RuntimeException("Unable to access exported package: " |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
136 |
+ pkg, se); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
137 |
} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
138 |
} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
139 |
} |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
140 |
|
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
141 |
private static final Test[] tests = new Test[] { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
142 |
// java.base module loaded by boot loader |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
143 |
new Test("java.base", "java.security", null, "jdk.internal.jrtfs", |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
144 |
"jdk.internal.loader", null, null), |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
145 |
// java.desktop module loaded by boot loader and has an openQual pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
146 |
// that is exported |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
147 |
new Test("java.desktop", "java.applet", null, "sun.applet", |
43245
bc7dea80c4d0
8173082: java/bean/* tests fail since change of JDK-8055206
mullan
parents:
43221
diff
changeset
|
148 |
"sun.awt", null, "javax.swing.plaf.basic"), |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
149 |
// java.security.jgss module loaded by platform loader |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
150 |
new Test("java.security.jgss", "org.ietf.jgss", null, |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
151 |
"sun.security.krb5.internal.crypto", "sun.security.krb5", |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
152 |
null, null), |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
153 |
// java.xml.ws module loaded by platform loader but needs to be added |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
154 |
// and has an openQual pkg that is exported |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
155 |
new Test("java.xml.ws", "javax.xml.soap", null, |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
156 |
"com.sun.xml.internal.stream.buffer", |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
157 |
"com.sun.xml.internal.ws.api", null, |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
158 |
"javax.xml.ws.wsaddressing"), |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
159 |
// java.xml.ws module loaded by platform loader but needs to be added |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
160 |
// and has an openQual pkg |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
161 |
new Test("java.corba", "javax.rmi", null, "sun.corba", |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
162 |
"com.sun.corba.se.impl.util", "com.sun.jndi.cosnaming", null), |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
163 |
}; |
12446 | 164 |
|
31180
316a8c3e572a
8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents:
27565
diff
changeset
|
165 |
public static void main(String[] args) throws Exception { |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
166 |
|
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
167 |
// check expected list of restricted packages in java.security file |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
168 |
checkPackages(Arrays.asList(EXPECTED)); |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
169 |
|
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
170 |
// check access to each module's packages |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
171 |
for (Test test : tests) { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
172 |
test.test(); |
20774
330ea6efa3fd
8007292: Add JavaFX internal packages to package.access
mullan
parents:
19600
diff
changeset
|
173 |
} |
330ea6efa3fd
8007292: Add JavaFX internal packages to package.access
mullan
parents:
19600
diff
changeset
|
174 |
|
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
175 |
System.out.println("Test passed"); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
176 |
} |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
177 |
|
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
178 |
private static void checkPackages(List<String> pkgs) { |
31180
316a8c3e572a
8072692: Improve performance of SecurityManager.checkPackageAccess
dfuchs
parents:
27565
diff
changeset
|
179 |
for (String pkg : pkgs) { |
12446 | 180 |
try { |
181 |
sm.checkPackageAccess(pkg); |
|
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
182 |
throw new RuntimeException("Able to access " + pkg + |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
183 |
" package"); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
184 |
} catch (SecurityException se) { } |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
185 |
try { |
18138
02cb2d482ed0
8000450: Restrict access to com/sun/corba/se/impl package
coffeys
parents:
12446
diff
changeset
|
186 |
sm.checkPackageDefinition(pkg); |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
187 |
throw new RuntimeException("Able to define class in " + pkg + |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
188 |
" package"); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
189 |
} catch (SecurityException se) { } |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
190 |
String subpkg = pkg + "foo"; |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
191 |
try { |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
192 |
sm.checkPackageAccess(subpkg); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
193 |
throw new RuntimeException("Able to access " + subpkg + |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
194 |
" package"); |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
195 |
} catch (SecurityException se) { } |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
196 |
try { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
197 |
sm.checkPackageDefinition(subpkg); |
43221
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
198 |
throw new RuntimeException("Able to define class in " + |
eef9383d25cb
8055206: Update SecurityManager::checkPackageAccess to restrict non-exported JDK packages by default
mullan
parents:
33283
diff
changeset
|
199 |
subpkg + " package"); |
12446 | 200 |
} catch (SecurityException se) { } |
201 |
} |
|
20874
3d0974c9a59e
8026346: test/java/lang/SecurityManager/CheckPackageAccess.java failing
mullan
parents:
20774
diff
changeset
|
202 |
} |
12446 | 203 |
} |