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