提交 52ea57dc 编写于 作者: S smarks

8001040: Rework RMI model

Reviewed-by: alanb, ahgross, coffeys, dmocek
上级 7d6df670
......@@ -55,13 +55,19 @@ import java.rmi.server.RMIClassLoader;
public class MarshalInputStream extends ObjectInputStream {
/**
* value of "java.rmi.server.useCodebaseOnly" property,
* Value of "java.rmi.server.useCodebaseOnly" property,
* as cached at class initialization time.
*
* The default value is true. That is, the value is true
* if the property is absent or is not equal to "false".
* The value is only false when the property is present
* and is equal to "false".
*/
private static final boolean useCodebaseOnlyProperty =
java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"java.rmi.server.useCodebaseOnly")).booleanValue();
! java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(
"java.rmi.server.useCodebaseOnly", "true"))
.equalsIgnoreCase("false");
/** table to hold sun classes to which access is explicitly permitted */
protected static Map<String, Class<?>> permittedSunClasses
......
......@@ -31,7 +31,8 @@
*
* @library ../../testlibrary
* @build TestLibrary Dummy
* @run main/othervm/policy=security.policy ClassPathCodebase
* @run main/othervm/policy=security.policy
* -Djava.rmi.server.useCodebaseOnly=false ClassPathCodebase
*/
import java.io.*;
......
......@@ -61,7 +61,8 @@ RMIREG_OUT=rmi.out
#start rmiregistry without any local classes on classpath
cd rmi_tmp
# NOTE: This RMI Registry port must match TestLibrary.READTEST_REGISTRY_PORT
${TESTJAVA}${FS}bin${FS}rmiregistry ${TESTTOOLVMOPTS} 64005 > ..${FS}${RMIREG_OUT} 2>&1 &
${TESTJAVA}${FS}bin${FS}rmiregistry -J-Djava.rmi.server.useCodebaseOnly=false \
${TESTTOOLVMOPTS} 64005 > ..${FS}${RMIREG_OUT} 2>&1 &
RMIREG_PID=$!
# allow some time to start
sleep 3
......
......@@ -64,6 +64,10 @@ public class DownloadArrayClass
TestLibrary.bomb(e);
}
System.err.println("Setting codebase property to: " + remoteCodebase);
System.setProperty("java.rmi.server.codebase",
remoteCodebase.toString());
/*
* Load Foo from a non-RMI class loader so that it won't be already
* loaded by an RMI class loader in this VM (for whatever that's
......
......@@ -7,6 +7,8 @@ grant codeBase "file:${java.home}/lib/ext/*" {
};
grant {
permission java.util.PropertyPermission
"java.rmi.server.codebase", "read,write";
// permissions needed to move classes into separate codebase directories
permission java.io.FilePermission
......
......@@ -32,7 +32,8 @@
* @library ../../../testlibrary
* @build TestLibrary FnnClass FnnUnmarshal NonpublicInterface
* NonpublicInterface1 PublicInterface PublicInterface1
* @run main/othervm/policy=security.policy LoadProxyClasses
* @run main/othervm/policy=security.policy
* -Djava.rmi.server.useCodebaseOnly=false LoadProxyClasses
*/
import java.rmi.server.RMIClassLoader;
......
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* 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.
*
* 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.
*/
/*
* @test
* @bug 8001040
* @summary Tests proper parsing and defaulting of the
* "java.rmi.server.useCodebaseOnly" property.
*
* @run main/othervm UseCodebaseOnlyDefault true
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=xyzzy UseCodebaseOnlyDefault true
* @run main/othervm -Djava.rmi.server.useCodebaseOnly UseCodebaseOnlyDefault true
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=true UseCodebaseOnlyDefault true
* @run main/othervm -Djava.rmi.server.useCodebaseOnly=false UseCodebaseOnlyDefault false
*/
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import sun.rmi.server.MarshalInputStream;
/**
* usage: UseCodebaseOnlyDefault expected
*
* 'expected' is the expected value of useCodebaseOnly, which
* must be "true" or "false".
*/
public class UseCodebaseOnlyDefault {
static final String USAGE = "usage: UseCodebaseOnlyDefault boolean";
static final String PROPNAME = "java.rmi.server.useCodebaseOnly";
/**
* Gets the actual useCodebaseOnly value by creating an instance
* of MarshalInputStream and reflecting on the useCodebaseOnly field.
*/
static boolean getActualValue() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject("foo");
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
MarshalInputStream mis = new MarshalInputStream(bais);
Field f = MarshalInputStream.class.getDeclaredField("useCodebaseOnly");
f.setAccessible(true);
return f.getBoolean(mis);
}
public static void main(String[] args) throws Exception {
if (args.length != 1) {
throw new IllegalArgumentException(USAGE);
}
boolean expected;
if (args[0].equals("true")) {
expected = true;
} else if (args[0].equals("false")) {
expected = false;
} else {
throw new IllegalArgumentException(USAGE);
}
System.out.println("expected = " + expected);
String prop = System.getProperty(PROPNAME);
System.out.print("Property " + PROPNAME);
if (prop == null) {
System.out.println(" is not set");
} else {
System.out.println(" = '" + prop + "'");
}
boolean actual = getActualValue();
System.out.println("actual = " + actual);
if (expected != actual)
throw new AssertionError("actual does not match expected value");
}
}
......@@ -108,6 +108,9 @@ public class RMID extends JavaVM {
if (!TestParams.testClasses.equals("")) {
args += " -C-Dtest.classes=" + TestParams.testClasses;
}
args += " -C-Djava.rmi.server.useCodebaseOnly=false ";
args += " " + getCodeCoverageArgs();
return args;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册