author | mli |
Wed, 11 Jan 2017 19:36:11 -0800 | |
changeset 43066 | bc2234c64fbd |
parent 43010 | f3c984a6f1d9 |
permissions | -rw-r--r-- |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
1 |
/* |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
* @bug 4183202 |
|
26 |
* @summary rmid and rmiregistry could allow alternate security manager |
|
27 |
* @author Laird Dornin |
|
28 |
* |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
29 |
* @library ../../testlibrary |
30820 | 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 |
|
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
34 |
* java.base/sun.nio.ch |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
35 |
* @build TestLibrary RMID RMIDSelectorProvider RegistryVM RMIRegistryRunner |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
36 |
* TestSecurityManager |
2 | 37 |
* @run main/othervm AltSecurityManager |
38 |
*/ |
|
39 |
||
40 |
/** |
|
41 |
* Ensure that a user is able to specify alternate security managers to |
|
42 |
* be used in rmiregistry and rmid. Test specifies a security manager |
|
43 |
* that throws a runtime exception in its checkListen method, this |
|
44 |
* will cause rmiregistry and rmid to exit early because those |
|
45 |
* utilities will be unable to export any remote objects; test fails |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
46 |
* if registry and rmid take too long to exit. |
2 | 47 |
*/ |
48 |
public class AltSecurityManager implements Runnable { |
|
49 |
// variable to hold registry and rmid children |
|
50 |
static JavaVM vm = null; |
|
51 |
||
52 |
// names of utilities |
|
53 |
static String utilityToStart = null; |
|
13256 | 54 |
static final String REGISTRY_IMPL = "sun.rmi.registry.RegistryImpl"; |
55 |
static final String ACTIVATION = "sun.rmi.server.Activation"; |
|
2 | 56 |
|
57 |
// children should exit in at least this time. |
|
43010
f3c984a6f1d9
8030175: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails due to timeout
mli
parents:
35667
diff
changeset
|
58 |
private static final long TIME_OUT = |
f3c984a6f1d9
8030175: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails due to timeout
mli
parents:
35667
diff
changeset
|
59 |
(long)(15000 * TestLibrary.getTimeoutFactor()); |
2 | 60 |
|
61 |
public void run() { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
62 |
try { |
13256 | 63 |
if (utilityToStart.equals(REGISTRY_IMPL)) { |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
64 |
vm = RegistryVM.createRegistryVMWithRunner( |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
65 |
"RMIRegistryRunner", |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
66 |
"-Djava.security.manager=TestSecurityManager"); |
13256 | 67 |
} else if (utilityToStart.contains(ACTIVATION)) { |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
68 |
vm = RMID.createRMIDOnEphemeralPortWithOptions( |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
69 |
"-Djava.security.manager=TestSecurityManager"); |
13256 | 70 |
} else { |
71 |
TestLibrary.bomb("Utility to start must be " + REGISTRY_IMPL + |
|
72 |
" or " + ACTIVATION); |
|
73 |
} |
|
74 |
||
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
75 |
System.err.println("starting " + utilityToStart); |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
76 |
try { |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
77 |
vm.start(); |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
78 |
throw new RuntimeException("Expected exception did not occur!"); |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
79 |
} catch (Exception expected) { |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
80 |
int exit = vm.waitFor(); |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
81 |
if (exit != TestSecurityManager.EXIT_VALUE) { |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
82 |
throw new RuntimeException(utilityToStart |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
83 |
+ " exit with an unexpected value " |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
84 |
+ exit + "."); |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
85 |
} |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
86 |
System.err.format("Success: starting %s exited with status %d%n", |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
87 |
utilityToStart, TestSecurityManager.EXIT_VALUE); |
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
88 |
} |
2 | 89 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
90 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
91 |
TestLibrary.bomb(e); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
92 |
} |
2 | 93 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
94 |
|
2 | 95 |
/** |
96 |
* Wait to make sure that the registry and rmid exit after |
|
97 |
* their security manager is set. |
|
98 |
*/ |
|
99 |
public static void ensureExit(String utility) throws Exception { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
100 |
utilityToStart = utility; |
2 | 101 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
102 |
try { |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
103 |
Thread thread = new Thread(new AltSecurityManager()); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
104 |
System.err.println("expecting RuntimeException for " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
105 |
"checkListen in child process"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
106 |
long start = System.currentTimeMillis(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
107 |
thread.start(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
108 |
thread.join(TIME_OUT); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
109 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
110 |
long time = System.currentTimeMillis() - start; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
111 |
System.err.println("waited " + time + " millis for " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
112 |
utilityToStart + " to die"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
113 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
114 |
if (time >= TIME_OUT) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
115 |
TestLibrary.bomb(utilityToStart + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
116 |
" took too long to die..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
117 |
} else { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
118 |
System.err.println(utilityToStart + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
119 |
" terminated on time"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
120 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
121 |
} finally { |
43066
bc2234c64fbd
8172314: java/rmi/registry/altSecurityManager/AltSecurityManager.java fails with "port in use"
mli
parents:
43010
diff
changeset
|
122 |
vm.cleanup(); |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
123 |
vm = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
124 |
} |
2 | 125 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
126 |
|
2 | 127 |
public static void main(String[] args) { |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
128 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
129 |
System.err.println("\nRegression test for bug 4183202\n"); |
2 | 130 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
131 |
// make sure the registry exits early. |
13256 | 132 |
ensureExit(REGISTRY_IMPL); |
2 | 133 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
134 |
// make sure rmid exits early |
13256 | 135 |
ensureExit(ACTIVATION); |
2 | 136 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
137 |
System.err.println("test passed"); |
2 | 138 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
139 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
140 |
TestLibrary.bomb(e); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
141 |
} finally { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
142 |
RMID.removeLog(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
143 |
} |
2 | 144 |
} |
145 |
} |