List of usage examples for javax.management.remote.rmi RMIConnectorServer RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE
String RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE
To view the source code for javax.management.remote.rmi RMIConnectorServer RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE.
Click Source Link
Name of the attribute that specifies the RMIClientSocketFactory for the RMI objects created in conjunction with this connector.
From source file:com.tc.management.JMXConnectorProxy.java
private void determineConnector() throws Exception { JMXServiceURL url = new JMXServiceURL(getSecureJMXConnectorURL(m_host, m_port)); if (m_secured) { RMIClientSocketFactory csf; if (Boolean.getBoolean("tc.ssl.trustAllCerts")) { csf = new TSASSLSocketFactory(); } else {//from w ww . j a va 2 s .co m csf = new SslRMIClientSocketFactory(); } SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory(); m_env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); m_env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); // Needed to avoid "non-JRMP server at remote endpoint" error m_env.put("com.sun.jndi.rmi.factory.socket", csf); m_serviceURL = new JMXServiceURL("service:jmx:rmi://" + m_host + ":" + m_port + "/jndi/rmi://" + m_host + ":" + m_port + "/jmxrmi"); m_connector = JMXConnectorFactory.connect(url, m_env); } else { try { m_connector = JMXConnectorFactory.connect(url, m_env); m_serviceURL = url; } catch (IOException ioe) { if (isConnectException(ioe)) { throw ioe; } if (isAuthenticationException(ioe)) { throw new SecurityException("Invalid login name or credentials"); } url = new JMXServiceURL(getJMXConnectorURL(m_host, m_port)); m_connector = JMXConnectorFactory.connect(url, m_env); m_serviceURL = url; } } }
From source file:com.continuent.tungsten.common.jmx.JmxManager.java
/** * Starts the JMX connector for the server. */// www. ja v a 2 s. co m protected void startJmxConnector() { String serviceAddress = null; try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); serviceAddress = generateServiceAddress(host, beanPort, registryPort, serviceName); JMXServiceURL address = new JMXServiceURL(serviceAddress); // --- Define security attributes --- HashMap<String, Object> env = new HashMap<String, Object>(); // --- Authentication based on password and access files--- if (authenticationInfo != null && authenticationInfo.isAuthenticationNeeded()) { if (authenticationInfo.isUseTungstenAuthenticationRealm()) env.put(JMXConnectorServer.AUTHENTICATOR, new RealmJMXAuthenticator(authenticationInfo)); else env.put("jmx.remote.x.password.file", authenticationInfo.getPasswordFileLocation()); env.put("jmx.remote.x.access.file", authenticationInfo.getAccessFileLocation()); } // --- SSL encryption --- if (authenticationInfo != null && authenticationInfo.isEncryptionNeeded()) { // Keystore System.setProperty("javax.net.ssl.keyStore", authenticationInfo.getKeystoreLocation()); System.setProperty("javax.net.ssl.keyStorePassword", authenticationInfo.getKeystorePassword()); /** * Configure SSL. Protocols and ciphers are set in * securityHelper.setSecurityProperties and used by * SslRMIClientSocketFactory */ try { String[] protocolArray = authenticationInfo.getEnabledProtocols().toArray(new String[0]); String[] allowedCipherSuites = authenticationInfo.getEnabledCipherSuites() .toArray(new String[0]); String[] cipherArray; if (protocolArray.length == 0) protocolArray = null; if (allowedCipherSuites.length == 0) cipherArray = null; else { // Ensure we choose an allowed cipher suite. cipherArray = authenticationInfo.getJvmEnabledCipherSuites().toArray(new String[0]); if (cipherArray.length == 0) { // We don't have any cipher suites in common. This // is not good! String message = "Unable to find approved ciphers in the supported cipher suites on this JVM"; StringBuffer sb = new StringBuffer(message).append("\n"); sb.append(String.format("JVM supported cipher suites: %s\n", StringUtils.join(SecurityHelper.getJvmSupportedCiphers()))); sb.append(String.format("Approved cipher suites from security.properties: %s\n", StringUtils.join(allowedCipherSuites))); logger.error(sb.toString()); throw new RuntimeException(message); } } logger.info("Setting allowed JMX server protocols: " + StringUtils.join(protocolArray, ",")); logger.info("Setting allowed JMX server ciphers: " + StringUtils.join(cipherArray, ",")); SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory(); SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory(cipherArray, protocolArray, false); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); } catch (IllegalArgumentException ie) { logger.warn("Some of the protocols or ciphers are not supported. " + ie.getMessage()); throw new RuntimeException(ie.getLocalizedMessage(), ie); } } env.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true"); JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(address, env, mbs); connector.start(); logger.info(MessageFormat.format("JMXConnector: security.properties={0}", (authenticationInfo != null) ? authenticationInfo.getParentPropertiesFileLocation() : "No security.properties file found !...")); if (authenticationInfo != null) logger.info(authenticationInfo.toString()); logger.info(String.format("JMXConnector started at address %s", serviceAddress)); jmxConnectorServer = connector; } catch (Throwable e) { throw new ServerRuntimeException( MessageFormat.format("Unable to create RMI listener: {0} -> {1}", getServiceProps(), e), e); } }
From source file:org.apache.cassandra.utils.JMXServerUtils.java
private static void configureRMIRegistry(int port, Map<String, Object> env) throws RemoteException { Exporter exporter = (Exporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE); // If ssl is enabled, make sure it's also in place for the RMI registry // by using the SSL socket factories already created and stashed in env if (Boolean.getBoolean("com.sun.management.jmxremote.ssl")) { registry = new Registry(port, (RMIClientSocketFactory) env.get(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE), (RMIServerSocketFactory) env.get(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE), exporter.connectorServer); } else {//from w w w.j a v a 2s. com registry = new Registry(port, exporter.connectorServer); } }
From source file:org.apache.cassandra.utils.JMXServerUtils.java
private static Map<String, Object> configureJmxSocketFactories(InetAddress serverAddress, boolean localOnly) { Map<String, Object> env = new HashMap<>(); if (Boolean.getBoolean("com.sun.management.jmxremote.ssl")) { boolean requireClientAuth = Boolean.getBoolean("com.sun.management.jmxremote.ssl.need.client.auth"); String[] protocols = null; String protocolList = System.getProperty("com.sun.management.jmxremote.ssl.enabled.protocols"); if (protocolList != null) { System.setProperty("javax.rmi.ssl.client.enabledProtocols", protocolList); protocols = StringUtils.split(protocolList, ','); }/*from ww w . j a v a 2s.c o m*/ String[] ciphers = null; String cipherList = System.getProperty("com.sun.management.jmxremote.ssl.enabled.cipher.suites"); if (cipherList != null) { System.setProperty("javax.rmi.ssl.client.enabledCipherSuites", cipherList); ciphers = StringUtils.split(cipherList, ','); } SslRMIClientSocketFactory clientFactory = new SslRMIClientSocketFactory(); SslRMIServerSocketFactory serverFactory = new SslRMIServerSocketFactory(ciphers, protocols, requireClientAuth); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverFactory); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, clientFactory); env.put("com.sun.jndi.rmi.factory.socket", clientFactory); logJmxSslConfig(serverFactory); } else if (localOnly) { env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, new RMIServerSocketFactoryImpl(serverAddress)); } return env; }
From source file:org.apache.geode.admin.jmx.internal.AgentImpl.java
/** * Defines and starts the JMX RMIConnector and service. * <p>/*from www .j av a 2 s. com*/ * If {@link AgentConfig#isRmiEnabled} returns false, then this adaptor will not be started. */ private void startRMIConnectorServer() { if (!this.agentConfig.isRmiEnabled()) return; String rmiBindAddress = this.agentConfig.getRmiBindAddress(); // Set RMI Stubs to use the given RMI Bind Address // Default bindAddress is "", if none is set - ignore if not set // If java.rmi.server.hostname property is specified then // that override is not changed String rmiStubServerNameKey = "java.rmi.server.hostname"; String overrideHostName = System.getProperty(rmiStubServerNameKey); if ((overrideHostName == null || overrideHostName.trim().length() == 0) && (rmiBindAddress != null && rmiBindAddress.trim().length() != 0)) { System.setProperty(rmiStubServerNameKey, rmiBindAddress); logger.info(LocalizedMessage.create(LocalizedStrings.AgentImpl_SETTING_0, new StringBuilder(rmiStubServerNameKey).append(" = ").append(rmiBindAddress))); } try { createRMIRegistry(); ObjectName objName = getRMIConnectorServerName(); // make sure this adaptor is not already registered... if (getMBeanServer().isRegistered(objName)) { // dunno how we got here... logger.info(LocalizedMessage .create(LocalizedStrings.AgentImpl_RMICONNECTORSERVER_ALREADY_REGISTERED_AS__0, objName)); return; } /* * url defined as: service:jmx:protocol:sap where 1. protocol: rmi 2. sap is: * [host[:port]][url-path] where host: rmi-binding-address port: rmi-server-port url-path: * /jndi/rmi://<rmi-binding-address>:<rmi-port><JNDI_NAME> */ String urlString = null; String connectorServerHost = ""; int connectorServerPort = this.agentConfig.getRmiServerPort(); String rmiRegistryHost = ""; int rmiRegistryPort = this.agentConfig.getRmiPort(); // Set registryHost to localhost if not specified // RMI stubs would use a default IP if namingHost is left empty if (rmiBindAddress == null || rmiBindAddress.trim().length() == 0) { connectorServerHost = "localhost"; rmiRegistryHost = ""; } else { connectorServerHost = applyRFC2732(rmiBindAddress); rmiRegistryHost = connectorServerHost; } urlString = MessageFormat.format(AgentImpl.JMX_SERVICE_URL, connectorServerHost, String.valueOf(connectorServerPort), rmiRegistryHost, String.valueOf(rmiRegistryPort), JNDI_NAME); logger.debug("JMX Service URL string is : \"{}\"", urlString); // The address of the connector JMXServiceURL url = new JMXServiceURL(urlString); Map<String, Object> env = new HashMap<String, Object>(); // env.put(Context.INITIAL_CONTEXT_FACTORY, // "com.sun.jndi.rmi.registry.RegistryContextFactory"); // env.put(Context.PROVIDER_URL, "rmi://localhost:1099"); RMIServerSocketFactory ssf = new MX4JServerSocketFactory(this.agentConfig.isAgentSSLEnabled(), // true, this.agentConfig.isAgentSSLRequireAuth(), // true, this.agentConfig.getAgentSSLProtocols(), // "any", this.agentConfig.getAgentSSLCiphers(), // "any", this.agentConfig.getRmiBindAddress(), 10, // backlog this.agentConfig.getGfSecurityProperties()); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); if (this.agentConfig.isAgentSSLEnabled()) { RMIClientSocketFactory csf = new SslRMIClientSocketFactory(); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); } MBeanServer mbs = null; // will be set by registering w/ mbeanServer this.rmiConnector = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); // for cleanup this.rmiConnector.addNotificationListener(new ConnectionNotificationAdapter(), new ConnectionNotificationFilterImpl(), this); // Register the JMXConnectorServer in the MBeanServer getMBeanServer().registerMBean(this.rmiConnector, objName); // Start the JMXConnectorServer this.rmiConnector.start(); } catch (VirtualMachineError err) { SystemFailure.initiateFailure(err); // If this ever returns, rethrow the error. We're poisoned // now, so don't let this thread continue. throw err; } catch (Throwable t) { // Whenever you catch Error or Throwable, you must also // catch VirtualMachineError (see above). However, there is // _still_ a possibility that you are dealing with a cascading // error condition, so you also need to check to see if the JVM // is still usable: SystemFailure.checkFailure(); logger.error(LocalizedStrings.AgentImpl_FAILED_TO_START_RMICONNECTORSERVER, t); throw new StartupException(LocalizedStrings.AgentImpl_FAILED_TO_START_RMI_SERVICE.toLocalizedString(), t); } }
From source file:org.apache.hadoop.hbase.JMXListener.java
public void startConnectorServer(int rmiRegistryPort, int rmiConnectorPort) throws IOException { boolean rmiSSL = false; boolean authenticate = true; String passwordFile = null;/*from w ww. j a v a2s . c om*/ String accessFile = null; System.setProperty("java.rmi.server.randomIDs", "true"); String rmiSSLValue = System.getProperty("com.sun.management.jmxremote.ssl", "false"); rmiSSL = Boolean.parseBoolean(rmiSSLValue); String authenticateValue = System.getProperty("com.sun.management.jmxremote.authenticate", "false"); authenticate = Boolean.parseBoolean(authenticateValue); passwordFile = System.getProperty("com.sun.management.jmxremote.password.file"); accessFile = System.getProperty("com.sun.management.jmxremote.access.file"); LOG.info("rmiSSL:" + rmiSSLValue + ",authenticate:" + authenticateValue + ",passwordFile:" + passwordFile + ",accessFile:" + accessFile); // Environment map HashMap<String, Object> jmxEnv = new HashMap<String, Object>(); RMIClientSocketFactory csf = null; RMIServerSocketFactory ssf = null; if (rmiSSL) { if (rmiRegistryPort == rmiConnectorPort) { throw new IOException( "SSL is enabled. " + "rmiConnectorPort cannot share with the rmiRegistryPort!"); } csf = new SslRMIClientSocketFactory(); ssf = new SslRMIServerSocketFactory(); } if (csf != null) { jmxEnv.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); } if (ssf != null) { jmxEnv.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); } // Configure authentication if (authenticate) { jmxEnv.put("jmx.remote.x.password.file", passwordFile); jmxEnv.put("jmx.remote.x.access.file", accessFile); } // Create the RMI registry LocateRegistry.createRegistry(rmiRegistryPort); // Retrieve the PlatformMBeanServer. MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); // Build jmxURL JMXServiceURL serviceUrl = buildJMXServiceURL(rmiRegistryPort, rmiConnectorPort); try { // Start the JMXListener with the connection string jmxCS = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl, jmxEnv, mbs); jmxCS.start(); LOG.info("ConnectorServer started!"); } catch (IOException e) { LOG.error("fail to start connector server!", e); } }
From source file:org.apereo.portal.jmx.JavaManagementServerBean.java
/** * Generates the environment Map for the JMX server based on system properties * @return A non-null Map of environment settings for the JMX server. */// w w w .ja v a2s . c o m protected Map<String, Object> getJmxServerEnvironment() { final Map<String, Object> jmxEnv = new HashMap<String, Object>(); //SSL Options final String enableSSL = System.getProperty(JMX_SSL_PROPERTY); if (Boolean.getBoolean(enableSSL)) { SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory(); jmxEnv.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory(); jmxEnv.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); } //Password file options final String passwordFile = System.getProperty(JMX_PASSWORD_FILE_PROPERTY); if (passwordFile != null) { jmxEnv.put(JMX_REMOTE_X_PASSWORD_FILE, passwordFile); } //Access file options final String accessFile = System.getProperty(JMX_ACCESS_FILE_PROPERTY); if (accessFile != null) { jmxEnv.put(JMX_REMOTE_X_ACCESS_FILE, accessFile); } if (this.logger.isDebugEnabled()) { this.logger.debug("Configured JMX Server Environment = '" + jmxEnv + "'"); } return jmxEnv; }
From source file:org.red5.server.jmx.JMXAgent.java
public void init() { //environmental var holder HashMap env = null;/*from www. ja va 2 s. co m*/ if (enableHtmlAdapter) { // setup the adapter try { //instance an html adaptor int port = htmlAdapterPort == null ? 8082 : Integer.valueOf(htmlAdapterPort); html = new HtmlAdaptorServer(port); ObjectName htmlName = new ObjectName( JMXFactory.getDefaultDomain() + ":type=HtmlAdaptorServer,port=" + port); log.debug("Created HTML adaptor on port: " + port); //add the adaptor to the server mbs.registerMBean(html, htmlName); //start the adaptor html.start(); log.info("JMX HTML connector server successfully started"); } catch (Exception e) { log.error("Error in setup of JMX subsystem (HTML adapter)", e); } } else { log.info("JMX HTML adapter was not enabled"); } if (enableRmiAdapter) { // Create an RMI connector server log.debug("Create an RMI connector server"); try { Registry r = null; try { //lookup the registry r = LocateRegistry.getRegistry(Integer.valueOf(rmiAdapterPort)); //ensure we are not already registered with the registry for (String regName : r.list()) { if (regName.equals("red5")) { //unbind connector from rmi registry r.unbind("red5"); } } } catch (RemoteException re) { log.info("RMI Registry server was not found on port " + rmiAdapterPort); //if we didnt find the registry and the user wants it created if (startRegistry) { log.info("Starting an internal RMI registry"); // create registry for rmi port 9999 r = LocateRegistry.createRegistry(Integer.valueOf(rmiAdapterPort)); } } JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + rmiAdapterPort + "/red5"); //if SSL is requested to secure rmi connections if (enableSsl) { // Environment map log.debug("Initialize the environment map"); env = new HashMap(); // Provide SSL-based RMI socket factories SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory(); SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory(); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); } //if authentication is requested if (StringUtils.isNotBlank(remoteAccessProperties)) { //if ssl is not used this will be null if (null == env) { env = new HashMap(); } //check the existance of the files //in the war version the full path is needed File file = new File(remoteAccessProperties); if (!file.exists()) { log.debug("Access file was not found on path, will prepend config_root"); //pre-pend the system property set in war startup remoteAccessProperties = System.getProperty("red5.config_root") + '/' + remoteAccessProperties; remotePasswordProperties = System.getProperty("red5.config_root") + '/' + remotePasswordProperties; } env.put("jmx.remote.x.access.file", remoteAccessProperties); env.put("jmx.remote.x.password.file", remotePasswordProperties); } // create the connector server cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); // add a listener for shutdown cs.addNotificationListener(this, null, null); // Start the RMI connector server log.debug("Start the RMI connector server"); cs.start(); log.info("JMX RMI connector server successfully started"); } catch (ConnectException e) { log.warn("Could not establish RMI connection to port " + rmiAdapterPort + ", please make sure \"rmiregistry\" is running and configured to listen on this port."); } catch (IOException e) { String errMsg = e.getMessage(); if (errMsg.indexOf("NameAlreadyBoundException") != -1) { log.error("JMX connector (red5) already registered, you will need to restart your rmiregistry"); } else { log.error("{}", e); } } catch (Exception e) { log.error("Error in setup of JMX subsystem (RMI connector)", e); } } else { log.info("JMX RMI adapter was not enabled"); } }