Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/registry/altSecurityManager/AltSecurityManager.java
41155 views
1
/*
2
* Copyright (c) 1999, 2021, 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
/* @test
25
* @bug 4183202
26
* @summary rmiregistry could allow alternate security manager
27
* @author Laird Dornin
28
*
29
* @library ../../testlibrary
30
* @modules java.rmi/sun.rmi.registry
31
* java.rmi/sun.rmi.server
32
* java.rmi/sun.rmi.transport
33
* java.rmi/sun.rmi.transport.tcp
34
* java.base/sun.nio.ch
35
* @build TestLibrary RegistryVM RMIRegistryRunner TestSecurityManager
36
* @run main/othervm AltSecurityManager
37
*/
38
39
/**
40
* Ensure that a user is able to specify alternate security managers to
41
* be used in rmiregistry. Test specifies a security manager
42
* that throws a runtime exception in its checkListen method, this
43
* will cause rmiregistry to exit early because those
44
* utilities will be unable to export any remote objects; test fails
45
* if registry takes too long to exit.
46
*/
47
public class AltSecurityManager implements Runnable {
48
// variable to hold registry child
49
static JavaVM vm = null;
50
51
// names of utilities
52
static String utilityToStart = null;
53
static final String REGISTRY_IMPL = "sun.rmi.registry.RegistryImpl";
54
55
// children should exit in at least this time.
56
private static final long TIME_OUT =
57
(long)(15000 * TestLibrary.getTimeoutFactor());
58
59
public void run() {
60
try {
61
if (utilityToStart.equals(REGISTRY_IMPL)) {
62
vm = RegistryVM.createRegistryVMWithRunner(
63
"RMIRegistryRunner",
64
"-Djava.security.manager=TestSecurityManager");
65
} else {
66
TestLibrary.bomb("Utility to start must be " + REGISTRY_IMPL);
67
}
68
69
System.err.println("starting " + utilityToStart);
70
try {
71
vm.start();
72
throw new RuntimeException("Expected exception did not occur!");
73
} catch (Exception expected) {
74
int exit = vm.waitFor();
75
if (exit != TestSecurityManager.EXIT_VALUE) {
76
throw new RuntimeException(utilityToStart
77
+ " exit with an unexpected value "
78
+ exit + ".");
79
}
80
System.err.format("Success: starting %s exited with status %d%n",
81
utilityToStart, TestSecurityManager.EXIT_VALUE);
82
}
83
84
} catch (Exception e) {
85
TestLibrary.bomb(e);
86
}
87
}
88
89
/**
90
* Wait to make sure that the registry exits after
91
* their security manager is set.
92
*/
93
public static void ensureExit(String utility) throws Exception {
94
utilityToStart = utility;
95
96
try {
97
Thread thread = new Thread(new AltSecurityManager());
98
System.err.println("expecting RuntimeException for " +
99
"checkListen in child process");
100
long start = System.currentTimeMillis();
101
thread.start();
102
thread.join(TIME_OUT);
103
104
long time = System.currentTimeMillis() - start;
105
System.err.println("waited " + time + " millis for " +
106
utilityToStart + " to die");
107
108
if (time >= TIME_OUT) {
109
TestLibrary.bomb(utilityToStart +
110
" took too long to die...");
111
} else {
112
System.err.println(utilityToStart +
113
" terminated on time");
114
}
115
} finally {
116
vm.cleanup();
117
vm = null;
118
}
119
}
120
121
public static void main(String[] args) {
122
try {
123
System.err.println("\nRegression test for bug 4183202\n");
124
125
// make sure the registry exits early.
126
ensureExit(REGISTRY_IMPL);
127
128
System.err.println("test passed");
129
130
} catch (Exception e) {
131
TestLibrary.bomb(e);
132
}
133
}
134
}
135
136