1 /*
   2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4191926 4349670
  26  * @summary When the RMIClassLoader.loadClass() methods are invoked with a
  27  * codebase URL that the caller does not have permission to load from, but
  28  * with a class name that is accessible through the caller's context class
  29  * loader (such as in the boot or system class paths, for an application),
  30  * the operations should succeed, instead of throwing a
  31  * ClassNotFoundException (wrapping a SecurityExcpetion) because the caller
  32  * does not have permission to access the codebase URL.
  33  * @author Peter Jones
  34  *
  35  * @library ../../../testlibrary
  36  * @modules java.rmi/sun.rmi.registry
  37  *          java.rmi/sun.rmi.server
  38  *          java.rmi/sun.rmi.transport
  39  *          java.rmi/sun.rmi.transport.tcp
  40  * @build TestLibrary Foo
  41  * @run main/othervm DelegateBeforePermissionCheck
  42  */
  43 
  44 import java.net.*;
  45 import java.rmi.*;
  46 import java.rmi.server.*;
  47 
  48 public class DelegateBeforePermissionCheck {
  49 
  50     private final static String tabooCodebase = "http://taboo/codebase/";
  51 
  52     public static void main(String[] args) {
  53 
  54         System.err.println("\nRegression test for bug 4191926\n");
  55 
  56         TestLibrary.suggestSecurityManager(null);
  57 
  58         try {
  59             String localClassName = Foo.class.getName();
  60             System.err.println("Attempting to load local class \"" +
  61                 localClassName + "\" from codebase " + tabooCodebase);
  62             Class cl = RMIClassLoader.loadClass(
  63                 tabooCodebase, localClassName);
  64             System.err.println("TEST PASSED: loaded " + cl + " locally");
  65 
  66         } catch (Exception e) {
  67             TestLibrary.bomb(e);
  68         }
  69     }
  70 }