jdk/src/share/classes/sun/rmi/server/MarshalInputStream.java
author robm
Wed, 11 Apr 2012 17:47:56 -0700
changeset 13041 8477cb6992be
parent 12040 558b0e0d5910
child 14342 8435a30053c1
permissions -rw-r--r--
7143606: File.createTempFile should be improved for temporary files created by the platform. Reviewed-by: sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 1996, 2008, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
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
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10799
diff changeset
    68
        = new HashMap<>(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
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10799
diff changeset
    75
        = new HashMap<>(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
     * Create a new MarshalInputStream object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public MarshalInputStream(InputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        throws IOException, StreamCorruptedException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Returns a callback previously registered via the setDoneCallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * method with given key, or null if no callback has yet been registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * with that key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public Runnable getDoneCallback(Object key) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   127
        return doneCallbacks.get(key);                 // not thread-safe
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Registers a callback to make when this stream's done() method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * invoked, along with a key for retrieving the same callback instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * subsequently from the getDoneCallback method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void setDoneCallback(Object key, Runnable callback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        //assert(!doneCallbacks.contains(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        doneCallbacks.put(key, callback);               // not thread-safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Indicates that the user of this MarshalInputStream is done reading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * objects from it, so all callbacks registered with the setDoneCallback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * method should now be (synchronously) executed.  When this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * returns, there are no more callbacks registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * This method is implicitly invoked by close() before it delegates to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * the superclass's close method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public void done() {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   150
        Iterator<Runnable> iter = doneCallbacks.values().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        while (iter.hasNext()) {                        // not thread-safe
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   152
            Runnable callback = iter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            callback.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        doneCallbacks.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Closes this stream, implicitly invoking done() first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        super.close();
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
     * resolveClass is extended to acquire (if present) the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * from which to load the specified class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * It will find, load, and return the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10799
diff changeset
   171
    protected Class<?> resolveClass(ObjectStreamClass classDesc)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * Always read annotation written by MarshalOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         * describing where to load class from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        Object annotation = readLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        String className = classDesc.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * Unless we were told to skip this consideration, choose the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         * "default loader" to simulate the default ObjectInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * resolveClass mechanism (that is, choose the first non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * loader on the execution stack) to maximize the likelihood of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * type compatibility with calling code.  (This consideration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * is skipped during server parameter unmarshalling using the 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * stub protocol, because there would never be a non-null class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * loader on the stack in that situation anyway.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        ClassLoader defaultLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            skipDefaultResolveClass ? null : latestUserDefinedLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * If the "java.rmi.server.useCodebaseOnly" property was true or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * useCodebaseOnly() was called or the annotation is not a String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * load from the local loader using the "java.rmi.server.codebase"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * URL.  Otherwise, load from a loader using the codebase URL in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         * the annotation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        String codebase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (!useCodebaseOnly && annotation instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            codebase = (String) annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return RMIClassLoader.loadClass(codebase, className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                            defaultLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (AccessControlException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return checkSunClass(className, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
             * Fix for 4442373: delegate to ObjectInputStream.resolveClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
             * to resolve primitive classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                if (Character.isLowerCase(className.charAt(0)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    className.indexOf('.') == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    return super.resolveClass(classDesc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            } catch (ClassNotFoundException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * resolveProxyClass is extended to acquire (if present) the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * to determine the class loader to define the proxy class in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10799
diff changeset
   233
    protected Class<?> resolveProxyClass(String[] interfaces)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * Always read annotation written by MarshalOutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        Object annotation = readLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        ClassLoader defaultLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            skipDefaultResolveClass ? null : latestUserDefinedLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        String codebase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (!useCodebaseOnly && annotation instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            codebase = (String) annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return RMIClassLoader.loadProxyClass(codebase, interfaces,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                             defaultLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Returns the first non-null class loader up the execution stack, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * if only code from the null class loader is on the stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
10797
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 5506
diff changeset
   257
    private static ClassLoader latestUserDefinedLoader() {
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 5506
diff changeset
   258
        return sun.misc.VM.latestUserDefinedLoader();
f51518b30c84 7104209: Cleanup and remove librmi (native library)
chegar
parents: 5506
diff changeset
   259
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Fix for 4179055: Need to assist resolving sun stubs; resolve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * class locally if it is a "permitted" sun class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10799
diff changeset
   265
    private Class<?> checkSunClass(String className, AccessControlException e)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        throws AccessControlException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // ensure that we are giving out a stub for the correct reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        Permission perm = e.getPermission();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        String name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (perm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            name = perm.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   275
        Class<?> resolvedClass = permittedSunClasses.get(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        // if class not permitted, throw the SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if ((name == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            (resolvedClass == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            ((!name.equals("accessClassInPackage.sun.rmi.server")) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            (!name.equals("accessClassInPackage.sun.rmi.registry"))))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return resolvedClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Return the location for the class in the stream.  This method can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * be overridden by subclasses that store this annotation somewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * else than as the next object in the stream, as is done by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    protected Object readLocation()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Set a flag to indicate that the superclass's default resolveClass()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * implementation should not be invoked by our resolveClass().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    void skipDefaultResolveClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        skipDefaultResolveClass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Disable code downloading except from the URL specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * "java.rmi.server.codebase" property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    void useCodebaseOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        useCodebaseOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}