Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/dgc/dgcImplInsulation/DGCImplInsulation.java
38828 views
/*1* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 446531525* @summary The RMI runtime's server-side DGC implementation object should26* not be exported with the arbitrary access control context that was in27* effect when it gets lazily created. For example, calls to it should not28* fail due to the "accept" SocketPermission check simply because of the29* access control context that it was exported with.30* @author Peter Jones31*32* @library ../../testlibrary33* @build TestLibrary DGCImplInsulation_Stub34* @run main/othervm/policy=security.policy DGCImplInsulation35*/3637import java.lang.ref.Reference;38import java.lang.ref.ReferenceQueue;39import java.lang.ref.WeakReference;40import java.net.SocketPermission;41import java.rmi.MarshalledObject;42import java.rmi.Remote;43import java.rmi.server.UnicastRemoteObject;44import java.security.AccessControlContext;45import java.security.CodeSource;46import java.security.Permissions;47import java.security.PrivilegedExceptionAction;48import java.security.ProtectionDomain;49import java.security.cert.Certificate;5051public class DGCImplInsulation implements java.rmi.Remote {5253private static final long TIMEOUT = 5000;5455public static void main(String[] args) throws Exception {5657TestLibrary.suggestSecurityManager(null);5859Permissions perms = new Permissions();60perms.add(new SocketPermission("*:1024-", "listen"));61AccessControlContext acc =62new AccessControlContext(new ProtectionDomain[] {63new ProtectionDomain(64new CodeSource(null, (Certificate[]) null), perms) });6566Remote impl = new DGCImplInsulation();;6768try {69Remote stub = (Remote) java.security.AccessController.doPrivileged(70new ExportAction(impl));71System.err.println("exported remote object; local stub: " + stub);7273MarshalledObject mobj = new MarshalledObject(stub);74stub = (Remote) mobj.get();75System.err.println("marshalled/unmarshalled stub: " + stub);7677ReferenceQueue refQueue = new ReferenceQueue();78Reference weakRef = new WeakReference(impl, refQueue);79impl = null;80System.gc();81if (refQueue.remove(TIMEOUT) == weakRef) {82throw new RuntimeException(83"TEST FAILED: remote object garbage collected");84} else {85System.err.println("TEST PASSED");86stub = null;87System.gc();88Thread.sleep(2000);89System.gc();90}91} finally {92try {93UnicastRemoteObject.unexportObject(impl, true);94} catch (Exception e) {95}96}97}9899private static class ExportAction implements PrivilegedExceptionAction {100private final Remote impl;101ExportAction(Remote impl) {102this.impl = impl;103}104public Object run() throws Exception {105return UnicastRemoteObject.exportObject(impl);106}107}108}109110111