use of java.rmi.server.RMIServerSocketFactory in project tomcat70 by apache.
the class JmxRemoteLifecycleListener method lifecycleEvent.
@Override
public void lifecycleEvent(LifecycleEvent event) {
// When the server starts, configure JMX/RMI
if (Lifecycle.START_EVENT.equals(event.getType())) {
// Configure using standard jmx system properties
init();
// Prevent an attacker guessing the RMI object ID
System.setProperty("java.rmi.server.randomIDs", "true");
// Create the environment
HashMap<String, Object> env = new HashMap<String, Object>();
RMIClientSocketFactory registryCsf = null;
RMIServerSocketFactory registrySsf = null;
RMIClientSocketFactory serverCsf = null;
RMIServerSocketFactory serverSsf = null;
// Configure registry socket factories
if (rmiRegistrySSL) {
registryCsf = new SslRMIClientSocketFactory();
if (rmiBindAddress == null) {
registrySsf = new SslRMIServerSocketFactory(ciphers, protocols, clientAuth);
} else {
registrySsf = new SslRmiServerBindSocketFactory(ciphers, protocols, clientAuth, rmiBindAddress);
}
} else {
if (rmiBindAddress != null) {
registrySsf = new RmiServerBindSocketFactory(rmiBindAddress);
}
}
// Configure server socket factories
if (rmiServerSSL) {
serverCsf = new SslRMIClientSocketFactory();
if (rmiBindAddress == null) {
serverSsf = new SslRMIServerSocketFactory(ciphers, protocols, clientAuth);
} else {
serverSsf = new SslRmiServerBindSocketFactory(ciphers, protocols, clientAuth, rmiBindAddress);
}
} else {
if (rmiBindAddress != null) {
serverSsf = new RmiServerBindSocketFactory(rmiBindAddress);
}
}
// the configured address.
if (rmiBindAddress != null) {
System.setProperty("java.rmi.server.hostname", rmiBindAddress);
}
// Force the use of local ports if required
if (useLocalPorts) {
registryCsf = new RmiClientLocalhostSocketFactory(registryCsf);
serverCsf = new RmiClientLocalhostSocketFactory(serverCsf);
}
env.put("jmx.remote.rmi.server.credential.types", new String[] { String[].class.getName(), String.class.getName() });
// Populate the env properties used to create the server
if (serverCsf != null) {
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, serverCsf);
env.put("com.sun.jndi.rmi.factory.socket", registryCsf);
}
if (serverSsf != null) {
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverSsf);
}
// Configure authentication
if (authenticate) {
env.put("jmx.remote.x.password.file", passwordFile);
env.put("jmx.remote.x.access.file", accessFile);
env.put("jmx.remote.x.login.config", loginModuleName);
}
// Create the Platform server
csPlatform = createServer("Platform", rmiBindAddress, rmiRegistryPortPlatform, rmiServerPortPlatform, env, registryCsf, registrySsf, serverCsf, serverSsf);
} else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
destroyServer("Platform", csPlatform);
}
}
use of java.rmi.server.RMIServerSocketFactory in project activemq-artemis by apache.
the class ConnectorServerFactory method setupSsl.
// todo fix
private void setupSsl() throws Exception {
SSLContext context = SSLSupport.createContext(keyStoreProvider, keyStorePath, keyStorePassword, trustStoreProvider, trustStorePath, trustStorePassword);
SSLServerSocketFactory sssf = context.getServerSocketFactory();
RMIServerSocketFactory rssf = new ArtemisSslRMIServerSocketFactory(sssf, this.isClientAuth(), rmiServerHost);
RMIClientSocketFactory rcsf = new SslRMIClientSocketFactory();
environment.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, rssf);
environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, rcsf);
}
use of java.rmi.server.RMIServerSocketFactory in project jackrabbit by apache.
the class RepositoryStartupServlet method registerRMI.
/**
* Registers the repository to an RMI registry configured in the web
* application. See <a href="#registerAlgo">Registration with RMI</a> in the
* class documentation for a description of the algorithms used to register
* the repository with an RMI registry.
* @throws ServletException if an error occurs.
*/
private void registerRMI() {
RMIConfig rc = config.getRmiConfig();
if (!rc.isValid() || !rc.enabled()) {
return;
}
// try to create remote repository
Remote remote;
try {
Class<?> clazz = Class.forName(getRemoteFactoryDelegaterClass());
RemoteFactoryDelegater rmf = (RemoteFactoryDelegater) clazz.newInstance();
remote = rmf.createRemoteRepository(repository);
} catch (RemoteException e) {
log.warn("Unable to create RMI repository.", e);
return;
} catch (Throwable t) {
log.warn("Unable to create RMI repository." + " The jcr-rmi jar might be missing.", t);
return;
}
try {
System.setProperty("java.rmi.server.useCodebaseOnly", "true");
Registry reg = null;
// or if the rmiHost is not local
try {
// find the server socket factory: use the default if the
// rmiHost is not configured
RMIServerSocketFactory sf;
if (rc.getRmiHost().length() > 0) {
log.debug("Creating RMIServerSocketFactory for host " + rc.getRmiHost());
InetAddress hostAddress = InetAddress.getByName(rc.getRmiHost());
sf = getRMIServerSocketFactory(hostAddress);
} else {
// have the RMI implementation decide which factory is the
// default actually
log.debug("Using default RMIServerSocketFactory");
sf = null;
}
// create a registry using the default client socket factory
// and the server socket factory retrieved above. This also
// binds to the server socket to the rmiHost:rmiPort.
reg = LocateRegistry.createRegistry(rc.rmiPort(), null, sf);
rmiRegistry = reg;
} catch (UnknownHostException uhe) {
// thrown if the rmiHost cannot be resolved into an IP-Address
// by getRMIServerSocketFactory
log.info("Cannot create Registry", uhe);
} catch (RemoteException e) {
// thrown by createRegistry if binding to the rmiHost:rmiPort
// fails, for example due to rmiHost being remote or another
// application already being bound to the port
log.info("Cannot create Registry", e);
}
// registry is actually accessible.
if (reg == null) {
log.debug("Trying to access existing registry at " + rc.getRmiHost() + ":" + rc.getRmiPort());
try {
reg = LocateRegistry.getRegistry(rc.getRmiHost(), rc.rmiPort());
} catch (RemoteException re) {
log.warn("Cannot create the reference to the registry at " + rc.getRmiHost() + ":" + rc.getRmiPort(), re);
}
}
// rmiName
if (reg != null) {
log.debug("Registering repository as " + rc.getRmiName() + " to registry " + reg);
reg.bind(rc.getRmiName(), remote);
// when successfull, keep references
this.rmiRepository = remote;
log.info("Repository bound via RMI with name: " + rc.getRmiUri());
} else {
log.info("RMI registry missing, cannot bind repository via RMI");
}
} catch (RemoteException e) {
log.warn("Unable to bind repository via RMI: " + rc.getRmiUri(), e);
} catch (AlreadyBoundException e) {
log.warn("Unable to bind repository via RMI: " + rc.getRmiUri(), e);
}
}
use of java.rmi.server.RMIServerSocketFactory in project iep by Netflix.
the class JmxPort method configure.
public static void configure(String hostname, int port) {
if (hostname == null) {
throw new IllegalArgumentException("hostname cannot be null");
}
System.setProperty("java.rmi.server.hostname", hostname);
LOGGER.info("set java.rmi.server.hostname to '" + hostname + "'");
// Setup server on the configured port
try {
InetAddress address = InetAddress.getByName(hostname);
RMIServerSocketFactory factory = new SingleInterfaceRMIServerSocketFactory(address);
LocateRegistry.createRegistry(port, null, factory);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Map<String, Object> env = new HashMap<>();
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, factory);
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostname + ":" + port + "/jndi/rmi://" + hostname + ":" + port + "/jmxrmi");
JMXConnectorServer jmxConn = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
LOGGER.info("starting JMX connector server on: " + url.getURLPath());
jmxConn.start();
} catch (Exception e) {
throw new IllegalStateException("failed to initialize jmx port", e);
}
}
use of java.rmi.server.RMIServerSocketFactory in project cassandra by apache.
the class RMIServerSocketFactoryImplTest method testReusableAddrSocket.
@Test
public void testReusableAddrSocket() throws IOException {
RMIServerSocketFactory serverFactory = new RMIServerSocketFactoryImpl(null);
ServerSocket socket = serverFactory.createServerSocket(7199);
assertTrue(socket.getReuseAddress());
}
Aggregations