use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class TCPEndpoint method read.
/**
* Get the endpoint from the input stream.
* @param in the input stream
* @exception IOException If id could not be read (due to stream failure)
*/
public static TCPEndpoint read(ObjectInput in) throws IOException, ClassNotFoundException {
String host;
int port;
RMIClientSocketFactory csf = null;
byte format = in.readByte();
switch(format) {
case FORMAT_HOST_PORT:
host = in.readUTF();
port = in.readInt();
break;
case FORMAT_HOST_PORT_FACTORY:
host = in.readUTF();
port = in.readInt();
csf = (RMIClientSocketFactory) in.readObject();
break;
default:
throw new IOException("invalid endpoint format");
}
return new TCPEndpoint(host, port, csf, null);
}
use of java.rmi.server.RMIClientSocketFactory in project hbase by apache.
the class JMXListener method startConnectorServer.
public void startConnectorServer(int rmiRegistryPort, int rmiConnectorPort) throws IOException {
boolean rmiSSL = false;
boolean authenticate = true;
String passwordFile = null;
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<>();
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 SslRMIClientSocketFactorySecure();
ssf = new SslRMIServerSocketFactorySecure();
}
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
rmiRegistry = 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
synchronized (JMXListener.class) {
if (JMX_CS != null) {
throw new RuntimeException("Started by another thread?");
}
JMX_CS = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl, jmxEnv, mbs);
JMX_CS.start();
}
LOG.info("ConnectorServer started!");
} catch (IOException e) {
LOG.error("fail to start connector server!", e);
// deregister the RMI registry
if (rmiRegistry != null) {
UnicastRemoteObject.unexportObject(rmiRegistry, true);
}
}
}
use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class ConnectorBootstrap method exportMBeanServer.
private static JMXConnectorServerData exportMBeanServer(MBeanServer mbs, int port, int rmiPort, boolean useSsl, boolean useRegistrySsl, String sslConfigFileName, String[] enabledCipherSuites, String[] enabledProtocols, boolean sslNeedClientAuth, boolean useAuthentication, String loginConfigName, String passwordFileName, String accessFileName, String bindAddress) throws IOException, MalformedURLException {
/* Make sure we use non-guessable RMI object IDs. Otherwise
* attackers could hijack open connections by guessing their
* IDs. */
System.setProperty("java.rmi.server.randomIDs", "true");
JMXServiceURL url = new JMXServiceURL("rmi", bindAddress, rmiPort);
Map<String, Object> env = new HashMap<>();
PermanentExporter exporter = new PermanentExporter();
env.put(RMIExporter.EXPORTER_ATTRIBUTE, exporter);
env.put(EnvHelp.CREDENTIAL_TYPES, new String[] { String[].class.getName(), String.class.getName() });
boolean useSocketFactory = bindAddress != null && !useSsl;
if (useAuthentication) {
if (loginConfigName != null) {
env.put("jmx.remote.x.login.config", loginConfigName);
}
if (passwordFileName != null) {
env.put("jmx.remote.x.password.file", passwordFileName);
}
env.put("jmx.remote.x.access.file", accessFileName);
if (env.get("jmx.remote.x.password.file") != null || env.get("jmx.remote.x.login.config") != null) {
env.put(JMXConnectorServer.AUTHENTICATOR, new AccessFileCheckerAuthenticator(env));
}
}
RMIClientSocketFactory csf = null;
RMIServerSocketFactory ssf = null;
if (useSsl || useRegistrySsl) {
csf = new SslRMIClientSocketFactory();
ssf = createSslRMIServerSocketFactory(sslConfigFileName, enabledCipherSuites, enabledProtocols, sslNeedClientAuth, bindAddress);
}
if (useSsl) {
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
}
if (useSocketFactory) {
ssf = new HostAwareSocketFactory(bindAddress);
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
}
JMXConnectorServer connServer = null;
try {
connServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
connServer.start();
} catch (IOException e) {
if (connServer == null || connServer.getAddress() == null) {
throw new AgentConfigurationError(CONNECTOR_SERVER_IO_ERROR, e, url.toString());
} else {
throw new AgentConfigurationError(CONNECTOR_SERVER_IO_ERROR, e, connServer.getAddress().toString());
}
}
if (useRegistrySsl) {
registry = new SingleEntryRegistry(port, csf, ssf, "jmxrmi", exporter.firstExported);
} else if (useSocketFactory) {
registry = new SingleEntryRegistry(port, csf, ssf, "jmxrmi", exporter.firstExported);
} else {
registry = new SingleEntryRegistry(port, "jmxrmi", exporter.firstExported);
}
int registryPort = ((UnicastRef) ((RemoteObject) registry).getRef()).getLiveRef().getPort();
String jmxUrlStr = String.format("service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", url.getHost(), registryPort);
JMXServiceURL remoteURL = new JMXServiceURL(jmxUrlStr);
return new JMXConnectorServerData(connServer, remoteURL);
}
use of java.rmi.server.RMIClientSocketFactory in project jdk8u_jdk by JetBrains.
the class LiveRef method remoteEquals.
public boolean remoteEquals(Object obj) {
if (obj != null && obj instanceof LiveRef) {
LiveRef ref = (LiveRef) obj;
TCPEndpoint thisEp = ((TCPEndpoint) ep);
TCPEndpoint refEp = ((TCPEndpoint) ref.ep);
RMIClientSocketFactory thisClientFactory = thisEp.getClientSocketFactory();
RMIClientSocketFactory refClientFactory = refEp.getClientSocketFactory();
/**
* Fix for 4254103: LiveRef.remoteEquals should not fail
* if one of the objects in the comparison has a null
* server socket. Comparison should only consider the
* following criteria:
*
* hosts, ports, client socket factories and object IDs.
*/
if (thisEp.getPort() != refEp.getPort() || !thisEp.getHost().equals(refEp.getHost())) {
return false;
}
if ((thisClientFactory == null) ^ (refClientFactory == null)) {
return false;
}
if ((thisClientFactory != null) && !((thisClientFactory.getClass() == refClientFactory.getClass()) && (thisClientFactory.equals(refClientFactory)))) {
return false;
}
return (id.equals(ref.id));
} else {
return false;
}
}
use of java.rmi.server.RMIClientSocketFactory in project geode by apache.
the class ConnectionNotificationFilterImpl method startRMIConnectorServer.
/**
* Defines and starts the JMX RMIConnector and service.
* <p>
* 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();
// 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 // true,
MX4JServerSocketFactory(// true,
this.agentConfig.isAgentSSLEnabled(), // true,
this.agentConfig.isAgentSSLRequireAuth(), // "any",
this.agentConfig.getAgentSSLProtocols(), // "any",
this.agentConfig.getAgentSSLCiphers(), // backlog
this.agentConfig.getRmiBindAddress(), // backlog
10, 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);
}
// will be set by registering w/ mbeanServer
MBeanServer mbs = null;
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);
// 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);
}
}
Aggregations