author | aeubanks |
Tue, 16 Apr 2019 13:06:23 -0700 | |
changeset 54770 | 62b6e7587b1f |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
27033 | 1 |
/* |
38883 | 2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
27033 | 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 |
/* |
|
26 |
* @test |
|
27 |
* @bug 8048052 |
|
28 |
* @summary Test a series of methods which requires "setFactory" runtime permission |
|
38883 | 29 |
* @modules java.rmi |
40795
bf74cb76388a
8165711: java/net/SetFactoryPermission/SetFactoryPermission.java needs to run in ovm mode
coffeys
parents:
38883
diff
changeset
|
30 |
* @run main/othervm SetFactoryPermission success |
27033 | 31 |
* @run main/othervm/policy=policy.fail SetFactoryPermission fail |
32 |
* @run main/othervm/policy=policy.success SetFactoryPermission success |
|
33 |
*/ |
|
34 |
import java.net.ServerSocket; |
|
35 |
import java.net.Socket; |
|
36 |
import java.net.URL; |
|
37 |
import java.net.URLConnection; |
|
38 |
import java.rmi.server.RMISocketFactory; |
|
39 |
import java.security.AccessControlException; |
|
40 |
||
41 |
public class SetFactoryPermission { |
|
42 |
static boolean success = false; |
|
43 |
||
44 |
interface Runner { |
|
45 |
public void run() throws Exception; |
|
46 |
} |
|
47 |
||
48 |
public static void main (String[] args) throws Exception { |
|
49 |
if (args.length > 0) { |
|
50 |
success = System.getSecurityManager() == null || args[0].equals("success"); |
|
51 |
} |
|
52 |
||
53 |
doTest(()->{ |
|
54 |
System.out.println("Verify URLConnection.setContentHandlerFactor()"); |
|
55 |
URLConnection.setContentHandlerFactory(null); |
|
56 |
}); |
|
57 |
doTest(()->{ |
|
58 |
System.out.println("Verify URL.setURLStreamHandlerFactory()"); |
|
59 |
URL.setURLStreamHandlerFactory(null); |
|
60 |
}); |
|
61 |
doTest(()->{ |
|
62 |
System.out.println("Verify ServerSocket.setSocketFactory()"); |
|
63 |
ServerSocket.setSocketFactory(null); |
|
64 |
}); |
|
65 |
doTest(()->{ |
|
66 |
System.out.println("Verify Socket.setSocketImplFactory()"); |
|
67 |
Socket.setSocketImplFactory(null); |
|
68 |
}); |
|
69 |
doTest(()->{ |
|
70 |
System.out.println("Verify RMISocketFactory.setSocketFactory()"); |
|
71 |
RMISocketFactory.setSocketFactory(null); |
|
72 |
}); |
|
73 |
} |
|
74 |
||
75 |
static void doTest(Runner func) throws Exception { |
|
76 |
try { |
|
77 |
func.run(); |
|
78 |
if (!success) { |
|
79 |
throw new RuntimeException("AccessControlException is not thrown. Test failed"); |
|
80 |
} |
|
81 |
} catch (SecurityException e) { |
|
82 |
if (success) { |
|
83 |
e.printStackTrace(); |
|
84 |
throw new RuntimeException("AccessControlException is thrown unexpectedly. Test failed"); |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
} |