// Get serverPort number
final int serverPort;
try {
serverPort = Integer.parseInt(portStr);
} catch (NumberFormatException x) {
throw new AgentConfigurationError(INVALID_JMXREMOTE_PORT,
x, portStr);
}
if (serverPort < 0) {
throw new AgentConfigurationError(INVALID_JMXREMOTE_PORT,
portStr);
}
// Do we use authentication?
final String useAuthenticationStr = props.getProperty(
PropertyNames.USE_AUTHENTICATION,
DefaultValues.USE_AUTHENTICATION);
final boolean useAuthentication = Boolean.valueOf(
useAuthenticationStr).booleanValue();
// Do we use SSL?
final String useSslStr = props.getProperty(
PropertyNames.USE_SSL, DefaultValues.USE_SSL);
final boolean useSsl = Boolean.valueOf(useSslStr).booleanValue();
// Do we use RMI Registry SSL?
final String useRegistrySslStr = props.getProperty(
PropertyNames.USE_REGISTRY_SSL,
DefaultValues.USE_REGISTRY_SSL);
final boolean useRegistrySsl = Boolean.valueOf(
useRegistrySslStr).booleanValue();
final String enabledCipherSuites = props.getProperty(PropertyNames.SSL_ENABLED_CIPHER_SUITES);
String enabledCipherSuitesList[] = null;
if (enabledCipherSuites != null) {
StringTokenizer st = new StringTokenizer(
enabledCipherSuites, ",");
int tokens = st.countTokens();
enabledCipherSuitesList = new String[tokens];
for (int i = 0; i < tokens; i++) {
enabledCipherSuitesList[i] = st.nextToken();
}
}
final String enabledProtocols = props.getProperty(PropertyNames.SSL_ENABLED_PROTOCOLS);
String enabledProtocolsList[] = null;
if (enabledProtocols != null) {
StringTokenizer st = new StringTokenizer(enabledProtocols,
",");
int tokens = st.countTokens();
enabledProtocolsList = new String[tokens];
for (int i = 0; i < tokens; i++) {
enabledProtocolsList[i] = st.nextToken();
}
}
final String sslNeedClientAuthStr = props.getProperty(
PropertyNames.SSL_NEED_CLIENT_AUTH,
DefaultValues.SSL_NEED_CLIENT_AUTH);
final boolean sslNeedClientAuth = Boolean.valueOf(
sslNeedClientAuthStr).booleanValue();
String serverKeystorePassword = null;
String loginConfigName = null;
String passwordFileName = null;
String keystorePasswordFileName = null;
String accessFileName = null;
// Initialize settings when authentication is active
if (useAuthentication) {
// Get non-default login configuration
loginConfigName = props.getProperty(PropertyNames.LOGIN_CONFIG_NAME);
if (loginConfigName == null) {
// Get password file
passwordFileName = props.getProperty(
PropertyNames.PASSWORD_FILE_NAME,
getDefaultFileName(DefaultValues.PASSWORD_FILE_NAME));
checkPasswordFile(passwordFileName);
}
// Get access file
accessFileName = props.getProperty(
PropertyNames.ACCESS_FILE_NAME,
getDefaultFileName(DefaultValues.ACCESS_FILE_NAME));
checkAccessFile(accessFileName);
}
if (useSsl) {
// Get keystore password file
keystorePasswordFileName = props.getProperty(PropertyNames.SSL_SERVER_KEYSTORE_PASSWORD_FILE);
// get the keystore password from the keystore password file
// (/var/sgeCA/portNNNN/sge_cell/private/keystore.password)
// workaround for euid problem of libjvm under Linux otherwise jmxremote.password
// could have been used
try {
serverKeystorePassword = propertiesFromFile(keystorePasswordFileName).getProperty(PropertyNames.SSL_SERVER_KEYSTORE_PASSWORD);
} catch (IOException ex) {
throw new AgentConfigurationError(AGENT_EXCEPTION, ex, ex.getMessage());
}
// setup SSLContext to use different TrustManager and KeyManager
final String serverKeystore = props.getProperty(PropertyNames.SSL_SERVER_KEYSTORE);
File serverKeystoreFile = new File(serverKeystore);
File caTop = JGDIAgent.getCaTop();
String serverHost = "";
try {
serverHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
throw new AgentConfigurationError(AGENT_EXCEPTION, ex, "Can't resolve local host");
}
char[] pw = (serverKeystorePassword != null) ? serverKeystorePassword.toCharArray() : "".toCharArray();
log.log(Level.FINE, "SSLHelper.init: caTop = {0} serverKeystore = {1} serverKeystorePW = {2}",
new Object[]{caTop, serverKeystore, (serverKeystorePassword != null) ? serverKeystorePassword : "-empty pw-"});
SSLHelper.getInstanceByKey(serverHost, serverPort, caTop).setKeystore(serverKeystoreFile, pw);
}
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
"initialize",
Agent.getText("jmxremote.ConnectorBootstrap.initialize") + "\n\t" + PropertyNames.PORT + "=" + serverPort + "\n\t" + PropertyNames.USE_SSL + "=" + useSsl + "\n\t" + PropertyNames.USE_REGISTRY_SSL + "=" + useRegistrySsl + "\n\t" + PropertyNames.SSL_ENABLED_CIPHER_SUITES + "=" + enabledCipherSuites + "\n\t" + PropertyNames.SSL_ENABLED_PROTOCOLS + "=" + enabledProtocols + "\n\t" + PropertyNames.SSL_NEED_CLIENT_AUTH + "=" + sslNeedClientAuth + "\n\t" + PropertyNames.USE_AUTHENTICATION + "=" + useAuthentication + (useAuthentication ? (loginConfigName == null ? ("\n\t" + PropertyNames.PASSWORD_FILE_NAME + "=" + passwordFileName)
: ("\n\t" + PropertyNames.LOGIN_CONFIG_NAME + "=" + loginConfigName))
: "\n\t" + Agent.getText("jmxremote.ConnectorBootstrap.initialize.noAuthentication")) + (useAuthentication ? ("\n\t" + PropertyNames.ACCESS_FILE_NAME + "=" + accessFileName)
: "") + "");
}
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXConnectorServer cs = null;
try {
cs = exportMBeanServer(mbs, serverPort, useSsl, useRegistrySsl,
enabledCipherSuitesList, enabledProtocolsList,
sslNeedClientAuth, useAuthentication,
loginConfigName, passwordFileName, accessFileName);
final JMXServiceURL url = cs.getAddress();
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, "initialize", Agent.getText(
"jmxremote.ConnectorBootstrap.initialize.ready",
new JMXServiceURL(url.getProtocol(), url.getHost(),
url.getPort(), "/jndi/rmi://" + url.getHost() + ":" + serverPort + "/" + "jmxrmi").toString()));
}
} catch (Exception e) {
throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
}
return cs;
}