Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/Security/ClassLoader/DeprivilegedModuleLoaderTest.java
41153 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. 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 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
/*
25
* @test
26
* @bug 8159964
27
* @summary Classes from deprivileged modules should get loaded through
28
* Platform Classloader.
29
* @modules java.xml.crypto
30
* jdk.security.auth
31
* jdk.security.jgss
32
* @run main DeprivilegedModuleLoaderTest
33
*/
34
35
import java.io.File;
36
import java.util.ArrayList;
37
import java.util.List;
38
import javax.security.auth.kerberos.KeyTab;
39
import javax.xml.crypto.KeySelectorException;
40
import javax.xml.crypto.dsig.XMLSignatureFactory;
41
import com.sun.security.auth.callback.TextCallbackHandler;
42
import com.sun.security.jgss.AuthorizationDataEntry;
43
44
public class DeprivilegedModuleLoaderTest {
45
46
public static void main(String[] args) {
47
48
boolean pass = true;
49
List<Class<?>> classes = getDeprivilegedClasses();
50
for (Class<?> cls : classes) {
51
try {
52
pass &= testPlatformClassLoader(cls);
53
} catch (Exception exc) {
54
exc.printStackTrace(System.out);
55
pass = false;
56
}
57
}
58
59
if (!pass) {
60
throw new RuntimeException("Atleast one test failed.");
61
}
62
}
63
64
private static List<Class<?>> getDeprivilegedClasses() {
65
66
List<Class<?>> classes = new ArrayList<Class<?>>();
67
// Test from java.xml.crypto/javax/xml/crypto/dsig package
68
classes.add(XMLSignatureFactory.class);
69
// Test from java.xml.crypto/javax/xml/crypto package
70
classes.add(KeySelectorException.class);
71
// Test From java.security.jgss/javax/security/auth/kerberos package
72
classes.add(KeyTab.class);
73
// Test from jdk.security.jgss/com/sun/security/jgss package
74
classes.add(AuthorizationDataEntry.class);
75
// Test from jdk.security.auth/com/sun/security/auth/callback package
76
classes.add(TextCallbackHandler.class);
77
return classes;
78
}
79
80
private static boolean testPlatformClassLoader(Class<?> cls) {
81
82
ClassLoader loader = cls.getClassLoader();
83
if (loader == null) {
84
throw new RuntimeException(String.format(
85
"Loaded through Bootstrap Classloader: '%s'", cls));
86
} else if (!loader.toString().contains("PlatformClassLoader")) {
87
throw new RuntimeException(String.format(
88
"Not loaded through Platform ClassLoader: '%s'", cls));
89
}
90
System.out.println(String.format(
91
"Pass: '%s' get loaded through PlatformClassLoader", cls));
92
return true;
93
}
94
}
95
96