Path: blob/master/src/java.management.rmi/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java
41162 views
/*1* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.management.remote.rmi;2627import java.io.IOException;28import java.rmi.MarshalledObject;29import java.rmi.UnmarshalException;30import java.rmi.server.Unreferenced;31import java.security.AccessControlContext;32import java.security.AccessController;33import java.security.Permission;34import java.security.Permissions;35import java.security.PrivilegedAction;36import java.security.PrivilegedActionException;37import java.security.PrivilegedExceptionAction;38import java.security.ProtectionDomain;39import java.util.Arrays;40import java.util.Collections;41import java.util.Map;42import java.util.Set;4344import javax.management.*;45import javax.management.remote.JMXServerErrorException;46import javax.management.remote.NotificationResult;47import javax.security.auth.Subject;48import sun.reflect.misc.ReflectUtil;4950import static javax.management.remote.rmi.RMIConnector.Util.cast;51import com.sun.jmx.remote.internal.ServerCommunicatorAdmin;52import com.sun.jmx.remote.internal.ServerNotifForwarder;53import com.sun.jmx.remote.security.JMXSubjectDomainCombiner;54import com.sun.jmx.remote.security.SubjectDelegator;55import com.sun.jmx.remote.util.ClassLoaderWithRepository;56import com.sun.jmx.remote.util.ClassLogger;57import com.sun.jmx.remote.util.EnvHelp;58import com.sun.jmx.remote.util.OrderClassLoaders;59import javax.management.loading.ClassLoaderRepository;6061/**62* <p>Implementation of the {@link RMIConnection} interface. User63* code will not usually reference this class.</p>64*65* @since 1.566*/67/*68* Notice that we omit the type parameter from MarshalledObject everywhere,69* even though it would add useful information to the documentation. The70* reason is that it was only added in Mustang (Java SE 6), whereas versions71* 1.4 and 2.0 of the JMX API must be implementable on Tiger per our72* commitments for JSR 255.73*/74public class RMIConnectionImpl implements RMIConnection, Unreferenced {7576/**77* Constructs a new {@link RMIConnection}. This connection can be78* used with the JRMP transport. This object does79* not export itself: it is the responsibility of the caller to80* export it appropriately (see {@link81* RMIJRMPServerImpl#makeClient(String,Subject)}).82*83* @param rmiServer The RMIServerImpl object for which this84* connection is created. The behavior is unspecified if this85* parameter is null.86* @param connectionId The ID for this connection. The behavior87* is unspecified if this parameter is null.88* @param defaultClassLoader The default ClassLoader to be used89* when deserializing marshalled objects. Can be null, to signify90* the bootstrap class loader.91* @param subject the authenticated subject to be used for92* authorization. Can be null, to signify that no subject has93* been authenticated.94* @param env the environment containing attributes for the new95* <code>RMIServerImpl</code>. Can be null, equivalent to an96* empty map.97*/98@SuppressWarnings("removal")99public RMIConnectionImpl(RMIServerImpl rmiServer,100String connectionId,101ClassLoader defaultClassLoader,102Subject subject,103Map<String,?> env) {104if (rmiServer == null || connectionId == null)105throw new NullPointerException("Illegal null argument");106if (env == null)107env = Collections.emptyMap();108this.rmiServer = rmiServer;109this.connectionId = connectionId;110this.defaultClassLoader = defaultClassLoader;111112this.subjectDelegator = new SubjectDelegator();113this.subject = subject;114if (subject == null) {115this.acc = null;116this.removeCallerContext = false;117} else {118this.removeCallerContext =119SubjectDelegator.checkRemoveCallerContext(subject);120if (this.removeCallerContext) {121this.acc =122JMXSubjectDomainCombiner.getDomainCombinerContext(subject);123} else {124this.acc =125JMXSubjectDomainCombiner.getContext(subject);126}127}128this.mbeanServer = rmiServer.getMBeanServer();129130final ClassLoader dcl = defaultClassLoader;131132ClassLoaderRepository repository = AccessController.doPrivileged(133new PrivilegedAction<ClassLoaderRepository>() {134public ClassLoaderRepository run() {135return mbeanServer.getClassLoaderRepository();136}137},138withPermissions(new MBeanPermission("*", "getClassLoaderRepository"))139);140this.classLoaderWithRepository = AccessController.doPrivileged(141new PrivilegedAction<ClassLoaderWithRepository>() {142public ClassLoaderWithRepository run() {143return new ClassLoaderWithRepository(144repository,145dcl);146}147},148withPermissions(new RuntimePermission("createClassLoader"))149);150151this.defaultContextClassLoader =152AccessController.doPrivileged(153new PrivilegedAction<ClassLoader>() {154@Override155public ClassLoader run() {156return new CombinedClassLoader(Thread.currentThread().getContextClassLoader(),157dcl);158}159});160161serverCommunicatorAdmin = new162RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));163164this.env = env;165}166167@SuppressWarnings("removal")168private static AccessControlContext withPermissions(Permission ... perms){169Permissions col = new Permissions();170171for (Permission thePerm : perms ) {172col.add(thePerm);173}174175final ProtectionDomain pd = new ProtectionDomain(null, col);176return new AccessControlContext( new ProtectionDomain[] { pd });177}178179private synchronized ServerNotifForwarder getServerNotifFwd() {180// Lazily created when first use. Mainly when181// addNotificationListener is first called.182if (serverNotifForwarder == null)183serverNotifForwarder =184new ServerNotifForwarder(mbeanServer,185env,186rmiServer.getNotifBuffer(),187connectionId);188return serverNotifForwarder;189}190191public String getConnectionId() throws IOException {192// We should call reqIncomming() here... shouldn't we?193return connectionId;194}195196public void close() throws IOException {197final boolean debug = logger.debugOn();198final String idstr = (debug?"["+this.toString()+"]":null);199200synchronized (this) {201if (terminated) {202if (debug) logger.debug("close",idstr + " already terminated.");203return;204}205206if (debug) logger.debug("close",idstr + " closing.");207208terminated = true;209210if (serverCommunicatorAdmin != null) {211serverCommunicatorAdmin.terminate();212}213214if (serverNotifForwarder != null) {215serverNotifForwarder.terminate();216}217}218219rmiServer.clientClosed(this);220221if (debug) logger.debug("close",idstr + " closed.");222}223224public void unreferenced() {225logger.debug("unreferenced", "called");226try {227close();228logger.debug("unreferenced", "done");229} catch (IOException e) {230logger.fine("unreferenced", e);231}232}233234//-------------------------------------------------------------------------235// MBeanServerConnection Wrapper236//-------------------------------------------------------------------------237238public ObjectInstance createMBean(String className,239ObjectName name,240Subject delegationSubject)241throws242ReflectionException,243InstanceAlreadyExistsException,244MBeanRegistrationException,245MBeanException,246NotCompliantMBeanException,247IOException {248try {249final Object params[] =250new Object[] { className, name };251252if (logger.debugOn())253logger.debug("createMBean(String,ObjectName)",254"connectionId=" + connectionId +", className=" +255className+", name=" + name);256257return (ObjectInstance)258doPrivilegedOperation(259CREATE_MBEAN,260params,261delegationSubject);262} catch (PrivilegedActionException pe) {263Exception e = extractException(pe);264if (e instanceof ReflectionException)265throw (ReflectionException) e;266if (e instanceof InstanceAlreadyExistsException)267throw (InstanceAlreadyExistsException) e;268if (e instanceof MBeanRegistrationException)269throw (MBeanRegistrationException) e;270if (e instanceof MBeanException)271throw (MBeanException) e;272if (e instanceof NotCompliantMBeanException)273throw (NotCompliantMBeanException) e;274if (e instanceof IOException)275throw (IOException) e;276throw newIOException("Got unexpected server exception: " + e, e);277}278}279280public ObjectInstance createMBean(String className,281ObjectName name,282ObjectName loaderName,283Subject delegationSubject)284throws285ReflectionException,286InstanceAlreadyExistsException,287MBeanRegistrationException,288MBeanException,289NotCompliantMBeanException,290InstanceNotFoundException,291IOException {292try {293final Object params[] =294new Object[] { className, name, loaderName };295296if (logger.debugOn())297logger.debug("createMBean(String,ObjectName,ObjectName)",298"connectionId=" + connectionId299+", className=" + className300+", name=" + name301+", loaderName=" + loaderName);302303return (ObjectInstance)304doPrivilegedOperation(305CREATE_MBEAN_LOADER,306params,307delegationSubject);308} catch (PrivilegedActionException pe) {309Exception e = extractException(pe);310if (e instanceof ReflectionException)311throw (ReflectionException) e;312if (e instanceof InstanceAlreadyExistsException)313throw (InstanceAlreadyExistsException) e;314if (e instanceof MBeanRegistrationException)315throw (MBeanRegistrationException) e;316if (e instanceof MBeanException)317throw (MBeanException) e;318if (e instanceof NotCompliantMBeanException)319throw (NotCompliantMBeanException) e;320if (e instanceof InstanceNotFoundException)321throw (InstanceNotFoundException) e;322if (e instanceof IOException)323throw (IOException) e;324throw newIOException("Got unexpected server exception: " + e, e);325}326}327328@SuppressWarnings("rawtypes") // MarshalledObject329public ObjectInstance createMBean(String className,330ObjectName name,331MarshalledObject params,332String signature[],333Subject delegationSubject)334throws335ReflectionException,336InstanceAlreadyExistsException,337MBeanRegistrationException,338MBeanException,339NotCompliantMBeanException,340IOException {341342final Object[] values;343final boolean debug = logger.debugOn();344345if (debug) logger.debug(346"createMBean(String,ObjectName,Object[],String[])",347"connectionId=" + connectionId348+", unwrapping parameters using classLoaderWithRepository.");349350values =351nullIsEmpty(unwrap(params, classLoaderWithRepository, Object[].class,delegationSubject));352353try {354final Object params2[] =355new Object[] { className, name, values,356nullIsEmpty(signature) };357358if (debug)359logger.debug("createMBean(String,ObjectName,Object[],String[])",360"connectionId=" + connectionId361+", className=" + className362+", name=" + name363+", signature=" + strings(signature));364365return (ObjectInstance)366doPrivilegedOperation(367CREATE_MBEAN_PARAMS,368params2,369delegationSubject);370} catch (PrivilegedActionException pe) {371Exception e = extractException(pe);372if (e instanceof ReflectionException)373throw (ReflectionException) e;374if (e instanceof InstanceAlreadyExistsException)375throw (InstanceAlreadyExistsException) e;376if (e instanceof MBeanRegistrationException)377throw (MBeanRegistrationException) e;378if (e instanceof MBeanException)379throw (MBeanException) e;380if (e instanceof NotCompliantMBeanException)381throw (NotCompliantMBeanException) e;382if (e instanceof IOException)383throw (IOException) e;384throw newIOException("Got unexpected server exception: " + e, e);385}386}387388@SuppressWarnings("rawtypes") // MarshalledObject389public ObjectInstance createMBean(String className,390ObjectName name,391ObjectName loaderName,392MarshalledObject params,393String signature[],394Subject delegationSubject)395throws396ReflectionException,397InstanceAlreadyExistsException,398MBeanRegistrationException,399MBeanException,400NotCompliantMBeanException,401InstanceNotFoundException,402IOException {403404final Object[] values;405final boolean debug = logger.debugOn();406407if (debug) logger.debug(408"createMBean(String,ObjectName,ObjectName,Object[],String[])",409"connectionId=" + connectionId410+", unwrapping params with MBean extended ClassLoader.");411412values = nullIsEmpty(unwrap(params,413getClassLoader(loaderName),414defaultClassLoader,415Object[].class,delegationSubject));416417try {418final Object params2[] =419new Object[] { className, name, loaderName, values,420nullIsEmpty(signature) };421422if (debug) logger.debug(423"createMBean(String,ObjectName,ObjectName,Object[],String[])",424"connectionId=" + connectionId425+", className=" + className426+", name=" + name427+", loaderName=" + loaderName428+", signature=" + strings(signature));429430return (ObjectInstance)431doPrivilegedOperation(432CREATE_MBEAN_LOADER_PARAMS,433params2,434delegationSubject);435} catch (PrivilegedActionException pe) {436Exception e = extractException(pe);437if (e instanceof ReflectionException)438throw (ReflectionException) e;439if (e instanceof InstanceAlreadyExistsException)440throw (InstanceAlreadyExistsException) e;441if (e instanceof MBeanRegistrationException)442throw (MBeanRegistrationException) e;443if (e instanceof MBeanException)444throw (MBeanException) e;445if (e instanceof NotCompliantMBeanException)446throw (NotCompliantMBeanException) e;447if (e instanceof InstanceNotFoundException)448throw (InstanceNotFoundException) e;449if (e instanceof IOException)450throw (IOException) e;451throw newIOException("Got unexpected server exception: " + e, e);452}453}454455public void unregisterMBean(ObjectName name, Subject delegationSubject)456throws457InstanceNotFoundException,458MBeanRegistrationException,459IOException {460try {461final Object params[] = new Object[] { name };462463if (logger.debugOn()) logger.debug("unregisterMBean",464"connectionId=" + connectionId465+", name="+name);466467doPrivilegedOperation(468UNREGISTER_MBEAN,469params,470delegationSubject);471} catch (PrivilegedActionException pe) {472Exception e = extractException(pe);473if (e instanceof InstanceNotFoundException)474throw (InstanceNotFoundException) e;475if (e instanceof MBeanRegistrationException)476throw (MBeanRegistrationException) e;477if (e instanceof IOException)478throw (IOException) e;479throw newIOException("Got unexpected server exception: " + e, e);480}481}482483public ObjectInstance getObjectInstance(ObjectName name,484Subject delegationSubject)485throws486InstanceNotFoundException,487IOException {488489checkNonNull("ObjectName", name);490491try {492final Object params[] = new Object[] { name };493494if (logger.debugOn()) logger.debug("getObjectInstance",495"connectionId=" + connectionId496+", name="+name);497498return (ObjectInstance)499doPrivilegedOperation(500GET_OBJECT_INSTANCE,501params,502delegationSubject);503} catch (PrivilegedActionException pe) {504Exception e = extractException(pe);505if (e instanceof InstanceNotFoundException)506throw (InstanceNotFoundException) e;507if (e instanceof IOException)508throw (IOException) e;509throw newIOException("Got unexpected server exception: " + e, e);510}511}512513@SuppressWarnings("rawtypes") // MarshalledObject514public Set<ObjectInstance>515queryMBeans(ObjectName name,516MarshalledObject query,517Subject delegationSubject)518throws IOException {519final QueryExp queryValue;520final boolean debug=logger.debugOn();521522if (debug) logger.debug("queryMBeans",523"connectionId=" + connectionId524+" unwrapping query with defaultClassLoader.");525526queryValue = unwrap(query, defaultContextClassLoader, QueryExp.class, delegationSubject);527528try {529final Object params[] = new Object[] { name, queryValue };530531if (debug) logger.debug("queryMBeans",532"connectionId=" + connectionId533+", name="+name +", query="+query);534535return cast(536doPrivilegedOperation(537QUERY_MBEANS,538params,539delegationSubject));540} catch (PrivilegedActionException pe) {541Exception e = extractException(pe);542if (e instanceof IOException)543throw (IOException) e;544throw newIOException("Got unexpected server exception: " + e, e);545}546}547548@SuppressWarnings("rawtypes") // MarshalledObject549public Set<ObjectName>550queryNames(ObjectName name,551MarshalledObject query,552Subject delegationSubject)553throws IOException {554final QueryExp queryValue;555final boolean debug=logger.debugOn();556557if (debug) logger.debug("queryNames",558"connectionId=" + connectionId559+" unwrapping query with defaultClassLoader.");560561queryValue = unwrap(query, defaultContextClassLoader, QueryExp.class, delegationSubject);562563try {564final Object params[] = new Object[] { name, queryValue };565566if (debug) logger.debug("queryNames",567"connectionId=" + connectionId568+", name="+name +", query="+query);569570return cast(571doPrivilegedOperation(572QUERY_NAMES,573params,574delegationSubject));575} catch (PrivilegedActionException pe) {576Exception e = extractException(pe);577if (e instanceof IOException)578throw (IOException) e;579throw newIOException("Got unexpected server exception: " + e, e);580}581}582583public boolean isRegistered(ObjectName name,584Subject delegationSubject) throws IOException {585try {586final Object params[] = new Object[] { name };587return ((Boolean)588doPrivilegedOperation(589IS_REGISTERED,590params,591delegationSubject)).booleanValue();592} catch (PrivilegedActionException pe) {593Exception e = extractException(pe);594if (e instanceof IOException)595throw (IOException) e;596throw newIOException("Got unexpected server exception: " + e, e);597}598}599600public Integer getMBeanCount(Subject delegationSubject)601throws IOException {602try {603final Object params[] = new Object[] { };604605if (logger.debugOn()) logger.debug("getMBeanCount",606"connectionId=" + connectionId);607608return (Integer)609doPrivilegedOperation(610GET_MBEAN_COUNT,611params,612delegationSubject);613} catch (PrivilegedActionException pe) {614Exception e = extractException(pe);615if (e instanceof IOException)616throw (IOException) e;617throw newIOException("Got unexpected server exception: " + e, e);618}619}620621public Object getAttribute(ObjectName name,622String attribute,623Subject delegationSubject)624throws625MBeanException,626AttributeNotFoundException,627InstanceNotFoundException,628ReflectionException,629IOException {630try {631final Object params[] = new Object[] { name, attribute };632if (logger.debugOn()) logger.debug("getAttribute",633"connectionId=" + connectionId634+", name=" + name635+", attribute="+ attribute);636637return638doPrivilegedOperation(639GET_ATTRIBUTE,640params,641delegationSubject);642} catch (PrivilegedActionException pe) {643Exception e = extractException(pe);644if (e instanceof MBeanException)645throw (MBeanException) e;646if (e instanceof AttributeNotFoundException)647throw (AttributeNotFoundException) e;648if (e instanceof InstanceNotFoundException)649throw (InstanceNotFoundException) e;650if (e instanceof ReflectionException)651throw (ReflectionException) e;652if (e instanceof IOException)653throw (IOException) e;654throw newIOException("Got unexpected server exception: " + e, e);655}656}657658public AttributeList getAttributes(ObjectName name,659String[] attributes,660Subject delegationSubject)661throws662InstanceNotFoundException,663ReflectionException,664IOException {665try {666final Object params[] = new Object[] { name, attributes };667668if (logger.debugOn()) logger.debug("getAttributes",669"connectionId=" + connectionId670+", name=" + name671+", attributes="+ strings(attributes));672673return (AttributeList)674doPrivilegedOperation(675GET_ATTRIBUTES,676params,677delegationSubject);678} catch (PrivilegedActionException pe) {679Exception e = extractException(pe);680if (e instanceof InstanceNotFoundException)681throw (InstanceNotFoundException) e;682if (e instanceof ReflectionException)683throw (ReflectionException) e;684if (e instanceof IOException)685throw (IOException) e;686throw newIOException("Got unexpected server exception: " + e, e);687}688}689690@SuppressWarnings("rawtypes") // MarshalledObject691public void setAttribute(ObjectName name,692MarshalledObject attribute,693Subject delegationSubject)694throws695InstanceNotFoundException,696AttributeNotFoundException,697InvalidAttributeValueException,698MBeanException,699ReflectionException,700IOException {701final Attribute attr;702final boolean debug=logger.debugOn();703704if (debug) logger.debug("setAttribute",705"connectionId=" + connectionId706+" unwrapping attribute with MBean extended ClassLoader.");707708attr = unwrap(attribute,709getClassLoaderFor(name),710defaultClassLoader,711Attribute.class, delegationSubject);712713try {714final Object params[] = new Object[] { name, attr };715716if (debug) logger.debug("setAttribute",717"connectionId=" + connectionId718+", name="+name719+", attribute name="+attr.getName());720721doPrivilegedOperation(722SET_ATTRIBUTE,723params,724delegationSubject);725} catch (PrivilegedActionException pe) {726Exception e = extractException(pe);727if (e instanceof InstanceNotFoundException)728throw (InstanceNotFoundException) e;729if (e instanceof AttributeNotFoundException)730throw (AttributeNotFoundException) e;731if (e instanceof InvalidAttributeValueException)732throw (InvalidAttributeValueException) e;733if (e instanceof MBeanException)734throw (MBeanException) e;735if (e instanceof ReflectionException)736throw (ReflectionException) e;737if (e instanceof IOException)738throw (IOException) e;739throw newIOException("Got unexpected server exception: " + e, e);740}741}742743@SuppressWarnings("rawtypes") // MarshalledObject744public AttributeList setAttributes(ObjectName name,745MarshalledObject attributes,746Subject delegationSubject)747throws748InstanceNotFoundException,749ReflectionException,750IOException {751final AttributeList attrlist;752final boolean debug=logger.debugOn();753754if (debug) logger.debug("setAttributes",755"connectionId=" + connectionId756+" unwrapping attributes with MBean extended ClassLoader.");757758attrlist =759unwrap(attributes,760getClassLoaderFor(name),761defaultClassLoader,762AttributeList.class, delegationSubject);763764try {765final Object params[] = new Object[] { name, attrlist };766767if (debug) logger.debug("setAttributes",768"connectionId=" + connectionId769+", name="+name770+", attribute names="+RMIConnector.getAttributesNames(attrlist));771772return (AttributeList)773doPrivilegedOperation(774SET_ATTRIBUTES,775params,776delegationSubject);777} catch (PrivilegedActionException pe) {778Exception e = extractException(pe);779if (e instanceof InstanceNotFoundException)780throw (InstanceNotFoundException) e;781if (e instanceof ReflectionException)782throw (ReflectionException) e;783if (e instanceof IOException)784throw (IOException) e;785throw newIOException("Got unexpected server exception: " + e, e);786}787}788789@SuppressWarnings("rawtypes") // MarshalledObject790public Object invoke(ObjectName name,791String operationName,792MarshalledObject params,793String signature[],794Subject delegationSubject)795throws796InstanceNotFoundException,797MBeanException,798ReflectionException,799IOException {800801checkNonNull("ObjectName", name);802checkNonNull("Operation name", operationName);803804final Object[] values;805final boolean debug=logger.debugOn();806807if (debug) logger.debug("invoke",808"connectionId=" + connectionId809+" unwrapping params with MBean extended ClassLoader.");810811values = nullIsEmpty(unwrap(params,812getClassLoaderFor(name),813defaultClassLoader,814Object[].class, delegationSubject));815816try {817final Object params2[] =818new Object[] { name, operationName, values,819nullIsEmpty(signature) };820821if (debug) logger.debug("invoke",822"connectionId=" + connectionId823+", name="+name824+", operationName="+operationName825+", signature="+strings(signature));826827return828doPrivilegedOperation(829INVOKE,830params2,831delegationSubject);832} catch (PrivilegedActionException pe) {833Exception e = extractException(pe);834if (e instanceof InstanceNotFoundException)835throw (InstanceNotFoundException) e;836if (e instanceof MBeanException)837throw (MBeanException) e;838if (e instanceof ReflectionException)839throw (ReflectionException) e;840if (e instanceof IOException)841throw (IOException) e;842throw newIOException("Got unexpected server exception: " + e, e);843}844}845846public String getDefaultDomain(Subject delegationSubject)847throws IOException {848try {849final Object params[] = new Object[] { };850851if (logger.debugOn()) logger.debug("getDefaultDomain",852"connectionId=" + connectionId);853854return (String)855doPrivilegedOperation(856GET_DEFAULT_DOMAIN,857params,858delegationSubject);859} catch (PrivilegedActionException pe) {860Exception e = extractException(pe);861if (e instanceof IOException)862throw (IOException) e;863throw newIOException("Got unexpected server exception: " + e, e);864}865}866867public String[] getDomains(Subject delegationSubject) throws IOException {868try {869final Object params[] = new Object[] { };870871if (logger.debugOn()) logger.debug("getDomains",872"connectionId=" + connectionId);873874return (String[])875doPrivilegedOperation(876GET_DOMAINS,877params,878delegationSubject);879} catch (PrivilegedActionException pe) {880Exception e = extractException(pe);881if (e instanceof IOException)882throw (IOException) e;883throw newIOException("Got unexpected server exception: " + e, e);884}885}886887public MBeanInfo getMBeanInfo(ObjectName name, Subject delegationSubject)888throws889InstanceNotFoundException,890IntrospectionException,891ReflectionException,892IOException {893894checkNonNull("ObjectName", name);895896try {897final Object params[] = new Object[] { name };898899if (logger.debugOn()) logger.debug("getMBeanInfo",900"connectionId=" + connectionId901+", name="+name);902903return (MBeanInfo)904doPrivilegedOperation(905GET_MBEAN_INFO,906params,907delegationSubject);908} catch (PrivilegedActionException pe) {909Exception e = extractException(pe);910if (e instanceof InstanceNotFoundException)911throw (InstanceNotFoundException) e;912if (e instanceof IntrospectionException)913throw (IntrospectionException) e;914if (e instanceof ReflectionException)915throw (ReflectionException) e;916if (e instanceof IOException)917throw (IOException) e;918throw newIOException("Got unexpected server exception: " + e, e);919}920}921922public boolean isInstanceOf(ObjectName name,923String className,924Subject delegationSubject)925throws InstanceNotFoundException, IOException {926927checkNonNull("ObjectName", name);928929try {930final Object params[] = new Object[] { name, className };931932if (logger.debugOn()) logger.debug("isInstanceOf",933"connectionId=" + connectionId934+", name="+name935+", className="+className);936937return ((Boolean)938doPrivilegedOperation(939IS_INSTANCE_OF,940params,941delegationSubject)).booleanValue();942} catch (PrivilegedActionException pe) {943Exception e = extractException(pe);944if (e instanceof InstanceNotFoundException)945throw (InstanceNotFoundException) e;946if (e instanceof IOException)947throw (IOException) e;948throw newIOException("Got unexpected server exception: " + e, e);949}950}951952@SuppressWarnings("rawtypes") // MarshalledObject953public Integer[] addNotificationListeners(ObjectName[] names,954MarshalledObject[] filters,955Subject[] delegationSubjects)956throws InstanceNotFoundException, IOException {957958if (names == null || filters == null) {959throw new IllegalArgumentException("Got null arguments.");960}961962Subject[] sbjs = (delegationSubjects != null) ? delegationSubjects :963new Subject[names.length];964if (names.length != filters.length || filters.length != sbjs.length) {965final String msg =966"The value lengths of 3 parameters are not same.";967throw new IllegalArgumentException(msg);968}969970for (int i=0; i<names.length; i++) {971if (names[i] == null) {972throw new IllegalArgumentException("Null Object name.");973}974}975976int i=0;977ClassLoader targetCl;978NotificationFilter[] filterValues =979new NotificationFilter[names.length];980Integer[] ids = new Integer[names.length];981final boolean debug=logger.debugOn();982983try {984for (; i<names.length; i++) {985targetCl = getClassLoaderFor(names[i]);986987if (debug) logger.debug("addNotificationListener"+988"(ObjectName,NotificationFilter)",989"connectionId=" + connectionId +990" unwrapping filter with target extended ClassLoader.");991992filterValues[i] =993unwrap(filters[i], targetCl, defaultClassLoader,994NotificationFilter.class, sbjs[i]);995996if (debug) logger.debug("addNotificationListener"+997"(ObjectName,NotificationFilter)",998"connectionId=" + connectionId999+", name=" + names[i]1000+", filter=" + filterValues[i]);10011002ids[i] = (Integer)1003doPrivilegedOperation(ADD_NOTIFICATION_LISTENERS,1004new Object[] { names[i],1005filterValues[i] },1006sbjs[i]);1007}10081009return ids;1010} catch (Exception e) {1011// remove all registered listeners1012for (int j=0; j<i; j++) {1013try {1014getServerNotifFwd().removeNotificationListener(names[j],1015ids[j]);1016} catch (Exception eee) {1017// strange1018}1019}10201021if (e instanceof PrivilegedActionException) {1022e = extractException(e);1023}10241025if (e instanceof ClassCastException) {1026throw (ClassCastException) e;1027} else if (e instanceof IOException) {1028throw (IOException)e;1029} else if (e instanceof InstanceNotFoundException) {1030throw (InstanceNotFoundException) e;1031} else if (e instanceof RuntimeException) {1032throw (RuntimeException) e;1033} else {1034throw newIOException("Got unexpected server exception: "+e,e);1035}1036}1037}10381039@SuppressWarnings("rawtypes") // MarshalledObject1040public void addNotificationListener(ObjectName name,1041ObjectName listener,1042MarshalledObject filter,1043MarshalledObject handback,1044Subject delegationSubject)1045throws InstanceNotFoundException, IOException {10461047checkNonNull("Target MBean name", name);1048checkNonNull("Listener MBean name", listener);10491050final NotificationFilter filterValue;1051final Object handbackValue;1052final boolean debug=logger.debugOn();10531054final ClassLoader targetCl = getClassLoaderFor(name);10551056if (debug) logger.debug("addNotificationListener"+1057"(ObjectName,ObjectName,NotificationFilter,Object)",1058"connectionId=" + connectionId1059+" unwrapping filter with target extended ClassLoader.");10601061filterValue =1062unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class, delegationSubject);10631064if (debug) logger.debug("addNotificationListener"+1065"(ObjectName,ObjectName,NotificationFilter,Object)",1066"connectionId=" + connectionId1067+" unwrapping handback with target extended ClassLoader.");10681069handbackValue =1070unwrap(handback, targetCl, defaultClassLoader, Object.class, delegationSubject);10711072try {1073final Object params[] =1074new Object[] { name, listener, filterValue, handbackValue };10751076if (debug) logger.debug("addNotificationListener"+1077"(ObjectName,ObjectName,NotificationFilter,Object)",1078"connectionId=" + connectionId1079+", name=" + name1080+", listenerName=" + listener1081+", filter=" + filterValue1082+", handback=" + handbackValue);10831084doPrivilegedOperation(1085ADD_NOTIFICATION_LISTENER_OBJECTNAME,1086params,1087delegationSubject);1088} catch (PrivilegedActionException pe) {1089Exception e = extractException(pe);1090if (e instanceof InstanceNotFoundException)1091throw (InstanceNotFoundException) e;1092if (e instanceof IOException)1093throw (IOException) e;1094throw newIOException("Got unexpected server exception: " + e, e);1095}1096}10971098public void removeNotificationListeners(ObjectName name,1099Integer[] listenerIDs,1100Subject delegationSubject)1101throws1102InstanceNotFoundException,1103ListenerNotFoundException,1104IOException {11051106if (name == null || listenerIDs == null)1107throw new IllegalArgumentException("Illegal null parameter");11081109for (int i = 0; i < listenerIDs.length; i++) {1110if (listenerIDs[i] == null)1111throw new IllegalArgumentException("Null listener ID");1112}11131114try {1115final Object params[] = new Object[] { name, listenerIDs };11161117if (logger.debugOn()) logger.debug("removeNotificationListener"+1118"(ObjectName,Integer[])",1119"connectionId=" + connectionId1120+", name=" + name1121+", listenerIDs=" + objects(listenerIDs));11221123doPrivilegedOperation(1124REMOVE_NOTIFICATION_LISTENER,1125params,1126delegationSubject);1127} catch (PrivilegedActionException pe) {1128Exception e = extractException(pe);1129if (e instanceof InstanceNotFoundException)1130throw (InstanceNotFoundException) e;1131if (e instanceof ListenerNotFoundException)1132throw (ListenerNotFoundException) e;1133if (e instanceof IOException)1134throw (IOException) e;1135throw newIOException("Got unexpected server exception: " + e, e);1136}1137}11381139public void removeNotificationListener(ObjectName name,1140ObjectName listener,1141Subject delegationSubject)1142throws1143InstanceNotFoundException,1144ListenerNotFoundException,1145IOException {11461147checkNonNull("Target MBean name", name);1148checkNonNull("Listener MBean name", listener);11491150try {1151final Object params[] = new Object[] { name, listener };11521153if (logger.debugOn()) logger.debug("removeNotificationListener"+1154"(ObjectName,ObjectName)",1155"connectionId=" + connectionId1156+", name=" + name1157+", listenerName=" + listener);11581159doPrivilegedOperation(1160REMOVE_NOTIFICATION_LISTENER_OBJECTNAME,1161params,1162delegationSubject);1163} catch (PrivilegedActionException pe) {1164Exception e = extractException(pe);1165if (e instanceof InstanceNotFoundException)1166throw (InstanceNotFoundException) e;1167if (e instanceof ListenerNotFoundException)1168throw (ListenerNotFoundException) e;1169if (e instanceof IOException)1170throw (IOException) e;1171throw newIOException("Got unexpected server exception: " + e, e);1172}1173}11741175@SuppressWarnings("rawtypes") // MarshalledObject1176public void removeNotificationListener(ObjectName name,1177ObjectName listener,1178MarshalledObject filter,1179MarshalledObject handback,1180Subject delegationSubject)1181throws1182InstanceNotFoundException,1183ListenerNotFoundException,1184IOException {11851186checkNonNull("Target MBean name", name);1187checkNonNull("Listener MBean name", listener);11881189final NotificationFilter filterValue;1190final Object handbackValue;1191final boolean debug=logger.debugOn();11921193final ClassLoader targetCl = getClassLoaderFor(name);11941195if (debug) logger.debug("removeNotificationListener"+1196"(ObjectName,ObjectName,NotificationFilter,Object)",1197"connectionId=" + connectionId1198+" unwrapping filter with target extended ClassLoader.");11991200filterValue =1201unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class, delegationSubject);12021203if (debug) logger.debug("removeNotificationListener"+1204"(ObjectName,ObjectName,NotificationFilter,Object)",1205"connectionId=" + connectionId1206+" unwrapping handback with target extended ClassLoader.");12071208handbackValue =1209unwrap(handback, targetCl, defaultClassLoader, Object.class, delegationSubject);12101211try {1212final Object params[] =1213new Object[] { name, listener, filterValue, handbackValue };12141215if (debug) logger.debug("removeNotificationListener"+1216"(ObjectName,ObjectName,NotificationFilter,Object)",1217"connectionId=" + connectionId1218+", name=" + name1219+", listenerName=" + listener1220+", filter=" + filterValue1221+", handback=" + handbackValue);12221223doPrivilegedOperation(1224REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK,1225params,1226delegationSubject);1227} catch (PrivilegedActionException pe) {1228Exception e = extractException(pe);1229if (e instanceof InstanceNotFoundException)1230throw (InstanceNotFoundException) e;1231if (e instanceof ListenerNotFoundException)1232throw (ListenerNotFoundException) e;1233if (e instanceof IOException)1234throw (IOException) e;1235throw newIOException("Got unexpected server exception: " + e, e);1236}1237}12381239@SuppressWarnings("removal")1240public NotificationResult fetchNotifications(long clientSequenceNumber,1241int maxNotifications,1242long timeout)1243throws IOException {12441245if (logger.debugOn()) logger.debug("fetchNotifications",1246"connectionId=" + connectionId1247+", timeout=" + timeout);12481249if (maxNotifications < 0 || timeout < 0)1250throw new IllegalArgumentException("Illegal negative argument");12511252final boolean serverTerminated =1253serverCommunicatorAdmin.reqIncoming();1254try {1255if (serverTerminated) {1256// we must not call fetchNotifs() if the server is1257// terminated (timeout elapsed).1258// returns null to force the client to stop fetching1259if (logger.debugOn()) logger.debug("fetchNotifications",1260"The notification server has been closed, "1261+ "returns null to force the client to stop fetching");1262return null;1263}1264final long csn = clientSequenceNumber;1265final int mn = maxNotifications;1266final long t = timeout;1267PrivilegedAction<NotificationResult> action =1268new PrivilegedAction<NotificationResult>() {1269public NotificationResult run() {1270return getServerNotifFwd().fetchNotifs(csn, t, mn);1271}1272};1273if (acc == null)1274return action.run();1275else1276return AccessController.doPrivileged(action, acc);1277} finally {1278serverCommunicatorAdmin.rspOutgoing();1279}1280}12811282/**1283* <p>Returns a string representation of this object. In general,1284* the <code>toString</code> method returns a string that1285* "textually represents" this object. The result should be a1286* concise but informative representation that is easy for a1287* person to read.</p>1288*1289* @return a String representation of this object.1290**/1291@Override1292public String toString() {1293return super.toString() + ": connectionId=" + connectionId;1294}12951296//------------------------------------------------------------------------1297// private classes1298//------------------------------------------------------------------------12991300private class PrivilegedOperation1301implements PrivilegedExceptionAction<Object> {13021303public PrivilegedOperation(int operation, Object[] params) {1304this.operation = operation;1305this.params = params;1306}13071308public Object run() throws Exception {1309return doOperation(operation, params);1310}13111312private int operation;1313private Object[] params;1314}13151316//------------------------------------------------------------------------1317// private classes1318//------------------------------------------------------------------------1319private class RMIServerCommunicatorAdmin extends ServerCommunicatorAdmin {1320public RMIServerCommunicatorAdmin(long timeout) {1321super(timeout);1322}13231324protected void doStop() {1325try {1326close();1327} catch (IOException ie) {1328logger.warning("RMIServerCommunicatorAdmin-doStop",1329"Failed to close: " + ie);1330logger.debug("RMIServerCommunicatorAdmin-doStop",ie);1331}1332}13331334}133513361337//------------------------------------------------------------------------1338// private methods1339//------------------------------------------------------------------------13401341@SuppressWarnings("removal")1342private ClassLoader getClassLoader(final ObjectName name)1343throws InstanceNotFoundException {1344try {1345return1346AccessController.doPrivileged(1347new PrivilegedExceptionAction<ClassLoader>() {1348public ClassLoader run() throws InstanceNotFoundException {1349return mbeanServer.getClassLoader(name);1350}1351},1352withPermissions(new MBeanPermission("*", "getClassLoader"))1353);1354} catch (PrivilegedActionException pe) {1355throw (InstanceNotFoundException) extractException(pe);1356}1357}13581359@SuppressWarnings("removal")1360private ClassLoader getClassLoaderFor(final ObjectName name)1361throws InstanceNotFoundException {1362try {1363return (ClassLoader)1364AccessController.doPrivileged(1365new PrivilegedExceptionAction<Object>() {1366public Object run() throws InstanceNotFoundException {1367return mbeanServer.getClassLoaderFor(name);1368}1369},1370withPermissions(new MBeanPermission("*", "getClassLoaderFor"))1371);1372} catch (PrivilegedActionException pe) {1373throw (InstanceNotFoundException) extractException(pe);1374}1375}13761377@SuppressWarnings("removal")1378private Object doPrivilegedOperation(final int operation,1379final Object[] params,1380final Subject delegationSubject)1381throws PrivilegedActionException, IOException {13821383serverCommunicatorAdmin.reqIncoming();1384try {13851386final AccessControlContext reqACC;1387if (delegationSubject == null)1388reqACC = acc;1389else {1390if (subject == null) {1391final String msg =1392"Subject delegation cannot be enabled unless " +1393"an authenticated subject is put in place";1394throw new SecurityException(msg);1395}1396reqACC = subjectDelegator.delegatedContext(1397acc, delegationSubject, removeCallerContext);1398}13991400PrivilegedOperation op =1401new PrivilegedOperation(operation, params);1402if (reqACC == null) {1403try {1404return op.run();1405} catch (Exception e) {1406if (e instanceof RuntimeException)1407throw (RuntimeException) e;1408throw new PrivilegedActionException(e);1409}1410} else {1411return AccessController.doPrivileged(op, reqACC);1412}1413} catch (Error e) {1414throw new JMXServerErrorException(e.toString(),e);1415} finally {1416serverCommunicatorAdmin.rspOutgoing();1417}1418}14191420private Object doOperation(int operation, Object[] params)1421throws Exception {14221423switch (operation) {14241425case CREATE_MBEAN:1426return mbeanServer.createMBean((String)params[0],1427(ObjectName)params[1]);14281429case CREATE_MBEAN_LOADER:1430return mbeanServer.createMBean((String)params[0],1431(ObjectName)params[1],1432(ObjectName)params[2]);14331434case CREATE_MBEAN_PARAMS:1435return mbeanServer.createMBean((String)params[0],1436(ObjectName)params[1],1437(Object[])params[2],1438(String[])params[3]);14391440case CREATE_MBEAN_LOADER_PARAMS:1441return mbeanServer.createMBean((String)params[0],1442(ObjectName)params[1],1443(ObjectName)params[2],1444(Object[])params[3],1445(String[])params[4]);14461447case GET_ATTRIBUTE:1448return mbeanServer.getAttribute((ObjectName)params[0],1449(String)params[1]);14501451case GET_ATTRIBUTES:1452return mbeanServer.getAttributes((ObjectName)params[0],1453(String[])params[1]);14541455case GET_DEFAULT_DOMAIN:1456return mbeanServer.getDefaultDomain();14571458case GET_DOMAINS:1459return mbeanServer.getDomains();14601461case GET_MBEAN_COUNT:1462return mbeanServer.getMBeanCount();14631464case GET_MBEAN_INFO:1465return mbeanServer.getMBeanInfo((ObjectName)params[0]);14661467case GET_OBJECT_INSTANCE:1468return mbeanServer.getObjectInstance((ObjectName)params[0]);14691470case INVOKE:1471return mbeanServer.invoke((ObjectName)params[0],1472(String)params[1],1473(Object[])params[2],1474(String[])params[3]);14751476case IS_INSTANCE_OF:1477return mbeanServer.isInstanceOf((ObjectName)params[0],1478(String)params[1])1479? Boolean.TRUE : Boolean.FALSE;14801481case IS_REGISTERED:1482return mbeanServer.isRegistered((ObjectName)params[0])1483? Boolean.TRUE : Boolean.FALSE;14841485case QUERY_MBEANS:1486return mbeanServer.queryMBeans((ObjectName)params[0],1487(QueryExp)params[1]);14881489case QUERY_NAMES:1490return mbeanServer.queryNames((ObjectName)params[0],1491(QueryExp)params[1]);14921493case SET_ATTRIBUTE:1494mbeanServer.setAttribute((ObjectName)params[0],1495(Attribute)params[1]);1496return null;14971498case SET_ATTRIBUTES:1499return mbeanServer.setAttributes((ObjectName)params[0],1500(AttributeList)params[1]);15011502case UNREGISTER_MBEAN:1503mbeanServer.unregisterMBean((ObjectName)params[0]);1504return null;15051506case ADD_NOTIFICATION_LISTENERS:1507return getServerNotifFwd().addNotificationListener(1508(ObjectName)params[0],1509(NotificationFilter)params[1]);15101511case ADD_NOTIFICATION_LISTENER_OBJECTNAME:1512mbeanServer.addNotificationListener((ObjectName)params[0],1513(ObjectName)params[1],1514(NotificationFilter)params[2],1515params[3]);1516return null;15171518case REMOVE_NOTIFICATION_LISTENER:1519getServerNotifFwd().removeNotificationListener(1520(ObjectName)params[0],1521(Integer[])params[1]);1522return null;15231524case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME:1525mbeanServer.removeNotificationListener((ObjectName)params[0],1526(ObjectName)params[1]);1527return null;15281529case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK:1530mbeanServer.removeNotificationListener(1531(ObjectName)params[0],1532(ObjectName)params[1],1533(NotificationFilter)params[2],1534params[3]);1535return null;15361537default:1538throw new IllegalArgumentException("Invalid operation");1539}1540}15411542private static class SetCcl implements PrivilegedExceptionAction<ClassLoader> {1543private final ClassLoader classLoader;15441545SetCcl(ClassLoader classLoader) {1546this.classLoader = classLoader;1547}15481549public ClassLoader run() {1550Thread currentThread = Thread.currentThread();1551ClassLoader old = currentThread.getContextClassLoader();1552currentThread.setContextClassLoader(classLoader);1553return old;1554}1555}15561557@SuppressWarnings("removal")1558private <T> T unwrap(final MarshalledObject<?> mo,1559final ClassLoader cl,1560final Class<T> wrappedClass,1561Subject delegationSubject)1562throws IOException {1563if (mo == null) {1564return null;1565}1566try {1567final ClassLoader old = AccessController.doPrivileged(new SetCcl(cl));1568try{1569final AccessControlContext reqACC;1570if (delegationSubject == null)1571reqACC = acc;1572else {1573if (subject == null) {1574final String msg =1575"Subject delegation cannot be enabled unless " +1576"an authenticated subject is put in place";1577throw new SecurityException(msg);1578}1579reqACC = subjectDelegator.delegatedContext(1580acc, delegationSubject, removeCallerContext);1581}1582if(reqACC != null){1583return AccessController.doPrivileged(1584(PrivilegedExceptionAction<T>) () ->1585wrappedClass.cast(mo.get()), reqACC);1586}else{1587return wrappedClass.cast(mo.get());1588}1589}finally{1590AccessController.doPrivileged(new SetCcl(old));1591}1592} catch (PrivilegedActionException pe) {1593Exception e = extractException(pe);1594if (e instanceof IOException) {1595throw (IOException) e;1596}1597if (e instanceof ClassNotFoundException) {1598throw new UnmarshalException(e.toString(), e);1599}1600logger.warning("unwrap", "Failed to unmarshall object: " + e);1601logger.debug("unwrap", e);1602}catch (ClassNotFoundException ex) {1603logger.warning("unwrap", "Failed to unmarshall object: " + ex);1604logger.debug("unwrap", ex);1605throw new UnmarshalException(ex.toString(), ex);1606}1607return null;1608}16091610private <T> T unwrap(final MarshalledObject<?> mo,1611final ClassLoader cl1,1612final ClassLoader cl2,1613final Class<T> wrappedClass,1614Subject delegationSubject)1615throws IOException {1616if (mo == null) {1617return null;1618}1619try {1620@SuppressWarnings("removal")1621ClassLoader orderCL = AccessController.doPrivileged(1622new PrivilegedExceptionAction<ClassLoader>() {1623public ClassLoader run() throws Exception {1624return new CombinedClassLoader(Thread.currentThread().getContextClassLoader(),1625new OrderClassLoaders(cl1, cl2));1626}1627}1628);1629return unwrap(mo, orderCL, wrappedClass,delegationSubject);1630} catch (PrivilegedActionException pe) {1631Exception e = extractException(pe);1632if (e instanceof IOException) {1633throw (IOException) e;1634}1635if (e instanceof ClassNotFoundException) {1636throw new UnmarshalException(e.toString(), e);1637}1638logger.warning("unwrap", "Failed to unmarshall object: " + e);1639logger.debug("unwrap", e);1640}1641return null;1642}16431644/**1645* Construct a new IOException with a nested exception.1646* The nested exception is set only if JDK {@literal >= 1.4}1647*/1648private static IOException newIOException(String message,1649Throwable cause) {1650final IOException x = new IOException(message);1651return EnvHelp.initCause(x,cause);1652}16531654/**1655* Iterate until we extract the real exception1656* from a stack of PrivilegedActionExceptions.1657*/1658private static Exception extractException(Exception e) {1659while (e instanceof PrivilegedActionException) {1660e = ((PrivilegedActionException)e).getException();1661}1662return e;1663}16641665private static final Object[] NO_OBJECTS = new Object[0];1666private static final String[] NO_STRINGS = new String[0];16671668/*1669* The JMX spec doesn't explicitly say that a null Object[] or1670* String[] in e.g. MBeanServer.invoke is equivalent to an empty1671* array, but the RI behaves that way. In the interests of1672* maximal interoperability, we make it so even when we're1673* connected to some other JMX implementation that might not do1674* that. This should be clarified in the next version of JMX.1675*/1676private static Object[] nullIsEmpty(Object[] array) {1677return (array == null) ? NO_OBJECTS : array;1678}16791680private static String[] nullIsEmpty(String[] array) {1681return (array == null) ? NO_STRINGS : array;1682}16831684/*1685* Similarly, the JMX spec says for some but not all methods in1686* MBeanServer that take an ObjectName target, that if it's null1687* you get this exception. We specify it for all of them, and1688* make it so for the ones where it's not specified in JMX even if1689* the JMX implementation doesn't do so.1690*/1691private static void checkNonNull(String what, Object x) {1692if (x == null) {1693RuntimeException wrapped =1694new IllegalArgumentException(what + " must not be null");1695throw new RuntimeOperationsException(wrapped);1696}1697}16981699//------------------------------------------------------------------------1700// private variables1701//------------------------------------------------------------------------17021703private final Subject subject;17041705private final SubjectDelegator subjectDelegator;17061707private final boolean removeCallerContext;17081709@SuppressWarnings("removal")1710private final AccessControlContext acc;17111712private final RMIServerImpl rmiServer;17131714private final MBeanServer mbeanServer;17151716private final ClassLoader defaultClassLoader;17171718private final ClassLoader defaultContextClassLoader;17191720private final ClassLoaderWithRepository classLoaderWithRepository;17211722private boolean terminated = false;17231724private final String connectionId;17251726private final ServerCommunicatorAdmin serverCommunicatorAdmin;17271728// Method IDs for doOperation1729//---------------------------17301731private static final int1732ADD_NOTIFICATION_LISTENERS = 1;1733private static final int1734ADD_NOTIFICATION_LISTENER_OBJECTNAME = 2;1735private static final int1736CREATE_MBEAN = 3;1737private static final int1738CREATE_MBEAN_PARAMS = 4;1739private static final int1740CREATE_MBEAN_LOADER = 5;1741private static final int1742CREATE_MBEAN_LOADER_PARAMS = 6;1743private static final int1744GET_ATTRIBUTE = 7;1745private static final int1746GET_ATTRIBUTES = 8;1747private static final int1748GET_DEFAULT_DOMAIN = 9;1749private static final int1750GET_DOMAINS = 10;1751private static final int1752GET_MBEAN_COUNT = 11;1753private static final int1754GET_MBEAN_INFO = 12;1755private static final int1756GET_OBJECT_INSTANCE = 13;1757private static final int1758INVOKE = 14;1759private static final int1760IS_INSTANCE_OF = 15;1761private static final int1762IS_REGISTERED = 16;1763private static final int1764QUERY_MBEANS = 17;1765private static final int1766QUERY_NAMES = 18;1767private static final int1768REMOVE_NOTIFICATION_LISTENER = 19;1769private static final int1770REMOVE_NOTIFICATION_LISTENER_OBJECTNAME = 20;1771private static final int1772REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK = 21;1773private static final int1774SET_ATTRIBUTE = 22;1775private static final int1776SET_ATTRIBUTES = 23;1777private static final int1778UNREGISTER_MBEAN = 24;17791780// SERVER NOTIFICATION1781//--------------------17821783private ServerNotifForwarder serverNotifForwarder;1784private Map<String, ?> env;17851786// TRACES & DEBUG1787//---------------17881789private static String objects(final Object[] objs) {1790if (objs == null)1791return "null";1792else1793return Arrays.asList(objs).toString();1794}17951796private static String strings(final String[] strs) {1797return objects(strs);1798}17991800private static final ClassLogger logger =1801new ClassLogger("javax.management.remote.rmi", "RMIConnectionImpl");18021803private static final class CombinedClassLoader extends ClassLoader {18041805private static final class ClassLoaderWrapper extends ClassLoader {1806ClassLoaderWrapper(ClassLoader cl) {1807super(cl);1808}18091810@Override1811protected Class<?> loadClass(String name, boolean resolve)1812throws ClassNotFoundException {1813return super.loadClass(name, resolve);1814}1815};18161817final ClassLoaderWrapper defaultCL;18181819private CombinedClassLoader(ClassLoader parent, ClassLoader defaultCL) {1820super(parent);1821this.defaultCL = new ClassLoaderWrapper(defaultCL);1822}18231824@Override1825protected Class<?> loadClass(String name, boolean resolve)1826throws ClassNotFoundException {1827ReflectUtil.checkPackageAccess(name);1828try {1829super.loadClass(name, resolve);1830} catch(Exception e) {1831for(Throwable t = e; t != null; t = t.getCause()) {1832if(t instanceof SecurityException) {1833throw t==e?(SecurityException)t:new SecurityException(t.getMessage(), e);1834}1835}1836}1837final Class<?> cl = defaultCL.loadClass(name, resolve);1838return cl;1839}18401841}1842}184318441845