Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/provider/PolicyParser/ExtDirsChange.java
38853 views
1
/*
2
* Copyright (c) 2004, 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 4993819
27
* @summary standard extensions path is hard-coded in default
28
* system policy file
29
* @ignore run this by hand
30
*
31
* javac ExtDirChange
32
* rm ExtDirsA*.class ExtDirsB*.class
33
* java -Djava.security.manager \
34
* -Dtest.src=. \
35
* -Djava.security.policy=ExtDirsChange.policy \
36
* -Djava.security.debug=parser \
37
* -cp ExtDirsA/a.jar:ExtDirsB/b.jar:. \
38
* ExtDirsChange
39
*/
40
41
import java.io.File;
42
import java.security.*;
43
44
public class ExtDirsChange {
45
public static void main(String args[]) throws Exception {
46
System.out.println("java.ext.dirs: " +
47
System.getProperty("java.ext.dirs"));
48
49
// Uses default security policy and java.ext.dirs
50
try {
51
ExtDirsA a = new ExtDirsA();
52
a.go();
53
throw new Exception("Test Failed (Setup problem)");
54
} catch (SecurityException se) {
55
System.out.println("Setup OK");
56
}
57
58
// Change java.ext.dirs and refresh policy
59
AccessController.doPrivileged(new PrivilegedAction() {
60
public Object run() {
61
// Change java.ext.dirs
62
System.setProperty("java.ext.dirs",
63
"ExtDirsA" + File.pathSeparator + "ExtDirsB");
64
System.out.println("java.ext.dirs: " +
65
System.getProperty("java.ext.dirs"));
66
return null;
67
}
68
});
69
70
// Continue to use default security policy
71
try {
72
ExtDirsA a = new ExtDirsA();
73
a.go();
74
throw new Exception("Test Failed (Setup before refresh problem)");
75
} catch (SecurityException se) {
76
System.out.println("Setup before refresh OK");
77
}
78
79
// Refresh policy using updated java.ext.dirs
80
AccessController.doPrivileged(new PrivilegedAction() {
81
public Object run() {
82
Policy.getPolicy().refresh();
83
return null;
84
}
85
});
86
87
// Test should now succeed
88
try {
89
ExtDirsA a = new ExtDirsA();
90
a.go();
91
System.out.println("Test Succeeded");
92
} catch (SecurityException se) {
93
se.printStackTrace();
94
System.out.println("Test Failed");
95
throw se;
96
}
97
98
// Test with blank java.ext.dir
99
// Change java.ext.dirs and refresh policy
100
AccessController.doPrivileged(new PrivilegedAction() {
101
public Object run() {
102
// Change java.ext.dirs
103
System.setProperty("java.ext.dirs", " ");
104
System.out.println("java.ext.dirs: " +
105
System.getProperty("java.ext.dirs"));
106
Policy.getPolicy().refresh();
107
return null;
108
}
109
});
110
111
// Test with blank java.ext.dir
112
try {
113
ExtDirsA a = new ExtDirsA();
114
a.go();
115
throw new Exception("Blank Test Failed");
116
} catch (SecurityException se) {
117
System.out.println("Blank Test OK");
118
}
119
}
120
}
121
122