author | smarks |
Mon, 07 Jan 2013 18:09:07 -0800 | |
changeset 15005 | 796ffc400e9e |
parent 14778 | 5947768d173d |
child 27784 | a51d6d4e0528 |
permissions | -rw-r--r-- |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
1 |
/* |
15005
796ffc400e9e
7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
smarks
parents:
14778
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, 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 |
14778 | 30 |
* @build TestLibrary JavaVM RMID TestSecurityManager |
2 | 31 |
* @run main/othervm AltSecurityManager |
32 |
*/ |
|
33 |
||
34 |
/** |
|
35 |
* Ensure that a user is able to specify alternate security managers to |
|
36 |
* be used in rmiregistry and rmid. Test specifies a security manager |
|
37 |
* that throws a runtime exception in its checkListen method, this |
|
38 |
* will cause rmiregistry and rmid to exit early because those |
|
39 |
* 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
|
40 |
* if registry and rmid take too long to exit. |
2 | 41 |
*/ |
42 |
public class AltSecurityManager implements Runnable { |
|
13256 | 43 |
private final int regPort; |
2 | 44 |
// variable to hold registry and rmid children |
45 |
static JavaVM vm = null; |
|
46 |
||
47 |
// names of utilities |
|
48 |
static String utilityToStart = null; |
|
13256 | 49 |
static final String REGISTRY_IMPL = "sun.rmi.registry.RegistryImpl"; |
50 |
static final String ACTIVATION = "sun.rmi.server.Activation"; |
|
2 | 51 |
|
52 |
// children should exit in at least this time. |
|
53 |
static long TIME_OUT = 15000; |
|
54 |
||
13256 | 55 |
public AltSecurityManager(int port) { |
56 |
if (port <= 0) { |
|
57 |
TestLibrary.bomb("Port must be greater then 0."); |
|
58 |
} |
|
59 |
||
60 |
this.regPort = port; |
|
61 |
} |
|
62 |
||
2 | 63 |
public void run() { |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
64 |
try { |
13256 | 65 |
if (utilityToStart.equals(REGISTRY_IMPL)) { |
66 |
vm = new JavaVM(utilityToStart, |
|
67 |
" -Djava.security.manager=TestSecurityManager", |
|
68 |
Integer.toString(regPort)); |
|
69 |
} else if (utilityToStart.contains(ACTIVATION)) { |
|
70 |
vm = new JavaVM(utilityToStart, |
|
71 |
" -Djava.security.manager=TestSecurityManager", |
|
72 |
"-port " + Integer.toString(regPort)); |
|
73 |
} else { |
|
74 |
TestLibrary.bomb("Utility to start must be " + REGISTRY_IMPL + |
|
75 |
" or " + ACTIVATION); |
|
76 |
} |
|
77 |
||
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
78 |
System.err.println("starting " + utilityToStart); |
15005
796ffc400e9e
7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
smarks
parents:
14778
diff
changeset
|
79 |
vm.execute(); |
2 | 80 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
81 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
82 |
TestLibrary.bomb(e); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
83 |
} |
2 | 84 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
85 |
|
2 | 86 |
/** |
87 |
* Wait to make sure that the registry and rmid exit after |
|
88 |
* their security manager is set. |
|
89 |
*/ |
|
90 |
public static void ensureExit(String utility) throws Exception { |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
91 |
utilityToStart = utility; |
2 | 92 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
93 |
try { |
13256 | 94 |
int port = TestLibrary.getUnusedRandomPort(); |
95 |
Thread thread = new Thread(new AltSecurityManager(port)); |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
96 |
System.err.println("expecting RuntimeException for " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
97 |
"checkListen in child process"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
98 |
long start = System.currentTimeMillis(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
99 |
thread.start(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
100 |
thread.join(TIME_OUT); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
101 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
102 |
long time = System.currentTimeMillis() - start; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
103 |
System.err.println("waited " + time + " millis for " + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
104 |
utilityToStart + " to die"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
105 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
106 |
if (time >= TIME_OUT) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
107 |
|
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
108 |
// dont pollute other tests; increase the likelihood |
2 | 109 |
// that rmid will go away if it did not exit already. |
13256 | 110 |
if (utility.equals(ACTIVATION)) { |
111 |
RMID.shutdown(port); |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
112 |
} |
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 |
TestLibrary.bomb(utilityToStart + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
115 |
" took too long to die..."); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
116 |
} else { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
117 |
System.err.println(utilityToStart + |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
118 |
" terminated on time"); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
119 |
} |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
120 |
} finally { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
121 |
vm.destroy(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
122 |
vm = null; |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
123 |
} |
2 | 124 |
} |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
125 |
|
2 | 126 |
public static void main(String[] args) { |
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
127 |
try { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
128 |
System.err.println("\nRegression test for bug 4183202\n"); |
2 | 129 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
130 |
// make sure the registry exits early. |
13256 | 131 |
ensureExit(REGISTRY_IMPL); |
2 | 132 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
133 |
// make sure rmid exits early |
13256 | 134 |
ensureExit(ACTIVATION); |
2 | 135 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
136 |
System.err.println("test passed"); |
2 | 137 |
|
309
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
138 |
} catch (Exception e) { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
139 |
TestLibrary.bomb(e); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
140 |
} finally { |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
141 |
RMID.removeLog(); |
bda219d843f6
6627823: Missed whitespace normalization files: jdk/test/java/rmi
ohair
parents:
2
diff
changeset
|
142 |
} |
2 | 143 |
} |
144 |
} |