jdk/src/jdk.management.agent/share/classes/sun/management/jmxremote/SingleEntryRegistry.java
author rriggs
Wed, 03 May 2017 12:56:02 -0400
changeset 45989 e4f526fd8e09
parent 43494 11801b2ff456
permissions -rw-r--r--
8174770: Check registry registration location Reviewed-by: dfuchs, smarks, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
     2
 * Copyright (c) 2003, 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: 4173
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: 4173
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: 4173
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4173
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @author    Sun Microsystems, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @build        @BUILD_TAG_PLACEHOLDER@
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @COPYRIGHT_MINI_LEGAL_NOTICE_PLACEHOLDER@
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
package sun.management.jmxremote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    35
import java.io.ObjectInputFilter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.AccessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.NotBoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.server.RMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.server.RMIServerSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.rmi.registry.RegistryImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/** A Registry that consists of a single entry that never changes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class SingleEntryRegistry extends RegistryImpl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    SingleEntryRegistry(int port, String name, Remote object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        super(port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        this.object = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    SingleEntryRegistry(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                        RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                        RMIServerSocketFactory ssf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                        String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                        Remote object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            throws RemoteException {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    60
        super(port, csf, ssf, SingleEntryRegistry::singleRegistryFilter);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.object = object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public String[] list() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return new String[] {name};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public Remote lookup(String name) throws NotBoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (name.equals(this.name))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            return object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        throw new NotBoundException("Not bound: \"" + name + "\" (only " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                    "bound name is \"" + this.name + "\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void bind(String name, Remote obj) throws AccessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        throw new AccessException("Cannot modify this registry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void rebind(String name, Remote obj) throws AccessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        throw new AccessException("Cannot modify this registry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void unbind(String name) throws AccessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        throw new AccessException("Cannot modify this registry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    88
    /**
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    89
     * ObjectInputFilter to check parameters to SingleEntryRegistry.
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    90
     * Since it is a read-only Registry, no classes are accepted.
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    91
     * String arguments are accepted without passing them to the serialFilter.
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    92
     *
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    93
     * @param info a reference to the serialization filter information
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    94
     * @return Status.REJECTED if parameters are out of range
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    95
     */
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    96
    private static ObjectInputFilter.Status singleRegistryFilter(ObjectInputFilter.FilterInfo info) {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    97
        return (info.serialClass() != null ||
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    98
                info.depth() > 2 ||
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
    99
                info.references() > 4 ||
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
   100
                info.arrayLength() >= 0)
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
   101
        ? ObjectInputFilter.Status.REJECTED
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
   102
        : ObjectInputFilter.Status.ALLOWED;
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
   103
    }
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 43494
diff changeset
   104
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private final Remote object;
4173
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 2
diff changeset
   107
d01972926813 6895875: Missing serialVersionUID in sun.management classes
mchung
parents: 2
diff changeset
   108
    private static final long serialVersionUID = -4897238949499730950L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}