use of java.rmi.server.RMIServerSocketFactory in project tomcat 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<>();
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 felix by apache.
the class RMIResolver method createRMIServer.
protected RMIServerImpl createRMIServer(JMXServiceURL url, Map environment) throws IOException {
int port = url.getPort();
RMIClientSocketFactory clientFactory = (RMIClientSocketFactory) environment.get(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
RMIServerSocketFactory serverFactory = (RMIServerSocketFactory) environment.get(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
return new RMIJRMPServerImpl(port, clientFactory, serverFactory, environment);
}
use of java.rmi.server.RMIServerSocketFactory in project jdk8u_jdk by JetBrains.
the class RMIConnectorServer method newJRMPServer.
private static RMIServerImpl newJRMPServer(Map<String, ?> env, int port) throws IOException {
RMIClientSocketFactory csf = (RMIClientSocketFactory) env.get(RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE);
RMIServerSocketFactory ssf = (RMIServerSocketFactory) env.get(RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE);
return new RMIJRMPServerImpl(port, csf, ssf, env);
}
use of java.rmi.server.RMIServerSocketFactory in project karaf by apache.
the class ConnectorServerFactory method setupSsl.
private void setupSsl() throws GeneralSecurityException {
SSLServerSocketFactory sssf = keystoreManager.createSSLServerFactory(null, secureProtocol, algorithm, keyStore, keyAlias, trustStore, keyStoreAvailabilityTimeout);
RMIServerSocketFactory rssf = new KarafSslRMIServerSocketFactory(sssf, isClientAuth(), getRmiServerHost());
RMIClientSocketFactory rcsf = new SslRMIClientSocketFactory();
environment.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, rssf);
environment.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, rcsf);
// @TODO secure RMI connector as well?
// env.put("com.sun.jndi.rmi.factory.socket", rcsf);
}
use of java.rmi.server.RMIServerSocketFactory in project jackrabbit-oak 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);
}
}
Aggregations