author | weijun |
Fri, 16 Aug 2013 17:57:27 +0800 | |
changeset 22300 | d669110735f4 |
parent 18828 | f3678823f231 |
child 22308 | 8c0fcd365efc |
permissions | -rw-r--r-- |
12446 | 1 |
/* |
18138
02cb2d482ed0
8000450: Restrict access to com/sun/corba/se/impl package
coffeys
parents:
12446
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, 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 |
22300 | 26 |
* @bug 6741606 7146431 8000450 8022945 |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
27 |
* @summary Make sure all restricted packages listed in the package.access |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
28 |
* property in the java.security file are blocked |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
29 |
* @run main/othervm CheckPackageAccess |
12446 | 30 |
*/ |
31 |
||
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
32 |
import java.security.Security; |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
33 |
import java.util.Collections; |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
34 |
import java.util.Arrays; |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
35 |
import java.util.ArrayList; |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
36 |
import java.util.List; |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
37 |
import java.util.StringTokenizer; |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
38 |
|
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
39 |
/* |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
40 |
* The main benefit of this test is to catch merge errors or other types |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
41 |
* of issues where one or more of the packages are accidentally |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
42 |
* removed. This is why the packages that are known to be restricted have to |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
43 |
* be explicitly listed below. |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
44 |
*/ |
12446 | 45 |
public class CheckPackageAccess { |
46 |
||
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
47 |
/* |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
48 |
* This array should be updated whenever new packages are added to the |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
49 |
* package.access property in the java.security file |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
50 |
*/ |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
51 |
private static final String[] packages = { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
52 |
"sun.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
53 |
"com.sun.xml.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
54 |
"com.sun.imageio.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
55 |
"com.sun.istack.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
56 |
"com.sun.jmx.", |
22300 | 57 |
"com.sun.naming.internal.", |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
58 |
"com.sun.proxy.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
59 |
"com.sun.org.apache.bcel.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
60 |
"com.sun.org.apache.regexp.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
61 |
"com.sun.org.apache.xerces.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
62 |
"com.sun.org.apache.xpath.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
63 |
"com.sun.org.apache.xalan.internal.extensions.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
64 |
"com.sun.org.apache.xalan.internal.lib.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
65 |
"com.sun.org.apache.xalan.internal.res.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
66 |
"com.sun.org.apache.xalan.internal.templates.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
67 |
"com.sun.org.apache.xalan.internal.utils.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
68 |
"com.sun.org.apache.xalan.internal.xslt.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
69 |
"com.sun.org.apache.xalan.internal.xsltc.cmdline.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
70 |
"com.sun.org.apache.xalan.internal.xsltc.compiler.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
71 |
"com.sun.org.apache.xalan.internal.xsltc.trax.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
72 |
"com.sun.org.apache.xalan.internal.xsltc.util.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
73 |
"com.sun.org.apache.xml.internal.res.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
74 |
"com.sun.org.apache.xml.internal.security.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
75 |
"com.sun.org.apache.xml.internal.serializer.utils.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
76 |
"com.sun.org.apache.xml.internal.utils.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
77 |
"com.sun.org.glassfish.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
78 |
"com.oracle.xmlns.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
79 |
"com.oracle.webservices.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
80 |
"oracle.jrockit.jfr.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
81 |
"org.jcp.xml.dsig.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
82 |
"jdk.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
83 |
"jdk.nashorn.internal.", |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
84 |
"jdk.nashorn.tools." |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
85 |
}; |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
86 |
|
12446 | 87 |
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
|
88 |
List<String> pkgs = new ArrayList<>(Arrays.asList(packages)); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
89 |
String osName = System.getProperty("os.name"); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
90 |
if (osName.contains("OS X")) { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
91 |
pkgs.add("apple."); // add apple package for OS X |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
92 |
} else if (osName.startsWith("Windows")) { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
93 |
pkgs.add("com.sun.java.accessibility."); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
94 |
} |
12446 | 95 |
|
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
96 |
List<String> jspkgs = |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
97 |
getPackages(Security.getProperty("package.access")); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
98 |
|
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
99 |
// Sort to ensure lists are comparable |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
100 |
Collections.sort(pkgs); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
101 |
Collections.sort(jspkgs); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
102 |
|
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
103 |
if (!pkgs.equals(jspkgs)) { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
104 |
for (String p : pkgs) |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
105 |
if (!jspkgs.contains(p)) |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
106 |
System.out.println("In golden set, but not in j.s file: " + p); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
107 |
for (String p : jspkgs) |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
108 |
if (!pkgs.contains(p)) |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
109 |
System.out.println("In j.s file, but not in golden set: " + p); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
110 |
|
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
111 |
|
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
112 |
throw new RuntimeException("restricted packages are not " + |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
113 |
"consistent with java.security file"); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
114 |
} |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
115 |
System.setSecurityManager(new SecurityManager()); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
116 |
SecurityManager sm = System.getSecurityManager(); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
117 |
for (String pkg : packages) { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
118 |
String subpkg = pkg + "foo"; |
12446 | 119 |
try { |
120 |
sm.checkPackageAccess(pkg); |
|
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
121 |
throw new RuntimeException("Able to access " + pkg + |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
122 |
" package"); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
123 |
} catch (SecurityException se) { } |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
124 |
try { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
125 |
sm.checkPackageAccess(subpkg); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
126 |
throw new RuntimeException("Able to access " + subpkg + |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
127 |
" package"); |
18138
02cb2d482ed0
8000450: Restrict access to com/sun/corba/se/impl package
coffeys
parents:
12446
diff
changeset
|
128 |
} catch (SecurityException se) { } |
02cb2d482ed0
8000450: Restrict access to com/sun/corba/se/impl package
coffeys
parents:
12446
diff
changeset
|
129 |
try { |
02cb2d482ed0
8000450: Restrict access to com/sun/corba/se/impl package
coffeys
parents:
12446
diff
changeset
|
130 |
sm.checkPackageDefinition(pkg); |
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
131 |
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
|
132 |
" package"); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
133 |
} catch (SecurityException se) { } |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
134 |
try { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
135 |
sm.checkPackageDefinition(subpkg); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
136 |
throw new RuntimeException("Able to define class in " + subpkg + |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
137 |
" package"); |
12446 | 138 |
} catch (SecurityException se) { } |
139 |
} |
|
18791
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
140 |
System.out.println("Test passed"); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
141 |
} |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
142 |
|
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
143 |
private static List<String> getPackages(String p) { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
144 |
List<String> packages = new ArrayList<>(); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
145 |
if (p != null && !p.equals("")) { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
146 |
StringTokenizer tok = new StringTokenizer(p, ","); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
147 |
while (tok.hasMoreElements()) { |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
148 |
String s = tok.nextToken().trim(); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
149 |
packages.add(s); |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
150 |
} |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
151 |
} |
1973449fc9d9
8019979: Replace CheckPackageAccess test with better one from closed repo
coffeys
parents:
18138
diff
changeset
|
152 |
return packages; |
12446 | 153 |
} |
154 |
} |