src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java
author uvangapally
Mon, 25 Sep 2017 19:44:28 +0530
changeset 48576 b0ab05328879
parent 47216 71c04702a3d5
child 52427 3c6aa484536c
permissions -rw-r--r--
8186998: Improve JMX supportive features Summary: Improve JMX supportive features Reviewed-by: mchung, dfuchs, rriggs, hb, skoivu, rhalade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
     2
 * Copyright (c) 1996, 2017, 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.registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
    28
import java.io.ObjectInputFilter;
36670
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
    29
import java.nio.file.Path;
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
    30
import java.nio.file.Paths;
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
    31
import java.security.PrivilegedAction;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
    32
import java.security.Security;
36670
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
    33
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
36670
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
    36
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.ResourceBundle;
36670
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
    39
import java.io.File;
11039
4ee27839f531 7102369: remove java.rmi.server.codebase property parsing from registyimpl
coffeys
parents: 10914
diff changeset
    40
import java.io.FilePermission;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.rmi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.server.ObjID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.rmi.server.ServerNotActiveException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.registry.Registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.rmi.server.RMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.rmi.server.RMIServerSocketFactory;
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    49
import java.security.AccessControlContext;
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    50
import java.security.AccessController;
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    51
import java.security.CodeSource;
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    52
import java.security.Policy;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.security.PrivilegedActionException;
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    54
import java.security.PrivilegedExceptionAction;
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    55
import java.security.PermissionCollection;
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    56
import java.security.Permissions;
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
    57
import java.security.ProtectionDomain;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.text.MessageFormat;
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
    59
46160
c647e44ea1b9 8185346: Relax RMI Registry Serial Filter to allow arrays of any type
rriggs
parents: 45989
diff changeset
    60
import jdk.internal.misc.SharedSecrets;
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
    61
import sun.rmi.runtime.Log;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
    62
