From 52ea57dccca9e3c78f5628ac26c1d13aa9134b82 Mon Sep 17 00:00:00 2001 From: smarks Date: Wed, 27 Feb 2013 14:17:05 -0800 Subject: [PATCH] 8001040: Rework RMI model Reviewed-by: alanb, ahgross, coffeys, dmocek --- .../sun/rmi/server/MarshalInputStream.java | 14 ++- .../classPathCodebase/ClassPathCodebase.java | 3 +- test/java/rmi/registry/readTest/readTest.sh | 3 +- .../DownloadArrayClass.java | 4 + .../downloadArrayClass/security.policy | 2 + .../loadProxyClasses/LoadProxyClasses.java | 3 +- .../UseCodebaseOnlyDefault.java | 100 ++++++++++++++++++ test/java/rmi/testlibrary/RMID.java | 3 + 8 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 test/java/rmi/server/RMIClassLoader/useCodebaseOnlyDefault/UseCodebaseOnlyDefault.java diff --git a/src/share/classes/sun/rmi/server/MarshalInputStream.java b/src/share/classes/sun/rmi/server/MarshalInputStream.java index e24a8fb3f..4f67941a5 100644 --- a/src/share/classes/sun/rmi/server/MarshalInputStream.java +++ b/src/share/classes/sun/rmi/server/MarshalInputStream.java @@ -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> permittedSunClasses diff --git a/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java b/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java index 99ac5f091..b4be73762 100644 --- a/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java +++ b/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java @@ -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.*; diff --git a/test/java/rmi/registry/readTest/readTest.sh b/test/java/rmi/registry/readTest/readTest.sh index dad6847f3..bb37f65b4 100644 --- a/test/java/rmi/registry/readTest/readTest.sh +++ b/test/java/rmi/registry/readTest/readTest.sh @@ -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 diff --git a/test/java/rmi/server/RMIClassLoader/downloadArrayClass/DownloadArrayClass.java b/test/java/rmi/server/RMIClassLoader/downloadArrayClass/DownloadArrayClass.java index 9df187ab3..c0a946970 100644 --- a/test/java/rmi/server/RMIClassLoader/downloadArrayClass/DownloadArrayClass.java +++ b/test/java/rmi/server/RMIClassLoader/downloadArrayClass/DownloadArrayClass.java @@ -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 diff --git a/test/java/rmi/server/RMIClassLoader/downloadArrayClass/security.policy b/test/java/rmi/server/RMIClassLoader/downloadArrayClass/security.policy index 706a3cdfc..ac4ce0207 100644 --- a/test/java/rmi/server/RMIClassLoader/downloadArrayClass/security.policy +++ b/test/java/rmi/server/RMIClassLoader/downloadArrayClass/security.policy @@ -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 diff --git a/test/java/rmi/server/RMIClassLoader/loadProxyClasses/LoadProxyClasses.java b/test/java/rmi/server/RMIClassLoader/loadProxyClasses/LoadProxyClasses.java index 6d29cb246..b5bfcac63 100644 --- a/test/java/rmi/server/RMIClassLoader/loadProxyClasses/LoadProxyClasses.java +++ b/test/java/rmi/server/RMIClassLoader/loadProxyClasses/LoadProxyClasses.java @@ -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; diff --git a/test/java/rmi/server/RMIClassLoader/useCodebaseOnlyDefault/UseCodebaseOnlyDefault.java b/test/java/rmi/server/RMIClassLoader/useCodebaseOnlyDefault/UseCodebaseOnlyDefault.java new file mode 100644 index 000000000..80dfd7d70 --- /dev/null +++ b/test/java/rmi/server/RMIClassLoader/useCodebaseOnlyDefault/UseCodebaseOnlyDefault.java @@ -0,0 +1,100 @@ +/* + * 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"); + } +} diff --git a/test/java/rmi/testlibrary/RMID.java b/test/java/rmi/testlibrary/RMID.java index 8b0f3e26b..f528b2058 100644 --- a/test/java/rmi/testlibrary/RMID.java +++ b/test/java/rmi/testlibrary/RMID.java @@ -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; } -- GitLab