src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIJRMPServerImpl.java
author herrick
Mon, 30 Sep 2019 19:33:13 -0400
branchJDK-8200758-branch
changeset 58417 67ffaf3a2b75
parent 47425 96179f26139e
permissions -rw-r--r--
8231280: Linux packages produced by jpackage should have correct dependencies Submitted-by: asemenyuk Reviewed-by: herrick
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
     2
 * Copyright (c) 2002, 2016, 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: 1706
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: 1706
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: 1706
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1706
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1706
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 javax.management.remote.rmi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
    29
import java.io.ObjectInputFilter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.rmi.NoSuchObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.rmi.server.RMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.server.RMIServerSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.security.auth.Subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
43503
bc7f8619ab70 8173607: JMX RMI connector should be in its own module
dfuchs
parents: 37584
diff changeset
    41
import com.sun.jmx.remote.internal.rmi.RMIExporter;
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
    42
import com.sun.jmx.remote.util.EnvHelp;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    43
import java.util.Arrays;
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
    44
import java.util.Set;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
    45
import java.util.stream.Collectors;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    46
import sun.reflect.misc.ReflectUtil;
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
    47
import sun.rmi.server.UnicastServerRef;
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
    48
import sun.rmi.server.UnicastServerRef2;
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
    49
import sun.rmi.transport.LiveRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>An {@link RMIServer} object that is exported through JRMP and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * creates client connections as RMI objects exported through JRMP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * User code does not usually reference this class directly.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see RMIServerImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class RMIJRMPServerImpl extends RMIServerImpl {
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * <p>Creates a new {@link RMIServer} object that will be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * on the given port using the given socket factories.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @param port the port on which this object and the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * RMIConnectionImpl} objects it creates will be exported.  Can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * zero, to indicate any available port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param csf the client socket factory for the created RMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * objects.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param ssf the server socket factory for the created RMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * objects.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param env the environment map.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @exception IOException if the {@link RMIServer} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * cannot be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @exception IllegalArgumentException if <code>port</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public RMIJRMPServerImpl(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                             RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                             RMIServerSocketFactory ssf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                             Map<String,?> env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        super(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (port < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new IllegalArgumentException("Negative port: " + port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        this.csf = csf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this.ssf = ssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.env = (env == null) ? Collections.<String, Object>emptyMap() : env;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    99
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   100
        // This attribute was represented by RMIConnectorServer.CREDENTIALS_TYPES.
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   101
        // This attribute is superceded by
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   102
        // RMIConnectorServer.CREDENTIALS_FILTER_PATTERN.
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   103
        // Retaining this for backward compatibility.
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   104
        String[] credentialsTypes
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   105
                = (String[]) this.env.get("jmx.remote.rmi.server.credential.types");
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   106
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   107
        String credentialsFilter
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   108
                = (String) this.env.get(RMIConnectorServer.CREDENTIALS_FILTER_PATTERN);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   109
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   110
        // It is impossible for both attributes to be specified
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   111
        if(credentialsTypes != null && credentialsFilter != null)
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   112
            throw new IllegalArgumentException("Cannot specify both \""
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   113
                    + "jmx.remote.rmi.server.credential.types" + "\" and \""
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   114
           + RMIConnectorServer.CREDENTIALS_FILTER_PATTERN + "\"");
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   115
        else if(credentialsFilter != null){
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   116
            cFilter = ObjectInputFilter.Config.createFilter(credentialsFilter);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   117
            allowedTypes = null;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   118
        }
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   119
        else if (credentialsTypes != null) {
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   120
            allowedTypes = Arrays.stream(credentialsTypes).filter(
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   121
                    s -> s!= null).collect(Collectors.toSet());
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   122
            allowedTypes.stream().forEach(ReflectUtil::checkPackageAccess);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   123
            cFilter = this::newClientCheckInput;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   124
        } else {
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   125
            allowedTypes = null;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   126
            cFilter = null;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   127
        }
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   128
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   129
        String userJmxFilter =
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   130
                (String) this.env.get(RMIConnectorServer.SERIAL_FILTER_PATTERN);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   131
        if(userJmxFilter != null && !userJmxFilter.isEmpty())
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   132
            jmxRmiFilter = ObjectInputFilter.Config.createFilter(userJmxFilter);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   133
        else
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   134
            jmxRmiFilter = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected void export() throws IOException {
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   138
        export(this, cFilter);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   141
    private void export(Remote obj, ObjectInputFilter typeFilter) throws RemoteException {
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   142
        final RMIExporter exporter =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   144
        final boolean daemon = EnvHelp.isServerDaemon(env);
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   145
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   146
        if (daemon && exporter != null) {
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   147
            throw new IllegalArgumentException("If "+EnvHelp.JMX_SERVER_DAEMON+
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   148
                    " is specified as true, "+RMIExporter.EXPORTER_ATTRIBUTE+
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   149
                    " cannot be used to specify an exporter!");
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   150
        }
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   151
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   152
        if (exporter != null) {
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   153
            exporter.exportObject(obj, port, csf, ssf, typeFilter);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   154
        } else {
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   155
            if (csf == null && ssf == null) {
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   156
                new UnicastServerRef(new LiveRef(port), typeFilter).exportObject(obj, null, daemon);
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   157
            } else {
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   158
                new UnicastServerRef2(port, csf, ssf, typeFilter).exportObject(obj, null, daemon);
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   159
            }
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   160
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private void unexport(Remote obj, boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throws NoSuchObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        RMIExporter exporter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (exporter == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            UnicastRemoteObject.unexportObject(obj, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            exporter.unexportObject(obj, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    protected String getProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return "rmi";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <p>Returns a serializable stub for this {@link RMIServer} object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return a serializable stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception IOException if the stub cannot be obtained - e.g the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *            RMIJRMPServerImpl has not been exported yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public Remote toStub() throws IOException {
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   186
        return RemoteObject.toStub(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p>Creates a new client connection as an RMI object exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * through JRMP. The port and socket factories for the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * {@link RMIConnection} object are the ones supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * to the <code>RMIJRMPServerImpl</code> constructor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param connectionId the ID of the new connection. Every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * connection opened by this connector server will have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * different id.  The behavior is unspecified if this parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param subject the authenticated subject.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @return the newly-created <code>RMIConnection</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @exception IOException if the new {@link RMIConnection}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * object cannot be created or exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    protected RMIConnection makeClient(String connectionId, Subject subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (connectionId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            throw new NullPointerException("Null connectionId");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        RMIConnection client =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            new RMIConnectionImpl(this, connectionId, getDefaultClassLoader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                  subject, env);
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   216
        export(client, jmxRmiFilter);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    protected void closeClient(RMIConnection client) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        unexport(client, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p>Called by {@link #close()} to close the connector server by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * unexporting this object.  After returning from this method, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * connector server must not accept any new connections.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @exception IOException if the attempt to close the connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * server failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    protected void closeServer() throws IOException {
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   233
        unexport(this, true);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   234
    }
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   235
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   236
    /**
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   237
     * Check that a type in the remote invocation of {@link RMIServerImpl#newClient}
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   238
     * is one of the {@code allowedTypes}.
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   239
     *
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   240
     * @param clazz       the class; may be null
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   241
     * @param size        the size for arrays, otherwise is 0
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   242
     * @param nObjectRefs the current number of object references
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   243
     * @param depth       the current depth
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   244
     * @param streamBytes the current number of bytes consumed
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   245
     * @return {@code ObjectInputFilter.Status.ALLOWED} if the class is allowed,
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   246
     *          otherwise {@code ObjectInputFilter.Status.REJECTED}
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   247
     */
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   248
    ObjectInputFilter.Status newClientCheckInput(ObjectInputFilter.FilterInfo filterInfo) {
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   249
        ObjectInputFilter.Status status = ObjectInputFilter.Status.UNDECIDED;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   250
        if (allowedTypes != null && filterInfo.serialClass() != null) {
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   251
            // If enabled, check type
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   252
            String type = filterInfo.serialClass().getName();
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   253
            if (allowedTypes.contains(type))
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   254
                status = ObjectInputFilter.Status.ALLOWED;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   255
            else
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   256
                status = ObjectInputFilter.Status.REJECTED;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   257
        }
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   258
        return status;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private final int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private final RMIClientSocketFactory csf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    private final RMIServerSocketFactory ssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    private final Map<String, ?> env;
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   265
    private final Set<String> allowedTypes;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   266
    private final ObjectInputFilter jmxRmiFilter;
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   267
    private final ObjectInputFilter cFilter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
}