1 /* 2 * Copyright (c) 1999, 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 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 * "accessClassInPackage.*"). 32 * @author Peter Jones 33 * 34 * @run main/othervm CheckPackageAccess 35 */ 36 37 import java.rmi.RMISecurityManager; 38 39 public class CheckPackageAccess { 40 41 /* 42 * This test assumes that the default security manager protects untrusted 43 * access to classes in the sun.* hierarchy, which is what is specified 44 * in the JDK's default java.security file. 45 */ 46 private final static String restrictedClassName = "sun.misc.Cache"; 47 48 public static void main(String[] args) { 49 50 System.err.println("\nRegression test for bug 4180392\n"); 51 52 System.err.println("Setting RMISecurityManager."); 53 System.setSecurityManager(new RMISecurityManager()); 54 55 try { 56 System.err.println("Attempting to acquire restricted class " + 57 restrictedClassName); 58 Class restrictedClass = Class.forName(restrictedClassName); 59 throw new RuntimeException( 60 "TEST FAILED: successfully acquired restricted class " + 61 restrictedClass); 62 } catch (ClassNotFoundException e) { 63 throw new RuntimeException( 64 "TEST FAILED: couldn't find (but was allowed to look for) " + 65 "restricted class " + restrictedClassName); 66 } catch (SecurityException e) { 67 System.err.println("TEST PASSED: "); 68 e.printStackTrace(); 69 } 70 } 71 }