diff options
author | Singla, Rajiv (rs153v) <rs153v@att.com> | 2018-04-20 12:02:19 -0400 |
---|---|---|
committer | Singla, Rajiv (rs153v) <rs153v@att.com> | 2018-04-20 12:02:52 -0400 |
commit | 4754cc656acb01fed18da470ebc99f2d6debd9fe (patch) | |
tree | def1c7fe120fd05bc6e2ab1d167519c789a8d54b /dcae-analytics-aai/src/main | |
parent | aeb9ac94415a2e7825ff2d5de3b6560498e02df8 (diff) |
TCA:Added A&AI Authorization Header
Change-Id: I8c647d49ccd9a950402952ddbbb7699ffefa3d90
Signed-off-by: Singla, Rajiv (rs153v) <rs153v@att.com>
Issue-ID: DCAEGEN2-463
Diffstat (limited to 'dcae-analytics-aai/src/main')
-rw-r--r-- | dcae-analytics-aai/src/main/java/org/onap/dcae/apod/analytics/aai/service/AAIHttpClientImpl.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/dcae-analytics-aai/src/main/java/org/onap/dcae/apod/analytics/aai/service/AAIHttpClientImpl.java b/dcae-analytics-aai/src/main/java/org/onap/dcae/apod/analytics/aai/service/AAIHttpClientImpl.java index 03526ac..e13117b 100644 --- a/dcae-analytics-aai/src/main/java/org/onap/dcae/apod/analytics/aai/service/AAIHttpClientImpl.java +++ b/dcae-analytics-aai/src/main/java/org/onap/dcae/apod/analytics/aai/service/AAIHttpClientImpl.java @@ -22,7 +22,9 @@ package org.onap.dcae.apod.analytics.aai.service; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpHeaders; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.Credentials; @@ -34,6 +36,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.DefaultProxyRoutePlanner; +import org.apache.http.message.BasicHeader; import org.apache.http.ssl.SSLContextBuilder; import org.onap.dcae.apod.analytics.aai.domain.config.AAIHttpClientConfig; import org.onap.dcae.apod.analytics.aai.utils.ssl.AlwaysTrustingTrustStrategy; @@ -42,9 +45,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.URL; +import java.nio.charset.Charset; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; /** * <p> @@ -108,13 +113,14 @@ public class AAIHttpClientImpl implements AAIHttpClient { final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); if (aaiUserName != null) { - final String aaiHost = aaiHttpClientConfig.getAaiHost(); - final Integer aaiHostPortNumber = aaiHttpClientConfig.getAaiHostPortNumber(); + // add basic authentication header + LOG.info("Setting A&AI authentication headers with username: {}", aaiUserName); final String aaiUserPassword = aaiHttpClientConfig.getAaiUserPassword(); - LOG.info("Setting A&AI host credentials for AAI Host: {}", aaiHost); - final AuthScope aaiHostPortAuthScope = new AuthScope(aaiHost, aaiHostPortNumber); - final Credentials aaiCredentials = new UsernamePasswordCredentials(aaiUserName, aaiUserPassword); - credentialsProvider.setCredentials(aaiHostPortAuthScope, aaiCredentials); + final String auth = aaiUserName + ":" + aaiUserPassword; + final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII"))); + final String authHeader = "Basic " + new String(encodedAuth); + final BasicHeader basicAuthHeader = new BasicHeader(HttpHeaders.AUTHORIZATION, authHeader); + httpClientBuilder.setDefaultHeaders(Arrays.asList(basicAuthHeader)); } else { LOG.warn("A&AI userName not present. No credentials set for A&AI authentication"); } |