in gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/DiscoveryApiClient.java [73:140]
private void configure(GatewayConfig gatewayConfig, AliasService aliasService, KeyStore trustStore) {
String apiAddress = config.getAddress();
apiAddress += (apiAddress.endsWith("/") ? API_PATH : "/" + API_PATH);
setBasePath(apiAddress);
String username = config.getUser();
String passwordAlias = config.getPasswordAlias();
String password = null;
// If no configured username, then use default username alias
if (username == null) {
if (aliasService != null) {
try {
char[] defaultUser = aliasService.getPasswordFromAliasForGateway(DEFAULT_USER_ALIAS);
if (defaultUser != null) {
username = new String(defaultUser);
}
} catch (AliasServiceException e) {
log.aliasServiceUserError(DEFAULT_USER_ALIAS, e.getLocalizedMessage());
}
}
// If username is still null
if (username == null) {
log.aliasServiceUserNotFound();
throw new ConfigurationException("No username is configured for Cloudera Manager service discovery.");
}
}
if (aliasService != null) {
// If no password alias is configured, then try the default alias
if (passwordAlias == null) {
passwordAlias = DEFAULT_PWD_ALIAS;
}
try {
char[] pwd = aliasService.getPasswordFromAliasForGateway(passwordAlias);
if (pwd != null) {
password = new String(pwd);
}
} catch (AliasServiceException e) {
log.aliasServicePasswordError(passwordAlias, e.getLocalizedMessage());
}
}
// If the password could not be determined
if (password == null) {
log.aliasServicePasswordNotFound();
isKerberos = Boolean.getBoolean(GatewayConfig.HADOOP_KERBEROS_SECURED);
}
setUsername(username);
setPassword(password);
if (isKerberos) {
// If there is a Kerberos subject, then add the SPNEGO auth interceptor
Subject subject = AuthUtils.getKerberosSubject();
if (subject != null) {
SpnegoAuthInterceptor spnegoInterceptor = new SpnegoAuthInterceptor(subject);
getHttpClient().interceptors().add(spnegoInterceptor);
}
}
configureTimeouts(gatewayConfig);
configureSsl(gatewayConfig, trustStore);
}