blob: 928bf074d142873eada6b45eac69d1411bc7b68c [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001-2003 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 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
34 * @build ContextInsulation
35 * @build ServiceConfiguration
36 * @build TestProvider
37 * @build TestProvider2
38 * @run main/othervm/policy=security.policy ContextInsulation
39 */
40
41import java.security.AccessControlContext;
42import java.security.CodeSource;
43import java.security.Permissions;
44import java.security.ProtectionDomain;
45import java.security.cert.Certificate;
46
47public class ContextInsulation {
48 public static void main(String[] args) throws Exception {
49
50 /*
51 * If we delay setting the security manager until after the service
52 * configuration file has been installed, then this test still
53 * functions properly, but the -Djava.security.debug output is
54 * lacking, so to ease debugging, we'll set it early-- at the cost
55 * of having to specify the policy even when running standalone.
56 */
57 TestLibrary.suggestSecurityManager(null);
58
59 ServiceConfiguration.installServiceConfigurationFile();
60
61 /*
62 * Execute use of RMIClassLoader within an AccessControlContext
63 * that has a protection domain with no permissions, to make sure
64 * that RMIClassLoader can still properly initialize itself.
65 */
66 CodeSource codesource = new CodeSource(null, (Certificate[]) null);
67 Permissions perms = null;
68 ProtectionDomain pd = new ProtectionDomain(codesource, perms);
69 AccessControlContext acc =
70 new AccessControlContext(new ProtectionDomain[] { pd });
71
72 java.security.AccessController.doPrivileged(
73 new java.security.PrivilegedExceptionAction() {
74 public Object run() throws Exception {
75 TestProvider.exerciseTestProvider(
76 TestProvider2.loadClassReturn,
77 TestProvider2.loadProxyClassReturn,
78 TestProvider2.getClassLoaderReturn,
79 TestProvider2.getClassAnnotationReturn,
80 TestProvider2.invocations);
81 return null;
82 }
83 }, acc);
84 }
85}