jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 51 6fe31bc95bbc
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 51
diff changeset
     2
 * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.rmi.server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectStreamClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.StreamCorruptedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.AccessControlException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.server.RMIClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * MarshalInputStream is an extension of ObjectInputStream.  When resolving
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * a class, it reads an object from the stream written by a corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * MarshalOutputStream.  If the class to be resolved is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * locally, from the first class loader on the execution stack, or from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * context class loader of the current thread, it will attempt to load the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * class from the location annotated by the sending MarshalOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * This location object must be a string representing a path of URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * A new MarshalInputStream should be created to deserialize remote objects or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * graphs containing remote objects.  Objects are created from the stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * using the ObjectInputStream.readObject method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author      Peter Jones
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class MarshalInputStream extends ObjectInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * value of "java.rmi.server.useCodebaseOnly" property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * as cached at class initialization time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final boolean useCodebaseOnlyProperty =
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    62
        java.security.AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            new sun.security.action.GetBooleanAction(
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    64
                "java.rmi.server.useCodebaseOnly")).booleanValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /** table to hold sun classes to which access is explicitly permitted */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    67
    protected static Map<String, Class<?>> permittedSunClasses
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    68
        = new HashMap<String, Class<?>>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /** if true, don't try superclass first in resolveClass() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private boolean skipDefaultResolveClass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /** callbacks to make when done() called: maps Object to Runnable */
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    74
    private final Map<Object, Runnable> doneCallbacks
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    75
        = new HashMap<Object, Runnable>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * if true, load classes (if not available locally) only from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * URL specified by the "java.rmi.server.codebase" property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private boolean useCodebaseOnly = useCodebaseOnlyProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Fix for 4179055: The remote object services inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * activation daemon use stubs that are in the package
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * sun.rmi.server.  Classes for these stubs should be loaded from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * the classpath by RMI system code and not by the normal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * unmarshalling process as applications should not need to have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * permission to access the sun implementation classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Note: this fix should be redone when API changes may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * integrated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * During parameter unmarshalling RMI needs to explicitly permit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * access to three sun.* stub classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            String system =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                "sun.rmi.server.Activation$ActivationSystemImpl_Stub";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            String registry = "sun.rmi.registry.RegistryImpl_Stub";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            permittedSunClasses.put(system, Class.forName(system));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            permittedSunClasses.put(registry, Class.forName(registry));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throw new NoClassDefFoundError("Missing system class: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                           e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Load the "rmi" native library.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            new sun.security.action.LoadLibraryAction("rmi"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Create a new MarshalInputStream object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public MarshalInputStream(InputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        throws IOException, StreamCorruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns a callback previously registered via the setDoneCallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * method with given key, or null if no callback has yet been registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * with that key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public Runnable getDoneCallback(Object key) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   135
        return doneCallbacks.get(key);                 // not thread-safe
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Registers a callback to make when this stream's done() method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * invoked, along with a key for retrieving the same callback instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * subsequently from the getDoneCallback method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void setDoneCallback(Object key, Runnable callback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        //assert(!doneCallbacks.contains(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        doneCallbacks.put(key, callback);               // not thread-safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Indicates that the user of this MarshalInputStream is done reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * objects from it, so all callbacks registered with the setDoneCallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * method should now be (synchronously) executed.  When this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * returns, there are no more callbacks registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * This method is implicitly invoked by close() before it delegates to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * the superclass's close method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void done() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   158
        Iterator<Runnable> iter = doneCallbacks.values().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        while (iter.hasNext()) {                        // not thread-safe
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   160
            Runnable callback = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            callback.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        doneCallbacks.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Closes this stream, implicitly invoking done() first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * resolveClass is extended to acquire (if present) the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * from which to load the specified class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * It will find, load, and return the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    protected Class resolveClass(ObjectStreamClass classDesc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * Always read annotation written by MarshalOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * describing where to load class from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Object annotation = readLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        String className = classDesc.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * Unless we were told to skip this consideration, choose the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * "default loader" to simulate the default ObjectInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * resolveClass mechanism (that is, choose the first non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * loader on the execution stack) to maximize the likelihood of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * type compatibility with calling code.  (This consideration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * is skipped during server parameter unmarshalling using the 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * stub protocol, because there would never be a non-null class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * loader on the stack in that situation anyway.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        ClassLoader defaultLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            skipDefaultResolveClass ? null : latestUserDefinedLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * If the "java.rmi.server.useCodebaseOnly" property was true or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         * useCodebaseOnly() was called or the annotation is not a String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
         * load from the local loader using the "java.rmi.server.codebase"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         * URL.  Otherwise, load from a loader using the codebase URL in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         * the annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        String codebase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (!useCodebaseOnly && annotation instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            codebase = (String) annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return RMIClassLoader.loadClass(codebase, className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                            defaultLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        } catch (AccessControlException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return checkSunClass(className, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
             * Fix for 4442373: delegate to ObjectInputStream.resolveClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
             * to resolve primitive classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                if (Character.isLowerCase(className.charAt(0)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    className.indexOf('.') == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    return super.resolveClass(classDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            } catch (ClassNotFoundException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * resolveProxyClass is extended to acquire (if present) the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * to determine the class loader to define the proxy class in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    protected Class resolveProxyClass(String[] interfaces)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         * Always read annotation written by MarshalOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        Object annotation = readLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        ClassLoader defaultLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            skipDefaultResolveClass ? null : latestUserDefinedLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        String codebase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        if (!useCodebaseOnly && annotation instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            codebase = (String) annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return RMIClassLoader.loadProxyClass(codebase, interfaces,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                             defaultLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Returns the first non-null class loader up the execution stack, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * if only code from the null class loader is on the stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    private static native ClassLoader latestUserDefinedLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Fix for 4179055: Need to assist resolving sun stubs; resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * class locally if it is a "permitted" sun class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private Class checkSunClass(String className, AccessControlException e)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        throws AccessControlException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        // ensure that we are giving out a stub for the correct reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        Permission perm = e.getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        String name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (perm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            name = perm.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   281
        Class<?> resolvedClass = permittedSunClasses.get(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        // if class not permitted, throw the SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if ((name == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            (resolvedClass == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            ((!name.equals("accessClassInPackage.sun.rmi.server")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            (!name.equals("accessClassInPackage.sun.rmi.registry"))))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        return resolvedClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Return the location for the class in the stream.  This method can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * be overridden by subclasses that store this annotation somewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * else than as the next object in the stream, as is done by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    protected Object readLocation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Set a flag to indicate that the superclass's default resolveClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * implementation should not be invoked by our resolveClass().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    void skipDefaultResolveClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        skipDefaultResolveClass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Disable code downloading except from the URL specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * "java.rmi.server.codebase" property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    void useCodebaseOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        useCodebaseOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
}