import sun.rmi.server.UnicastRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import sun.rmi.server.UnicastServerRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import sun.rmi.server.UnicastServerRef2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import sun.rmi.transport.LiveRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * A "registry" exists on every node that allows RMI connections to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * servers on that node.  The registry on a particular node contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * transient database that maps names to remote objects.  When the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * node boots, the registry database is empty.  The names stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * registry are pure and are not parsed.  A service storing itself in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * the registry may want to prefix its name of the service by a package
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * name (although not required), to reduce name collisions in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * The LocateRegistry class is used to obtain registry for different hosts.
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
    78
 * <p>
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
    79
 * The default RegistryImpl exported restricts access to clients on the local host
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
    80
 * for the methods {@link #bind}, {@link #rebind}, {@link #unbind} by checking
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
    81
 * the client host in the skeleton.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see java.rmi.registry.LocateRegistry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
public class RegistryImpl extends java.rmi.server.RemoteServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        implements Registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /* indicate compatibility with JDK 1.1.x version of class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private static final long serialVersionUID = 4666870661827494597L;
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    91
    private Hashtable<String, Remote> bindings
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 11039
diff changeset
    92
        = new Hashtable<>(101);
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
    93
    private static Hashtable<InetAddress, InetAddress> allowedAccessCache
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 11039
diff changeset
    94
        = new Hashtable<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static RegistryImpl registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private static ObjID id = new ObjID(ObjID.REGISTRY_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static ResourceBundle resources = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   101
     * Property name of the RMI Registry serial filter to augment
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   102
     * the built-in list of allowed types.
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   103
     * Setting the property in the {@code conf/security/java.security} file
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   104
     * will enable the augmented filter.
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   105
     */
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   106
    private static final String REGISTRY_FILTER_PROPNAME = "sun.rmi.registry.registryFilter";
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   107
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   108
    /** Registry max depth of remote invocations. **/
45436
152ed642e379 8180582: The bind to rmiregistry is rejected by registryFilter even though registryFilter is set
rriggs
parents: 43211
diff changeset
   109
    private static final int REGISTRY_MAX_DEPTH = 20;
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   110
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   111
    /** Registry maximum array size in remote invocations. **/
46160
c647e44ea1b9 8185346: Relax RMI Registry Serial Filter to allow arrays of any type
rriggs
parents: 45989
diff changeset
   112
    private static final int REGISTRY_MAX_ARRAY_SIZE = 1_000_000;
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   113
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   114
    /**
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   115
     * The registryFilter created from the value of the {@code "sun.rmi.registry.registryFilter"}
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   116
     * property.
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   117
     */
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   118
    private static final ObjectInputFilter registryFilter =
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   119
            AccessController.doPrivileged((PrivilegedAction<ObjectInputFilter>)RegistryImpl::initRegistryFilter);
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   120
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   121
    /**
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   122
     * Initialize the registryFilter from the security properties or system property; if any
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   123
     * @return an ObjectInputFilter, or null
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   124
     */
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   125
    @SuppressWarnings("deprecation")
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   126
    private static ObjectInputFilter initRegistryFilter() {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   127
        ObjectInputFilter filter = null;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   128
        String props = System.getProperty(REGISTRY_FILTER_PROPNAME);
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   129
        if (props == null) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   130
            props = Security.getProperty(REGISTRY_FILTER_PROPNAME);
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   131
        }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   132
        if (props != null) {
46160
c647e44ea1b9 8185346: Relax RMI Registry Serial Filter to allow arrays of any type
rriggs
parents: 45989
diff changeset
   133
            filter = SharedSecrets.getJavaObjectInputFilterAccess().createFilter2(props);
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   134
            Log regLog = Log.getLog("sun.rmi.registry", "registry", -1);
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   135
            if (regLog.isLoggable(Log.BRIEF)) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   136
                regLog.log(Log.BRIEF, "registryFilter = " + filter);
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   137
            }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   138
        }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   139
        return filter;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   140
    }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   141
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   142
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Construct a new RegistryImpl on the specified port with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * given custom socket factory pair.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public RegistryImpl(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        RMIServerSocketFactory ssf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   151
        this(port, csf, ssf, RegistryImpl::registryFilter);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   152
    }
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   153
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   154
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   155
    /**
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   156
     * Construct a new RegistryImpl on the specified port with the
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   157
     * given custom socket factory pair and ObjectInputFilter.
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   158
     */
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   159
    public RegistryImpl(int port,
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   160
                        RMIClientSocketFactory csf,
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   161
                        RMIServerSocketFactory ssf,
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   162
                        ObjectInputFilter serialFilter)
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   163
        throws RemoteException
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   164
    {
22339
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   165
        if (port == Registry.REGISTRY_PORT && System.getSecurityManager() != null) {
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   166
            // grant permission for default port only.
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   167
            try {
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   168
                AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   169
                    public Void run() throws RemoteException {
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   170
                        LiveRef lref = new LiveRef(id, port, csf, ssf);
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   171
                        setup(new UnicastServerRef2(lref, serialFilter));
22339
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   172
                        return null;
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   173
                    }
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   174
                }, null, new SocketPermission("localhost:"+port, "listen,accept"));
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   175
            } catch (PrivilegedActionException pae) {
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   176
                throw (RemoteException)pae.getException();
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   177
            }
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   178
        } else {
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   179
            LiveRef lref = new LiveRef(id, port, csf, ssf);
48576
b0ab05328879 8186998: Improve JMX supportive features
uvangapally
parents: 47216
diff changeset
   180
            setup(new UnicastServerRef2(lref, serialFilter));
22339
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   181
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Construct a new RegistryImpl on the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public RegistryImpl(int port)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    {
22341
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   190
        if (port == Registry.REGISTRY_PORT && System.getSecurityManager() != null) {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   191
            // grant permission for default port only.
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   192
            try {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   193
                AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   194
                    public Void run() throws RemoteException {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   195
                        LiveRef lref = new LiveRef(id, port);
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   196
                        setup(new UnicastServerRef(lref, RegistryImpl::registryFilter));
22341
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   197
                        return null;
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   198
                    }
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   199
                }, null, new SocketPermission("localhost:"+port, "listen,accept"));
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   200
            } catch (PrivilegedActionException pae) {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   201
                throw (RemoteException)pae.getException();
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   202
            }
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   203
        } else {
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   204
            LiveRef lref = new LiveRef(id, port);
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   205
            setup(new UnicastServerRef(lref, RegistryImpl::registryFilter));
22341
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   206
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Create the export the object using the parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <code>uref</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private void setup(UnicastServerRef uref)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        /* Server ref must be created and assigned before remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * object 'this' can be exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        ref = uref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        uref.exportObject(this, null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Returns the remote object for specified name in the registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @exception RemoteException If remote operation failed.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 28053
diff changeset
   226
     * @exception NotBoundException If name is not currently bound.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public Remote lookup(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        throws RemoteException, NotBoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        synchronized (bindings) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   232
            Remote obj = bindings.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if (obj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                throw new NotBoundException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Binds the name to the specified remote object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @exception RemoteException If remote operation failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @exception AlreadyBoundException If name is already bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public void bind(String name, Remote obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        throws RemoteException, AlreadyBoundException, AccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   247
        // The access check preventing remote access is done in the skeleton
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   248
        // and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        synchronized (bindings) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   250
            Remote curr = bindings.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if (curr != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                throw new AlreadyBoundException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            bindings.put(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Unbind the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @exception RemoteException If remote operation failed.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 28053
diff changeset
   260
     * @exception NotBoundException If name is not currently bound.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void unbind(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        throws RemoteException, NotBoundException, AccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   265
        // The access check preventing remote access is done in the skeleton
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   266
        // and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        synchronized (bindings) {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   268
            Remote obj = bindings.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (obj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                throw new NotBoundException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            bindings.remove(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Rebind the name to a new object, replaces any existing binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @exception RemoteException If remote operation failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public void rebind(String name, Remote obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        throws RemoteException, AccessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   282
        // The access check preventing remote access is done in the skeleton
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   283
        // and is not applicable to local access.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        bindings.put(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Returns an enumeration of the names in the registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @exception RemoteException If remote operation failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public String[] list()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        String[] names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        synchronized (bindings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            int i = bindings.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            names = new String[i];
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 11039
diff changeset
   298
            Enumeration<String> enum_ = bindings.keys();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            while ((--i) >= 0)
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 11039
diff changeset
   300
                names[i] = enum_.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Check that the caller has access to perform indicated operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * The client must be on same the same host as this server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public static void checkAccess(String op) throws AccessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
             * Get client host that this registry operation was made from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            final String clientHostName = getClientHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            InetAddress clientHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            try {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   319
                clientHost = java.security.AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   320
                    new java.security.PrivilegedExceptionAction<InetAddress>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   321
                        public InetAddress run()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                            throws java.net.UnknownHostException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                            return InetAddress.getByName(clientHostName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            } catch (PrivilegedActionException pae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                throw (java.net.UnknownHostException) pae.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // if client not yet seen, make sure client allowed access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (allowedAccessCache.get(clientHost) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                if (clientHost.isAnyLocalAddress()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    throw new AccessException(
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   336
                        op + " disallowed; origin unknown");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    final InetAddress finalClientHost = clientHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    java.security.AccessController.doPrivileged(
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   343
                        new java.security.PrivilegedExceptionAction<Void>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   344
                            public Void run() throws java.io.IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                 * if a ServerSocket can be bound to the client's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                 * address then that address must be local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                (new ServerSocket(0, 10, finalClientHost)).close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                allowedAccessCache.put(finalClientHost,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                                       finalClientHost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                } catch (PrivilegedActionException pae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    // must have been an IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    throw new AccessException(
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   359
                        op + " disallowed; origin " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        clientHost + " is non-local host");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        } catch (ServerNotActiveException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
             * Local call from this VM: allow access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        } catch (java.net.UnknownHostException ex) {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45436
diff changeset
   368
            throw new AccessException(op + " disallowed; origin is unknown host");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public static ObjID getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Retrieves text resources from the locale-specific properties file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    private static String getTextResource(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (resources == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                resources = ResourceBundle.getBundle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    "sun.rmi.registry.resources.rmiregistry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            } catch (MissingResourceException mre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            if (resources == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                // throwing an Error is a bit extreme, methinks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                return ("[missing resource file: " + key + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        String val = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            val = resources.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        } catch (MissingResourceException mre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (val == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            return ("[missing resource: " + key + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return (val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
36670
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   406
     * Convert class path specification into an array of file URLs.
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   407
     *
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   408
     * The path of the file is converted to a URI then into URL
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   409
     * form so that reserved characters can safely appear in the path.
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   410
     */
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   411
    private static URL[] pathToURLs(String path) {
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   412
        List<URL> paths = new ArrayList<>();
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   413
        for (String entry: path.split(File.pathSeparator)) {
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   414
            Path p = Paths.get(entry);
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   415
            try {
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   416
                p = p.toRealPath();
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   417
            } catch (IOException x) {
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   418
                p = p.toAbsolutePath();
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   419
            }
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   420
            try {
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   421
                paths.add(p.toUri().toURL());
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   422
            } catch (MalformedURLException e) {
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   423
                //ignore / skip entry
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   424
            }
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   425
        }
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   426
        return paths.toArray(new URL[0]);
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   427
    }
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   428
acf999f92006 8152277: Move URLClassPath.pathToURLs(String) to RegistryImpl
chegar
parents: 30655
diff changeset
   429
    /**
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   430
     * ObjectInputFilter to filter Registry input objects.
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   431
     * The list of acceptable classes is limited to classes normally
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   432
     * stored in a registry.
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   433
     *
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   434
     * @param filterInfo access to the class, array length, etc.
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   435
     * @return  {@link ObjectInputFilter.Status#ALLOWED} if allowed,
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   436
     *          {@link ObjectInputFilter.Status#REJECTED} if rejected,
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   437
     *          otherwise {@link ObjectInputFilter.Status#UNDECIDED}
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   438
     */
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   439
    private static ObjectInputFilter.Status registryFilter(ObjectInputFilter.FilterInfo filterInfo) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   440
        if (registryFilter != null) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   441
            ObjectInputFilter.Status status = registryFilter.checkInput(filterInfo);
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   442
            if (status != ObjectInputFilter.Status.UNDECIDED) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   443
                // The Registry filter can override the built-in white-list
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   444
                return status;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   445
            }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   446
        }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   447
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   448
        if (filterInfo.depth() > REGISTRY_MAX_DEPTH) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   449
            return ObjectInputFilter.Status.REJECTED;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   450
        }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   451
        Class<?> clazz = filterInfo.serialClass();
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   452
        if (clazz != null) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   453
            if (clazz.isArray()) {
46160
c647e44ea1b9 8185346: Relax RMI Registry Serial Filter to allow arrays of any type
rriggs
parents: 45989
diff changeset
   454
                // Arrays are REJECTED only if they exceed the limit
c647e44ea1b9 8185346: Relax RMI Registry Serial Filter to allow arrays of any type
rriggs
parents: 45989
diff changeset
   455
                return (filterInfo.arrayLength() >= 0 && filterInfo.arrayLength() > REGISTRY_MAX_ARRAY_SIZE)
c647e44ea1b9 8185346: Relax RMI Registry Serial Filter to allow arrays of any type
rriggs
parents: 45989
diff changeset
   456
                    ? ObjectInputFilter.Status.REJECTED
c647e44ea1b9 8185346: Relax RMI Registry Serial Filter to allow arrays of any type
rriggs
parents: 45989
diff changeset
   457
                    : ObjectInputFilter.Status.UNDECIDED;
43211
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   458
            }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   459
            if (String.class == clazz
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   460
                    || java.lang.Number.class.isAssignableFrom(clazz)
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   461
                    || Remote.class.isAssignableFrom(clazz)
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   462
                    || java.lang.reflect.Proxy.class.isAssignableFrom(clazz)
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   463
                    || UnicastRef.class.isAssignableFrom(clazz)
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   464
                    || RMIClientSocketFactory.class.isAssignableFrom(clazz)
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   465
                    || RMIServerSocketFactory.class.isAssignableFrom(clazz)
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   466
                    || java.rmi.activation.ActivationID.class.isAssignableFrom(clazz)
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   467
                    || java.rmi.server.UID.class.isAssignableFrom(clazz)) {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   468
                return ObjectInputFilter.Status.ALLOWED;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   469
            } else {
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   470
                return ObjectInputFilter.Status.REJECTED;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   471
            }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   472
        }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   473
        return ObjectInputFilter.Status.UNDECIDED;
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   474
    }
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   475
f264afd5082c 8156802: Better constraint checking
rriggs
parents: 43061
diff changeset
   476
    /**
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   477
     * Return a new RegistryImpl on the requested port and export it to serve
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   478
     * registry requests. A classloader is initialized from the system property
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   479
     * "env.class.path" and a security manager is set unless one is already set.
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   480
     * <p>
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   481
     * The returned Registry is fully functional within the current process and
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   482
     * is usable for internal and testing purposes.
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   483
     *
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   484
     * @param regPort port on which the rmiregistry accepts requests;
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   485
     *                if 0, an implementation specific port is assigned
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   486
     * @return a RegistryImpl instance
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   487
     * @exception RemoteException If remote operation failed.
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   488
     * @since 9
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   490
    public static RegistryImpl createRegistry(int regPort) throws RemoteException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // Create and install the security manager if one is not installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        // already.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        if (System.getSecurityManager() == null) {
28053
b2366f339e39 8066633: Fix deprecation warnings in java.rmi module
smarks
parents: 27805
diff changeset
   494
            System.setSecurityManager(new SecurityManager());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   497
        /*
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   498
         * Fix bugid 4147561: When JDK tools are executed, the value of
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   499
         * the CLASSPATH environment variable for the shell in which they
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   500
         * were invoked is no longer incorporated into the application
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   501
         * class path; CLASSPATH's only effect is to be the value of the
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   502
         * system property "env.class.path".  To preserve the previous
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   503
         * (JDK1.1 and JDK1.2beta3) behavior of this tool, however, its
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   504
         * CLASSPATH should still be considered when resolving classes
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   505
         * being unmarshalled.  To effect this old behavior, a class
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   506
         * loader that loads from the file path specified in the
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   507
         * "env.class.path" property is created and set to be the context
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   508
         * class loader before the remote object is exported.
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   509
         */
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   510
        String envcp = System.getProperty("env.class.path");
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   511
        if (envcp == null) {
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   512
            envcp = ".";            // preserve old default behavior
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   513
        }
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   514
        URL[] urls = pathToURLs(envcp);
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   515
        ClassLoader cl = new URLClassLoader(urls);
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   516
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   517
        /*
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   518
         * Fix bugid 4242317: Classes defined by this class loader should
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   519
         * be annotated with the value of the "java.rmi.server.codebase"
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   520
         * property, not the "file:" URLs for the CLASSPATH elements.
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   521
         */
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   522
        sun.rmi.server.LoaderHandler.registerCodebaseLoader(cl);
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   523
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   524
        Thread.currentThread().setContextClassLoader(cl);
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   525
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   526
        RegistryImpl registryImpl = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        try {
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   528
            registryImpl = AccessController.doPrivileged(
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   529
                new PrivilegedExceptionAction<RegistryImpl>() {
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   530
                    public RegistryImpl run() throws RemoteException {
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   531
                        return new RegistryImpl(regPort);
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   532
                    }
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   533
                }, getAccessControlContext(regPort));
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   534
        } catch (PrivilegedActionException ex) {
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   535
            throw (RemoteException) ex.getException();
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   536
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   538
        return registryImpl;
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   539
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   541
    /**
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   542
     * Main program to start a registry. <br>
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   543
     * The port number can be specified on the command line.
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   544
     */
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   545
    public static void main(String args[])
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   546
    {
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   547
        try {
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   548
            final int regPort = (args.length >= 1) ? Integer.parseInt(args[0])
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   549
                                                   : Registry.REGISTRY_PORT;
43061
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   550
257cac611780 8172347: Refactoring src/java.rmi/share/classes/sun/rmi/registry/RegistryImpl.java to improve testability of rmiregistry
mli
parents: 36670
diff changeset
   551
            registry = createRegistry(regPort);
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   552
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            // prevent registry from exiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    Thread.sleep(Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            System.err.println(MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                getTextResource("rmiregistry.port.badnumber"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                args[0] ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            System.err.println(MessageFormat.format(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                getTextResource("rmiregistry.usage"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                "rmiregistry" ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   572
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   573
    /**
11039
4ee27839f531 7102369: remove java.rmi.server.codebase property parsing from registyimpl
coffeys
parents: 10914
diff changeset
   574
     * Generates an AccessControlContext with minimal permissions.
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   575
     * The approach used here is taken from the similar method
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   576
     * getAccessControlContext() in the sun.applet.AppletPanel class.
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   577
     */
22339
e91bfaf4360d 8011786: Better applet networking
michaelm
parents: 14342
diff changeset
   578
    private static AccessControlContext getAccessControlContext(int port) {
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   579
        // begin with permissions granted to all code in current policy
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   580
        PermissionCollection perms = AccessController.doPrivileged(
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   581
            new java.security.PrivilegedAction<PermissionCollection>() {
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   582
                public PermissionCollection run() {
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   583
                    CodeSource codesource = new CodeSource(null,
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   584
                        (java.security.cert.Certificate[]) null);
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   585
                    Policy p = java.security.Policy.getPolicy();
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   586
                    if (p != null) {
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   587
                        return p.getPermissions(codesource);
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   588
                    } else {
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   589
                        return new Permissions();
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   590
                    }
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   591
                }
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   592
            });
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   593
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   594
        /*
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   595
         * Anyone can connect to the registry and the registry can connect
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   596
         * to and possibly download stubs from anywhere. Downloaded stubs and
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   597
         * related classes themselves are more tightly limited by RMI.
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   598
         */
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   599
        perms.add(new SocketPermission("*", "connect,accept"));
22341
4689530d03b9 8028293: Check local configuration for actual ephemeral port range
michaelm
parents: 22339
diff changeset
   600
        perms.add(new SocketPermission("localhost:"+port, "listen,accept"));
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   601
14209
221f6d0a12ea 7093490: adjust package access in rmiregistry
smarks
parents: 12040
diff changeset
   602
        perms.add(new RuntimePermission("accessClassInPackage.sun.jvmstat.*"));
221f6d0a12ea 7093490: adjust package access in rmiregistry
smarks
parents: 12040
diff changeset
   603
        perms.add(new RuntimePermission("accessClassInPackage.sun.jvm.hotspot.*"));
10914
da696f9a3be6 7092186: adjust package access in rmiregistry
smarks
parents: 10913
diff changeset
   604
11039
4ee27839f531 7102369: remove java.rmi.server.codebase property parsing from registyimpl
coffeys
parents: 10914
diff changeset
   605
        perms.add(new FilePermission("<<ALL FILES>>", "read"));
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   606
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   607
        /*
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   608
         * Create an AccessControlContext that consists of a single
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   609
         * protection domain with only the permissions calculated above.
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   610
         */
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   611
        ProtectionDomain pd = new ProtectionDomain(
11039
4ee27839f531 7102369: remove java.rmi.server.codebase property parsing from registyimpl
coffeys
parents: 10914
diff changeset
   612
            new CodeSource(null,
4ee27839f531 7102369: remove java.rmi.server.codebase property parsing from registyimpl
coffeys
parents: 10914
diff changeset
   613
                (java.security.cert.Certificate[]) null), perms);
10913
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   614
        return new AccessControlContext(new ProtectionDomain[] { pd });
e1acf4473704 7083012: fix for RMI Registry
smarks
parents: 5506
diff changeset
   615
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
}