if (!SocketUtil.isAvailable(hostname, port)) {
throw new IOException(String.format("Host %s on port %d could not be reached", hostname, port));
}
AuthenticationClient authenticationClient = new BasicAuthenticationClient();
authenticationClient.setConnectionInfo(hostname, port, ssl);
Properties properties = new Properties();
properties.put(BasicAuthenticationClient.VERIFY_SSL_CERT_PROP_NAME, String.valueOf(cliConfig.isVerifySSLCert()));
if (authenticationClient.isAuthEnabled()) {
output.printf("Authentication is enabled in the gateway server: %s.\n", hostname);
ConsoleReader reader = new ConsoleReader();
for (Credential credential : authenticationClient.getRequiredCredentials()) {
String prompt = "Please, specify " + credential.getDescription() + "> ";
String credentialValue;
if (credential.isSecret()) {
credentialValue = reader.readLine(prompt, '*');
} else {
credentialValue = reader.readLine(prompt);
}
properties.put(credential.getName(), credentialValue);
}
authenticationClient.configure(properties);
cliConfig.getClientConfig().setAuthenticationClient(authenticationClient);
authenticationClient.getAccessToken();
}
cliConfig.setConnection(hostname, port, ssl);
output.printf("Successfully connected CDAP instance at %s:%d\n", hostname, port);
}