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