// Get port number
final int port;
try {
port = Integer.parseInt(portStr);
} catch (NumberFormatException x) {
throw new AgentConfigurationError(INVALID_JMXREMOTE_PORT, x, portStr);
}
if (port < 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();
// Read SSL config file name
final String sslConfigFileName =
props.getProperty(PropertyNames.SSL_CONFIG_FILE_NAME);
String loginConfigName = null;
String passwordFileName = 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 (log.debugOn()) {
log.debug("initialize",
Agent.getText("jmxremote.ConnectorBootstrap.initialize") +
"\n\t" + PropertyNames.PORT + "=" + port +
"\n\t" + PropertyNames.USE_SSL + "=" + useSsl +
"\n\t" + PropertyNames.USE_REGISTRY_SSL + "=" + useRegistrySsl +
"\n\t" + PropertyNames.SSL_CONFIG_FILE_NAME + "=" + sslConfigFileName +
"\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, port, useSsl, useRegistrySsl,
sslConfigFileName, enabledCipherSuitesList,
enabledProtocolsList, sslNeedClientAuth,
useAuthentication, loginConfigName,
passwordFileName, accessFileName);
final JMXServiceURL url = cs.getAddress();
log.config("initialize",
Agent.getText("jmxremote.ConnectorBootstrap.initialize.ready",
new JMXServiceURL(url.getProtocol(),
url.getHost(),
url.getPort(),
"/jndi/rmi://"+url.getHost()+":"+port+"/"+
"jmxrmi").toString()));
} catch (Exception e) {
throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
}
return cs;
}