ContextInsulation.java revision 6244:bd84d0927a2e
1/* 2 * Copyright (c) 2001, 2003, 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 4450891 26 * @summary verify that the java.util.ServiceLoader-based location of an 27 * RMIClassLoader provider does not require any permissions of the 28 * (arbitrary) protection domains that happens to be on the stack 29 * when RMIClassLoader is first used. 30 * @author Peter Jones 31 * 32 * @library ../../../testlibrary 33 * @build TestLibrary ServiceConfiguration TestProvider TestProvider2 34 * @run main/othervm/policy=security.policy ContextInsulation 35 */ 36 37import java.security.AccessControlContext; 38import java.security.CodeSource; 39import java.security.Permissions; 40import java.security.ProtectionDomain; 41import java.security.cert.Certificate; 42 43public class ContextInsulation { 44 public static void main(String[] args) throws Exception { 45 46 /* 47 * If we delay setting the security manager until after the service 48 * configuration file has been installed, then this test still 49 * functions properly, but the -Djava.security.debug output is 50 * lacking, so to ease debugging, we'll set it early-- at the cost 51 * of having to specify the policy even when running standalone. 52 */ 53 TestLibrary.suggestSecurityManager(null); 54 55 ServiceConfiguration.installServiceConfigurationFile(); 56 57 /* 58 * Execute use of RMIClassLoader within an AccessControlContext 59 * that has a protection domain with no permissions, to make sure 60 * that RMIClassLoader can still properly initialize itself. 61 */ 62 CodeSource codesource = new CodeSource(null, (Certificate[]) null); 63 Permissions perms = null; 64 ProtectionDomain pd = new ProtectionDomain(codesource, perms); 65 AccessControlContext acc = 66 new AccessControlContext(new ProtectionDomain[] { pd }); 67 68 java.security.AccessController.doPrivileged( 69 new java.security.PrivilegedExceptionAction() { 70 public Object run() throws Exception { 71 TestProvider.exerciseTestProvider( 72 TestProvider2.loadClassReturn, 73 TestProvider2.loadProxyClassReturn, 74 TestProvider2.getClassLoaderReturn, 75 TestProvider2.getClassAnnotationReturn, 76 TestProvider2.invocations); 77 return null; 78 } 79 }, acc); 80 } 81} 82