< prev index next >

src/jdk.management.agent/share/classes/sun/management/jmxremote/ConnectorBootstrap.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  55 import java.util.Iterator;
  56 import java.util.Map;
  57 import java.util.Properties;
  58 import java.util.Set;
  59 import java.util.StringTokenizer;
  60 
  61 import javax.management.MBeanServer;
  62 import javax.management.remote.JMXAuthenticator;
  63 import javax.management.remote.JMXConnectorServer;
  64 import javax.management.remote.JMXConnectorServerFactory;
  65 import javax.management.remote.JMXServiceURL;
  66 import javax.management.remote.rmi.RMIConnectorServer;
  67 import javax.net.ssl.KeyManagerFactory;
  68 import javax.net.ssl.SSLContext;
  69 import javax.net.ssl.SSLSocket;
  70 import javax.net.ssl.SSLSocketFactory;
  71 import javax.net.ssl.TrustManagerFactory;
  72 import javax.rmi.ssl.SslRMIClientSocketFactory;
  73 import javax.rmi.ssl.SslRMIServerSocketFactory;
  74 import javax.security.auth.Subject;
  75 
  76 import com.sun.jmx.remote.internal.rmi.RMIExporter;

  77 import com.sun.jmx.remote.security.JMXPluggableAuthenticator;
  78 
  79 import jdk.internal.agent.Agent;
  80 import jdk.internal.agent.AgentConfigurationError;
  81 import static jdk.internal.agent.AgentConfigurationError.*;
  82 import jdk.internal.agent.ConnectorAddressLink;
  83 import jdk.internal.agent.FileSystem;
  84 import sun.rmi.server.UnicastRef;
  85 import sun.rmi.server.UnicastServerRef;
  86 import sun.rmi.server.UnicastServerRef2;
  87 
  88 /**
  89  * This class initializes and starts the RMIConnectorServer for JSR 163
  90  * JMX Monitoring.
  91  **/
  92 public final class ConnectorBootstrap {
  93 
  94     /**
  95      * Default values for JMX configuration properties.
  96      **/
  97     public static interface DefaultValues {
  98 
  99         public static final String PORT = "0";
 100         public static final String CONFIG_FILE_NAME = "management.properties";
 101         public static final String USE_SSL = "true";
 102         public static final String USE_LOCAL_ONLY = "true";
 103         public static final String USE_REGISTRY_SSL = "false";
 104         public static final String USE_AUTHENTICATION = "true";
 105         public static final String PASSWORD_FILE_NAME = "jmxremote.password";

 106         public static final String ACCESS_FILE_NAME = "jmxremote.access";
 107         public static final String SSL_NEED_CLIENT_AUTH = "false";
 108     }
 109 
 110     /**
 111      * Names of JMX configuration properties.
 112      **/
 113     public static interface PropertyNames {
 114 
 115         public static final String PORT =
 116                 "com.sun.management.jmxremote.port";
 117         public static final String HOST =
 118                 "com.sun.management.jmxremote.host";
 119         public static final String RMI_PORT =
 120                 "com.sun.management.jmxremote.rmi.port";
 121         public static final String CONFIG_FILE_NAME =
 122                 "com.sun.management.config.file";
 123         public static final String USE_LOCAL_ONLY =
 124                 "com.sun.management.jmxremote.local.only";
 125         public static final String USE_SSL =
 126                 "com.sun.management.jmxremote.ssl";
 127         public static final String USE_REGISTRY_SSL =
 128                 "com.sun.management.jmxremote.registry.ssl";
 129         public static final String USE_AUTHENTICATION =
 130                 "com.sun.management.jmxremote.authenticate";
 131         public static final String PASSWORD_FILE_NAME =
 132                 "com.sun.management.jmxremote.password.file";


 133         public static final String ACCESS_FILE_NAME =
 134                 "com.sun.management.jmxremote.access.file";
 135         public static final String LOGIN_CONFIG_NAME =
 136                 "com.sun.management.jmxremote.login.config";
 137         public static final String SSL_ENABLED_CIPHER_SUITES =
 138                 "com.sun.management.jmxremote.ssl.enabled.cipher.suites";
 139         public static final String SSL_ENABLED_PROTOCOLS =
 140                 "com.sun.management.jmxremote.ssl.enabled.protocols";
 141         public static final String SSL_NEED_CLIENT_AUTH =
 142                 "com.sun.management.jmxremote.ssl.need.client.auth";
 143         public static final String SSL_CONFIG_FILE_NAME =
 144                 "com.sun.management.jmxremote.ssl.config.file";
 145     }
 146 
 147     /**
 148      * JMXConnectorServer associated data.
 149      */
 150     private static class JMXConnectorServerData {
 151 
 152         public JMXConnectorServerData(


 393             StringTokenizer st = new StringTokenizer(enabledProtocols, ",");
 394             int tokens = st.countTokens();
 395             enabledProtocolsList = new String[tokens];
 396             for (int i = 0; i < tokens; i++) {
 397                 enabledProtocolsList[i] = st.nextToken();
 398             }
 399         }
 400 
 401         final String sslNeedClientAuthStr =
 402                 props.getProperty(PropertyNames.SSL_NEED_CLIENT_AUTH,
 403                 DefaultValues.SSL_NEED_CLIENT_AUTH);
 404         final boolean sslNeedClientAuth =
 405                 Boolean.valueOf(sslNeedClientAuthStr).booleanValue();
 406 
 407         // Read SSL config file name
 408         final String sslConfigFileName =
 409                 props.getProperty(PropertyNames.SSL_CONFIG_FILE_NAME);
 410 
 411         String loginConfigName = null;
 412         String passwordFileName = null;

 413         String accessFileName = null;
 414 
 415         // Initialize settings when authentication is active
 416         if (useAuthentication) {
 417 
 418             // Get non-default login configuration
 419             loginConfigName =
 420                     props.getProperty(PropertyNames.LOGIN_CONFIG_NAME);
 421 
 422             if (loginConfigName == null) {
 423                 // Get password file
 424                 passwordFileName =
 425                         props.getProperty(PropertyNames.PASSWORD_FILE_NAME,
 426                         getDefaultFileName(DefaultValues.PASSWORD_FILE_NAME));





 427                 checkPasswordFile(passwordFileName);
 428             }
 429 
 430             // Get access file
 431             accessFileName = props.getProperty(PropertyNames.ACCESS_FILE_NAME,
 432                     getDefaultFileName(DefaultValues.ACCESS_FILE_NAME));
 433             checkAccessFile(accessFileName);
 434         }
 435 
 436         final String bindAddress =
 437                 props.getProperty(PropertyNames.HOST);
 438 
 439         if (logger.isLoggable(Level.DEBUG)) {
 440             logger.log(Level.DEBUG, "startRemoteConnectorServer",
 441                     Agent.getText("jmxremote.ConnectorBootstrap.starting") +
 442                     "\n\t" + PropertyNames.PORT + "=" + port +
 443                     (bindAddress == null ? "" : "\n\t" + PropertyNames.HOST + "=" + bindAddress) +
 444                     "\n\t" + PropertyNames.RMI_PORT + "=" + rmiPort +
 445                     "\n\t" + PropertyNames.USE_SSL + "=" + useSsl +
 446                     "\n\t" + PropertyNames.USE_REGISTRY_SSL + "=" + useRegistrySsl +


 454                     "\n\t" + PropertyNames.USE_AUTHENTICATION + "=" +
 455                     useAuthentication +
 456                     (useAuthentication ? (loginConfigName == null ? ("\n\t" + PropertyNames.PASSWORD_FILE_NAME + "=" +
 457                     passwordFileName) : ("\n\t" + PropertyNames.LOGIN_CONFIG_NAME + "=" +
 458                     loginConfigName)) : "\n\t" +
 459                     Agent.getText("jmxremote.ConnectorBootstrap.noAuthentication")) +
 460                     (useAuthentication ? ("\n\t" + PropertyNames.ACCESS_FILE_NAME + "=" +
 461                     accessFileName) : "") +
 462                     "");
 463         }
 464 
 465         final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
 466         JMXConnectorServer cs = null;
 467         JMXServiceURL url = null;
 468         try {
 469             final JMXConnectorServerData data = exportMBeanServer(
 470                     mbs, port, rmiPort, useSsl, useRegistrySsl,
 471                     sslConfigFileName, enabledCipherSuitesList,
 472                     enabledProtocolsList, sslNeedClientAuth,
 473                     useAuthentication, loginConfigName,
 474                     passwordFileName, accessFileName, bindAddress);
 475             cs = data.jmxConnectorServer;
 476             url = data.jmxRemoteURL;
 477             config("startRemoteConnectorServer",
 478                    Agent.getText("jmxremote.ConnectorBootstrap.ready",
 479                    url.toString()));
 480         } catch (Exception e) {
 481             throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
 482         }
 483         try {
 484             // Export remote connector address and associated configuration
 485             // properties to the instrumentation buffer.
 486             Map<String, String> properties = new HashMap<>();
 487             properties.put("remoteAddress", url.toString());
 488             properties.put("authenticate", useAuthenticationStr);
 489             properties.put("ssl", useSslStr);
 490             properties.put("sslRegistry", useRegistrySslStr);
 491             properties.put("sslNeedClientAuth", sslNeedClientAuthStr);
 492             ConnectorAddressLink.exportRemote(properties);
 493         } catch (Exception e) {
 494             // Remote connector server started but unable to export remote


 711                         sslNeedClientAuth, bindAddress);
 712             } catch (Exception e) {
 713                 throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
 714             }
 715         }
 716     }
 717 
 718     private static JMXConnectorServerData exportMBeanServer(
 719             MBeanServer mbs,
 720             int port,
 721             int rmiPort,
 722             boolean useSsl,
 723             boolean useRegistrySsl,
 724             String sslConfigFileName,
 725             String[] enabledCipherSuites,
 726             String[] enabledProtocols,
 727             boolean sslNeedClientAuth,
 728             boolean useAuthentication,
 729             String loginConfigName,
 730             String passwordFileName,

 731             String accessFileName,
 732             String bindAddress)
 733             throws IOException, MalformedURLException {
 734 
 735         /* Make sure we use non-guessable RMI object IDs.  Otherwise
 736          * attackers could hijack open connections by guessing their
 737          * IDs.  */
 738         System.setProperty("java.rmi.server.randomIDs", "true");
 739 
 740         JMXServiceURL url = new JMXServiceURL("rmi", bindAddress, rmiPort);
 741 
 742         Map<String, Object> env = new HashMap<>();
 743 
 744         PermanentExporter exporter = new PermanentExporter();
 745 
 746         env.put(RMIExporter.EXPORTER_ATTRIBUTE, exporter);
 747         env.put(RMIConnectorServer.CREDENTIAL_TYPES, new String[]{
 748             String[].class.getName(), String.class.getName()
 749         });
 750 
 751         boolean useSocketFactory = bindAddress != null && !useSsl;
 752 
 753         if (useAuthentication) {
 754             if (loginConfigName != null) {
 755                 env.put("jmx.remote.x.login.config", loginConfigName);
 756             }
 757             if (passwordFileName != null) {
 758                 env.put("jmx.remote.x.password.file", passwordFileName);



 759             }
 760 
 761             env.put("jmx.remote.x.access.file", accessFileName);
 762 
 763             if (env.get("jmx.remote.x.password.file") != null ||
 764                     env.get("jmx.remote.x.login.config") != null) {
 765                 env.put(JMXConnectorServer.AUTHENTICATOR,
 766                         new AccessFileCheckerAuthenticator(env));
 767             }
 768         }
 769 
 770         RMIClientSocketFactory csf = null;
 771         RMIServerSocketFactory ssf = null;
 772 
 773         if (useSsl || useRegistrySsl) {
 774             csf = new SslRMIClientSocketFactory();
 775             ssf = createSslRMIServerSocketFactory(
 776                     sslConfigFileName, enabledCipherSuites,
 777                     enabledProtocols, sslNeedClientAuth, bindAddress);
 778         }


   1 /*
   2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  55 import java.util.Iterator;
  56 import java.util.Map;
  57 import java.util.Properties;
  58 import java.util.Set;
  59 import java.util.StringTokenizer;
  60 
  61 import javax.management.MBeanServer;
  62 import javax.management.remote.JMXAuthenticator;
  63 import javax.management.remote.JMXConnectorServer;
  64 import javax.management.remote.JMXConnectorServerFactory;
  65 import javax.management.remote.JMXServiceURL;
  66 import javax.management.remote.rmi.RMIConnectorServer;
  67 import javax.net.ssl.KeyManagerFactory;
  68 import javax.net.ssl.SSLContext;
  69 import javax.net.ssl.SSLSocket;
  70 import javax.net.ssl.SSLSocketFactory;
  71 import javax.net.ssl.TrustManagerFactory;
  72 import javax.rmi.ssl.SslRMIClientSocketFactory;
  73 import javax.rmi.ssl.SslRMIServerSocketFactory;
  74 import javax.security.auth.Subject;

  75 import com.sun.jmx.remote.internal.rmi.RMIExporter;
  76 import com.sun.jmx.remote.security.HashedPasswordManager;
  77 import com.sun.jmx.remote.security.JMXPluggableAuthenticator;

  78 import jdk.internal.agent.Agent;
  79 import jdk.internal.agent.AgentConfigurationError;
  80 import static jdk.internal.agent.AgentConfigurationError.*;
  81 import jdk.internal.agent.ConnectorAddressLink;
  82 import jdk.internal.agent.FileSystem;
  83 import sun.rmi.server.UnicastRef;
  84 import sun.rmi.server.UnicastServerRef;
  85 import sun.rmi.server.UnicastServerRef2;
  86 
  87 /**
  88  * This class initializes and starts the RMIConnectorServer for JSR 163
  89  * JMX Monitoring.
  90  **/
  91 public final class ConnectorBootstrap {
  92 
  93     /**
  94      * Default values for JMX configuration properties.
  95      **/
  96     public static interface DefaultValues {
  97 
  98         public static final String PORT = "0";
  99         public static final String CONFIG_FILE_NAME = "management.properties";
 100         public static final String USE_SSL = "true";
 101         public static final String USE_LOCAL_ONLY = "true";
 102         public static final String USE_REGISTRY_SSL = "false";
 103         public static final String USE_AUTHENTICATION = "true";
 104         public static final String PASSWORD_FILE_NAME = "jmxremote.password";
 105         public static final String HASH_PASSWORDS = "true";
 106         public static final String ACCESS_FILE_NAME = "jmxremote.access";
 107         public static final String SSL_NEED_CLIENT_AUTH = "false";
 108     }
 109 
 110     /**
 111      * Names of JMX configuration properties.
 112      **/
 113     public static interface PropertyNames {
 114 
 115         public static final String PORT =
 116                 "com.sun.management.jmxremote.port";
 117         public static final String HOST =
 118                 "com.sun.management.jmxremote.host";
 119         public static final String RMI_PORT =
 120                 "com.sun.management.jmxremote.rmi.port";
 121         public static final String CONFIG_FILE_NAME =
 122                 "com.sun.management.config.file";
 123         public static final String USE_LOCAL_ONLY =
 124                 "com.sun.management.jmxremote.local.only";
 125         public static final String USE_SSL =
 126                 "com.sun.management.jmxremote.ssl";
 127         public static final String USE_REGISTRY_SSL =
 128                 "com.sun.management.jmxremote.registry.ssl";
 129         public static final String USE_AUTHENTICATION =
 130                 "com.sun.management.jmxremote.authenticate";
 131         public static final String PASSWORD_FILE_NAME =
 132                 "com.sun.management.jmxremote.password.file";
 133         public static final String HASH_PASSWORDS
 134                 = "com.sun.management.jmxremote.password.hashpasswords";
 135         public static final String ACCESS_FILE_NAME =
 136                 "com.sun.management.jmxremote.access.file";
 137         public static final String LOGIN_CONFIG_NAME =
 138                 "com.sun.management.jmxremote.login.config";
 139         public static final String SSL_ENABLED_CIPHER_SUITES =
 140                 "com.sun.management.jmxremote.ssl.enabled.cipher.suites";
 141         public static final String SSL_ENABLED_PROTOCOLS =
 142                 "com.sun.management.jmxremote.ssl.enabled.protocols";
 143         public static final String SSL_NEED_CLIENT_AUTH =
 144                 "com.sun.management.jmxremote.ssl.need.client.auth";
 145         public static final String SSL_CONFIG_FILE_NAME =
 146                 "com.sun.management.jmxremote.ssl.config.file";
 147     }
 148 
 149     /**
 150      * JMXConnectorServer associated data.
 151      */
 152     private static class JMXConnectorServerData {
 153 
 154         public JMXConnectorServerData(


 395             StringTokenizer st = new StringTokenizer(enabledProtocols, ",");
 396             int tokens = st.countTokens();
 397             enabledProtocolsList = new String[tokens];
 398             for (int i = 0; i < tokens; i++) {
 399                 enabledProtocolsList[i] = st.nextToken();
 400             }
 401         }
 402 
 403         final String sslNeedClientAuthStr =
 404                 props.getProperty(PropertyNames.SSL_NEED_CLIENT_AUTH,
 405                 DefaultValues.SSL_NEED_CLIENT_AUTH);
 406         final boolean sslNeedClientAuth =
 407                 Boolean.valueOf(sslNeedClientAuthStr).booleanValue();
 408 
 409         // Read SSL config file name
 410         final String sslConfigFileName =
 411                 props.getProperty(PropertyNames.SSL_CONFIG_FILE_NAME);
 412 
 413         String loginConfigName = null;
 414         String passwordFileName = null;
 415         boolean shouldHashPasswords = true;
 416         String accessFileName = null;
 417 
 418         // Initialize settings when authentication is active
 419         if (useAuthentication) {
 420 
 421             // Get non-default login configuration
 422             loginConfigName =
 423                     props.getProperty(PropertyNames.LOGIN_CONFIG_NAME);
 424 
 425             if (loginConfigName == null) {
 426                 // Get password file
 427                 passwordFileName =
 428                         props.getProperty(PropertyNames.PASSWORD_FILE_NAME,
 429                         getDefaultFileName(DefaultValues.PASSWORD_FILE_NAME));
 430                 String hashPasswords
 431                         = props.getProperty(PropertyNames.HASH_PASSWORDS,
 432                                 DefaultValues.HASH_PASSWORDS);
 433                 shouldHashPasswords = Boolean.parseBoolean(hashPasswords);
 434 
 435                 checkPasswordFile(passwordFileName);
 436             }
 437 
 438             // Get access file
 439             accessFileName = props.getProperty(PropertyNames.ACCESS_FILE_NAME,
 440                     getDefaultFileName(DefaultValues.ACCESS_FILE_NAME));
 441             checkAccessFile(accessFileName);
 442         }
 443 
 444         final String bindAddress =
 445                 props.getProperty(PropertyNames.HOST);
 446 
 447         if (logger.isLoggable(Level.DEBUG)) {
 448             logger.log(Level.DEBUG, "startRemoteConnectorServer",
 449                     Agent.getText("jmxremote.ConnectorBootstrap.starting") +
 450                     "\n\t" + PropertyNames.PORT + "=" + port +
 451                     (bindAddress == null ? "" : "\n\t" + PropertyNames.HOST + "=" + bindAddress) +
 452                     "\n\t" + PropertyNames.RMI_PORT + "=" + rmiPort +
 453                     "\n\t" + PropertyNames.USE_SSL + "=" + useSsl +
 454                     "\n\t" + PropertyNames.USE_REGISTRY_SSL + "=" + useRegistrySsl +


 462                     "\n\t" + PropertyNames.USE_AUTHENTICATION + "=" +
 463                     useAuthentication +
 464                     (useAuthentication ? (loginConfigName == null ? ("\n\t" + PropertyNames.PASSWORD_FILE_NAME + "=" +
 465                     passwordFileName) : ("\n\t" + PropertyNames.LOGIN_CONFIG_NAME + "=" +
 466                     loginConfigName)) : "\n\t" +
 467                     Agent.getText("jmxremote.ConnectorBootstrap.noAuthentication")) +
 468                     (useAuthentication ? ("\n\t" + PropertyNames.ACCESS_FILE_NAME + "=" +
 469                     accessFileName) : "") +
 470                     "");
 471         }
 472 
 473         final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
 474         JMXConnectorServer cs = null;
 475         JMXServiceURL url = null;
 476         try {
 477             final JMXConnectorServerData data = exportMBeanServer(
 478                     mbs, port, rmiPort, useSsl, useRegistrySsl,
 479                     sslConfigFileName, enabledCipherSuitesList,
 480                     enabledProtocolsList, sslNeedClientAuth,
 481                     useAuthentication, loginConfigName,
 482                     passwordFileName, shouldHashPasswords, accessFileName, bindAddress);
 483             cs = data.jmxConnectorServer;
 484             url = data.jmxRemoteURL;
 485             config("startRemoteConnectorServer",
 486                    Agent.getText("jmxremote.ConnectorBootstrap.ready",
 487                    url.toString()));
 488         } catch (Exception e) {
 489             throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
 490         }
 491         try {
 492             // Export remote connector address and associated configuration
 493             // properties to the instrumentation buffer.
 494             Map<String, String> properties = new HashMap<>();
 495             properties.put("remoteAddress", url.toString());
 496             properties.put("authenticate", useAuthenticationStr);
 497             properties.put("ssl", useSslStr);
 498             properties.put("sslRegistry", useRegistrySslStr);
 499             properties.put("sslNeedClientAuth", sslNeedClientAuthStr);
 500             ConnectorAddressLink.exportRemote(properties);
 501         } catch (Exception e) {
 502             // Remote connector server started but unable to export remote


 719                         sslNeedClientAuth, bindAddress);
 720             } catch (Exception e) {
 721                 throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
 722             }
 723         }
 724     }
 725 
 726     private static JMXConnectorServerData exportMBeanServer(
 727             MBeanServer mbs,
 728             int port,
 729             int rmiPort,
 730             boolean useSsl,
 731             boolean useRegistrySsl,
 732             String sslConfigFileName,
 733             String[] enabledCipherSuites,
 734             String[] enabledProtocols,
 735             boolean sslNeedClientAuth,
 736             boolean useAuthentication,
 737             String loginConfigName,
 738             String passwordFileName,
 739             boolean shouldHashPasswords,
 740             String accessFileName,
 741             String bindAddress)
 742             throws IOException, MalformedURLException {
 743 
 744         /* Make sure we use non-guessable RMI object IDs.  Otherwise
 745          * attackers could hijack open connections by guessing their
 746          * IDs.  */
 747         System.setProperty("java.rmi.server.randomIDs", "true");
 748 
 749         JMXServiceURL url = new JMXServiceURL("rmi", bindAddress, rmiPort);
 750 
 751         Map<String, Object> env = new HashMap<>();
 752 
 753         PermanentExporter exporter = new PermanentExporter();
 754 
 755         env.put(RMIExporter.EXPORTER_ATTRIBUTE, exporter);
 756         env.put(RMIConnectorServer.CREDENTIAL_TYPES, new String[]{
 757             String[].class.getName(), String.class.getName()
 758         });
 759 
 760         boolean useSocketFactory = bindAddress != null && !useSsl;
 761 
 762         if (useAuthentication) {
 763             if (loginConfigName != null) {
 764                 env.put("jmx.remote.x.login.config", loginConfigName);
 765             }
 766             if (passwordFileName != null) {
 767                 env.put("jmx.remote.x.password.file", passwordFileName);
 768             }
 769             if (shouldHashPasswords) {
 770                 env.put("jmx.remote.x.password.hashpasswords", "true");
 771             }
 772 
 773             env.put("jmx.remote.x.access.file", accessFileName);
 774 
 775             if (env.get("jmx.remote.x.password.file") != null ||
 776                     env.get("jmx.remote.x.login.config") != null) {
 777                 env.put(JMXConnectorServer.AUTHENTICATOR,
 778                         new AccessFileCheckerAuthenticator(env));
 779             }
 780         }
 781 
 782         RMIClientSocketFactory csf = null;
 783         RMIServerSocketFactory ssf = null;
 784 
 785         if (useSsl || useRegistrySsl) {
 786             csf = new SslRMIClientSocketFactory();
 787             ssf = createSslRMIServerSocketFactory(
 788                     sslConfigFileName, enabledCipherSuites,
 789                     enabledProtocols, sslNeedClientAuth, bindAddress);
 790         }


< prev index next >