blob: 67cb7bca6c64db7ac4a5abe9bfcb3ad9a8faa554 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 * @bug 4180392
26 * @summary When an instance of java.rmi.RMISecurityManager is set the VM's
27 * security manager, the same package access restrictions should be in effect
28 * as when the default java.lang.SecurityManager is set, which with the
29 * default "java.security" file in the JDK means that access to packages in
30 * the sun.* package hierarchy is denied (without explicit runtime permission
31 * "accessClassInPackge.*").
32 * @author Peter Jones
33 *
34 * @build CheckPackageAccess
35 * @run main/othervm CheckPackageAccess
36 */
37
38import java.rmi.RMISecurityManager;
39
40public class CheckPackageAccess {
41
42 /*
43 * This test assumes that the default security manager protects untrusted
44 * access to classes in the sun.* hierarchy, which is what is specified
45 * in the JDK's default java.security file.
46 */
47 private final static String restrictedClassName = "sun.misc.Ref";
48
49 public static void main(String[] args) {
50
51 System.err.println("\nRegression test for bug 4180392\n");
52
53 System.err.println("Setting RMISecurityManager.");
54 System.setSecurityManager(new RMISecurityManager());
55
56 try {
57 System.err.println("Attempting to acquire restricted class " +
58 restrictedClassName);
59 Class restrictedClass = Class.forName(restrictedClassName);
60 throw new RuntimeException(
61 "TEST FAILED: successfully acquired restricted class " +
62 restrictedClass);
63 } catch (ClassNotFoundException e) {
64 throw new RuntimeException(
65 "TEST FAILED: couldn't find (but was allowed to look for) " +
66 "restricted class " + restrictedClassName);
67 } catch (SecurityException e) {
68 System.err.println("TEST PASSED: ");
69 e.printStackTrace();
70 }
71 }
72}