169N/A/*
2362N/A * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A * @bug 4465315
0N/A * @summary The RMI runtime's server-side DGC implementation object should
0N/A * not be exported with the arbitrary access control context that was in
0N/A * effect when it gets lazily created. For example, calls to it should not
0N/A * fail due to the "accept" SocketPermission check simply because of the
0N/A * access control context that it was exported with.
0N/A * @author Peter Jones
0N/A *
0N/A * @library ../../testlibrary
5551N/A * @build TestLibrary DGCImplInsulation_Stub
0N/A * @run main/othervm/policy=security.policy DGCImplInsulation
0N/A */
0N/A
0N/Aimport java.lang.ref.Reference;
0N/Aimport java.lang.ref.ReferenceQueue;
0N/Aimport java.lang.ref.WeakReference;
0N/Aimport java.net.SocketPermission;
0N/Aimport java.rmi.MarshalledObject;
0N/Aimport java.rmi.Remote;
0N/Aimport java.rmi.server.UnicastRemoteObject;
0N/Aimport java.security.AccessControlContext;
0N/Aimport java.security.CodeSource;
0N/Aimport java.security.Permissions;
0N/Aimport java.security.PrivilegedExceptionAction;
0N/Aimport java.security.ProtectionDomain;
0N/Aimport java.security.cert.Certificate;
0N/A
0N/Apublic class DGCImplInsulation implements java.rmi.Remote {
0N/A
0N/A private static final long TIMEOUT = 5000;
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
169N/A TestLibrary.suggestSecurityManager(null);
0N/A
169N/A Permissions perms = new Permissions();
169N/A perms.add(new SocketPermission("*:1024-", "listen"));
169N/A AccessControlContext acc =
169N/A new AccessControlContext(new ProtectionDomain[] {
169N/A new ProtectionDomain(
169N/A new CodeSource(null, (Certificate[]) null), perms) });
0N/A
169N/A Remote impl = new DGCImplInsulation();;
0N/A
169N/A try {
169N/A Remote stub = (Remote) java.security.AccessController.doPrivileged(
169N/A new ExportAction(impl));
169N/A System.err.println("exported remote object; local stub: " + stub);
0N/A
169N/A MarshalledObject mobj = new MarshalledObject(stub);
169N/A stub = (Remote) mobj.get();
169N/A System.err.println("marshalled/unmarshalled stub: " + stub);
0N/A
169N/A ReferenceQueue refQueue = new ReferenceQueue();
169N/A Reference weakRef = new WeakReference(impl, refQueue);
169N/A impl = null;
169N/A System.gc();
169N/A if (refQueue.remove(TIMEOUT) == weakRef) {
169N/A throw new RuntimeException(
169N/A "TEST FAILED: remote object garbage collected");
169N/A } else {
169N/A System.err.println("TEST PASSED");
169N/A stub = null;
169N/A System.gc();
169N/A Thread.sleep(2000);
169N/A System.gc();
169N/A }
169N/A } finally {
169N/A try {
169N/A UnicastRemoteObject.unexportObject(impl, true);
169N/A } catch (Exception e) {
169N/A }
169N/A }
0N/A }
0N/A
0N/A private static class ExportAction implements PrivilegedExceptionAction {
169N/A private final Remote impl;
169N/A ExportAction(Remote impl) {
169N/A this.impl = impl;
169N/A }
169N/A public Object run() throws Exception {
169N/A return UnicastRemoteObject.exportObject(impl);
169N/A }
0N/A }
0N/A}