use of java.rmi.server.RMIServerSocketFactory in project jdk8u_jdk by JetBrains.
the class PipeWriter method main.
/**
* Main program to start the activation system. <br>
* The usage is as follows: rmid [-port num] [-log dir].
*/
public static void main(String[] args) {
boolean stop = false;
// already.
if (System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
try {
int port = ActivationSystem.SYSTEM_PORT;
RMIServerSocketFactory ssf = null;
/*
* If rmid has an inherited channel (meaning that it was
* launched from inetd), set the server socket factory to
* return the inherited server socket.
**/
Channel inheritedChannel = AccessController.doPrivileged(new PrivilegedExceptionAction<Channel>() {
public Channel run() throws IOException {
return System.inheritedChannel();
}
});
if (inheritedChannel != null && inheritedChannel instanceof ServerSocketChannel) {
/*
* Redirect System.err output to a file.
*/
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
public Void run() throws IOException {
File file = Files.createTempFile("rmid-err", null).toFile();
PrintStream errStream = new PrintStream(new FileOutputStream(file));
System.setErr(errStream);
return null;
}
});
ServerSocket serverSocket = ((ServerSocketChannel) inheritedChannel).socket();
port = serverSocket.getLocalPort();
ssf = new ActivationServerSocketFactory(serverSocket);
System.err.println(new Date());
System.err.println(getTextResource("rmid.inherited.channel.info") + ": " + inheritedChannel);
}
String log = null;
List<String> childArgs = new ArrayList<>();
/*
* Parse arguments
*/
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-port")) {
if (ssf != null) {
bomb(getTextResource("rmid.syntax.port.badarg"));
}
if ((i + 1) < args.length) {
try {
port = Integer.parseInt(args[++i]);
} catch (NumberFormatException nfe) {
bomb(getTextResource("rmid.syntax.port.badnumber"));
}
} else {
bomb(getTextResource("rmid.syntax.port.missing"));
}
} else if (args[i].equals("-log")) {
if ((i + 1) < args.length) {
log = args[++i];
} else {
bomb(getTextResource("rmid.syntax.log.missing"));
}
} else if (args[i].equals("-stop")) {
stop = true;
} else if (args[i].startsWith("-C")) {
childArgs.add(args[i].substring(2));
} else {
bomb(MessageFormat.format(getTextResource("rmid.syntax.illegal.option"), args[i]));
}
}
if (log == null) {
if (ssf != null) {
bomb(getTextResource("rmid.syntax.log.required"));
} else {
log = "log";
}
}
debugExec = AccessController.doPrivileged(new GetBooleanAction("sun.rmi.server.activation.debugExec"));
/**
* Determine class name for activation exec policy (if any).
*/
String execPolicyClassName = AccessController.doPrivileged(new GetPropertyAction("sun.rmi.activation.execPolicy", null));
if (execPolicyClassName == null) {
if (!stop) {
DefaultExecPolicy.checkConfiguration();
}
execPolicyClassName = "default";
}
/**
* Initialize method for activation exec policy.
*/
if (!execPolicyClassName.equals("none")) {
if (execPolicyClassName.equals("") || execPolicyClassName.equals("default")) {
execPolicyClassName = DefaultExecPolicy.class.getName();
}
try {
Class<?> execPolicyClass = getRMIClass(execPolicyClassName);
execPolicy = execPolicyClass.newInstance();
execPolicyMethod = execPolicyClass.getMethod("checkExecCommand", ActivationGroupDesc.class, String[].class);
} catch (Exception e) {
if (debugExec) {
System.err.println(getTextResource("rmid.exec.policy.exception"));
e.printStackTrace();
}
bomb(getTextResource("rmid.exec.policy.invalid"));
}
}
if (stop == true) {
final int finalPort = port;
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
System.setProperty("java.rmi.activation.port", Integer.toString(finalPort));
return null;
}
});
ActivationSystem system = ActivationGroup.getSystem();
system.shutdown();
System.exit(0);
}
/*
* Fix for 4173960: Create and initialize activation using
* a static method, startActivation, which will build the
* Activation state in two ways: if when rmid is run, no
* log file is found, the ActLogHandler.recover(...)
* method will create a new Activation instance.
* Alternatively, if a logfile is available, a serialized
* instance of activation will be read from the log's
* snapshot file. Log updates will be applied to this
* Activation object until rmid's state has been fully
* recovered. In either case, only one instance of
* Activation is created.
*/
startActivation(port, ssf, log, childArgs.toArray(new String[childArgs.size()]));
// prevent activator from exiting
while (true) {
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
}
}
} catch (Exception e) {
System.err.println(MessageFormat.format(getTextResource("rmid.unexpected.exception"), e));
e.printStackTrace();
}
System.exit(1);
}
use of java.rmi.server.RMIServerSocketFactory in project jdk8u_jdk by JetBrains.
the class TCPEndpoint method newServerSocket.
/**
* Return new server socket to listen for connections on this endpoint.
*/
ServerSocket newServerSocket() throws IOException {
if (TCPTransport.tcpLog.isLoggable(Log.VERBOSE)) {
TCPTransport.tcpLog.log(Log.VERBOSE, "creating server socket on " + this);
}
RMIServerSocketFactory serverFactory = ssf;
if (serverFactory == null) {
serverFactory = chooseFactory();
}
ServerSocket server = serverFactory.createServerSocket(listenPort);
// (for this socket factory)
if (listenPort == 0)
setDefaultPort(server.getLocalPort(), csf, ssf);
return server;
}
use of java.rmi.server.RMIServerSocketFactory in project karaf by apache.
the class RmiRegistryFactory method init.
public void init() throws RemoteException, UnknownHostException {
if (registry == null && locate) {
try {
Registry reg = LocateRegistry.getRegistry(host, getPort());
reg.list();
registry = reg;
} catch (RemoteException e) {
// ignore
}
}
if (registry == null && create) {
if (host != null && !host.isEmpty()) {
RMIClientSocketFactory socketFactory = RMISocketFactory.getDefaultSocketFactory();
InetAddress addr = InetAddress.getByName(host);
RMIServerSocketFactory serverSocketFactory = new KarafServerSocketFactory(addr, port);
registry = LocateRegistry.createRegistry(getPort(), socketFactory, serverSocketFactory);
} else {
registry = LocateRegistry.createRegistry(getPort());
}
locallyCreated = true;
}
if (registry != null) {
// register the registry as an OSGi service
Hashtable<String, Object> props = new Hashtable<>();
props.put("port", getPort());
props.put("host", getHost());
bundleContext.registerService(Registry.class, registry, props);
}
}
use of java.rmi.server.RMIServerSocketFactory 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.RMIServerSocketFactory in project karaf by apache.
the class ConnectorServerFactory method setupKarafRMIServerSocketFactory.
private void setupKarafRMIServerSocketFactory() {
RMIServerSocketFactory rssf = new KarafRMIServerSocketFactory(getRmiServerHost());
environment.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, rssf);
}
Aggregations