8001040: Rework RMI model
authorsmarks
Wed, 27 Feb 2013 14:17:05 -0800
changeset 16872 f5a07dbe9b1a
parent 16871 f8cfd245e458
child 16873 fb95bea093ea
8001040: Rework RMI model Reviewed-by: alanb, ahgross, coffeys, dmocek
jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java
jdk/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java
jdk/test/java/rmi/registry/readTest/readTest.sh
jdk/test/java/rmi/server/RMIClassLoader/downloadArrayClass/DownloadArrayClass.java
jdk/test/java/rmi/server/RMIClassLoader/downloadArrayClass/security.policy
jdk/test/java/rmi/server/RMIClassLoader/loadProxyClasses/LoadProxyClasses.java
jdk/test/java/rmi/server/RMIClassLoader/useCodebaseOnlyDefault/UseCodebaseOnlyDefault.java
jdk/test/java/rmi/testlibrary/RMID.java
--- a/jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java	Tue Feb 26 11:12:40 2013 -0800
+++ b/jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java	Wed Feb 27 14:17:05 2013 -0800
@@ -55,13 +55,19 @@
 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
--- a/jdk/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java	Tue Feb 26 11:12:40 2013 -0800
+++ b/jdk/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java	Wed Feb 27 14:17:05 2013 -0800
@@ -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.*;
--- a/jdk/test/java/rmi/registry/readTest/readTest.sh	Tue Feb 26 11:12:40 2013 -0800
+++ b/jdk/test/java/rmi/registry/readTest/readTest.sh	Wed Feb 27 14:17:05 2013 -0800
@@ -61,7 +61,8 @@
 #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
--- a/jdk/test/java/rmi/server/RMIClassLoader/downloadArrayClass/DownloadArrayClass.java	Tue Feb 26 11:12:40 2013 -0800
+++ b/jdk/test/java/rmi/server/RMIClassLoader/downloadArrayClass/DownloadArrayClass.java	Wed Feb 27 14:17:05 2013 -0800
@@ -64,6 +64,10 @@
             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
--- a/jdk/test/java/rmi/server/RMIClassLoader/downloadArrayClass/security.policy	Tue Feb 26 11:12:40 2013 -0800
+++ b/jdk/test/java/rmi/server/RMIClassLoader/downloadArrayClass/security.policy	Wed Feb 27 14:17:05 2013 -0800
@@ -7,6 +7,8 @@
 };
 
 grant {
+    permission java.util.PropertyPermission
+        "java.rmi.server.codebase", "read,write";
 
     // permissions needed to move classes into separate codebase directories
     permission java.io.FilePermission
--- a/jdk/test/java/rmi/server/RMIClassLoader/loadProxyClasses/LoadProxyClasses.java	Tue Feb 26 11:12:40 2013 -0800
+++ b/jdk/test/java/rmi/server/RMIClassLoader/loadProxyClasses/LoadProxyClasses.java	Wed Feb 27 14:17:05 2013 -0800
@@ -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;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/rmi/server/RMIClassLoader/useCodebaseOnlyDefault/UseCodebaseOnlyDefault.java	Wed Feb 27 14:17:05 2013 -0800
@@ -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");
+    }
+}
--- a/jdk/test/java/rmi/testlibrary/RMID.java	Tue Feb 26 11:12:40 2013 -0800
+++ b/jdk/test/java/rmi/testlibrary/RMID.java	Wed Feb 27 14:17:05 2013 -0800
@@ -108,6 +108,9 @@
         if (!TestParams.testClasses.equals("")) {
             args += " -C-Dtest.classes=" + TestParams.testClasses;
         }
+
+        args += " -C-Djava.rmi.server.useCodebaseOnly=false ";
+
         args += " " + getCodeCoverageArgs();
         return args;
     }