aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap
diff options
context:
space:
mode:
authorGeora Barsky <georab@amdocs.com>2018-08-30 09:54:28 -0400
committerGeora Barsky <georab@amdocs.com>2018-08-30 10:15:52 -0400
commitae69dc13d976b67c0278890b852444a134e23ca9 (patch)
treef25d74415edbd6f581b31f74efe942510abd116a /src/main/java/org/onap
parent21e55f946f9238a519c0084846f7052b5bab0327 (diff)
Fix the issue of missing auth header
Issue-ID: LOG-639 Change-Id: I7a3cf856da797f99d94a953a20cd2145c9f74302 Signed-off-by: Geora Barsky <georab@amdocs.com>
Diffstat (limited to 'src/main/java/org/onap')
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java7
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java4
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java16
3 files changed, 19 insertions, 8 deletions
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java b/src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java
index 98370bd..9c6d11d 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/AAIConfiguration.java
@@ -76,6 +76,13 @@ public class AAIConfiguration {
return ("Basic " + encodedAuth);
}
+ @Bean(name="aaiBasicAuthorization")
+ public String getAAIBasicAuth() {
+ String auth = new String(this.username + ":" + Password.deobfuscate(this.password));
+ String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes());
+ return ("Basic " + encodedAuth);
+ }
+
@Bean(name="aaiClient")
public RestClient restClient() {
RestClient restClient = new RestClient();
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
index 9a542a4..ff09e55 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/SpringServiceImpl.java
@@ -37,6 +37,8 @@ public class SpringServiceImpl implements SpringService {
private String aaiBaseUrl;
@Autowired
private String aaiServiceInstancePath;
+ @Autowired
+ private String aaiBasicAuthorization;
public SpringServiceImpl() {
// needed for instantiation
@@ -53,7 +55,7 @@ public class SpringServiceImpl implements SpringService {
// Retrieve the service instance information from AAI
try {
- context= RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiServiceInstancePath, tranId, serviceInstanceId, modelVersionId, modelInvariantId, serviceType, customerId);
+ context= RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiServiceInstancePath, tranId, serviceInstanceId, modelVersionId, modelInvariantId, serviceType, customerId,aaiBasicAuthorization);
} catch (AuditException ae) {
throw ae;
} catch (Exception e) {
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
index a997ebc..da7d241 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
@@ -83,6 +83,7 @@ public class RestUtil {
private static final String DELIMITER = "$";
private static final String DEPTH = "?depth=2";
+
/**
* Validates the URL parameter.
*
@@ -162,7 +163,7 @@ public class RestUtil {
*/
public static ModelContext retrieveAAIModelData(RestClient aaiClient, String baseURL, String aaiServiceInstancePath,
String transactionId, String serviceInstanceId, String modelVersionId, String modelInvariantId,
- String serviceType, String customerId) throws AuditException {
+ String serviceType, String customerId, String aaiBasicAuthorization) throws AuditException {
String serviceInstancePayload = null;
String genericVNFPayload = null;
String vnfcPayload = null;
@@ -177,7 +178,7 @@ public class RestUtil {
+ generateServiceInstanceURL(aaiServiceInstancePath, customerId, serviceType, serviceInstanceId);
// Response from service instance API call
serviceInstancePayload =
- getResource(aaiClient, url, transactionId, MediaType.valueOf(MediaType.APPLICATION_XML));
+ getResource(aaiClient, url, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON));
// Handle the case if the service instance is not found in AAI
if (isEmptyJson(serviceInstancePayload)) {
@@ -197,7 +198,7 @@ public class RestUtil {
String genericVNFURL = baseURL + genericVNFLink + DEPTH;
// Response from generic VNF API call
genericVNFPayload =
- getResource(aaiClient, genericVNFURL, transactionId, MediaType.valueOf(MediaType.APPLICATION_XML));
+ getResource(aaiClient, genericVNFURL, aaiBasicAuthorization, transactionId, MediaType.valueOf(MediaType.APPLICATION_JSON));
if (isEmptyJson(genericVNFPayload)) {
log.info(LogMessages.NOT_FOUND, "GenericVNF with url ", genericVNFLink);
@@ -214,7 +215,7 @@ public class RestUtil {
List<VnfcInstance> vnfcLst = new ArrayList<VnfcInstance>();
for (String vnfcLink : vnfcLinkLst) {
String vnfcURL = baseURL + vnfcLink;
- vnfcPayload = getResource(aaiClient, vnfcURL, transactionId,
+ vnfcPayload = getResource(aaiClient, vnfcURL, aaiBasicAuthorization, transactionId,
MediaType.valueOf(MediaType.APPLICATION_XML));
if (isEmptyJson(vnfcPayload)) {
@@ -410,17 +411,18 @@ public class RestUtil {
@SuppressWarnings("unchecked")
- private static Map<String, List<String>> buildHeaders(String transactionId) {
+ private static Map<String, List<String>> buildHeaders(String aaiBasicAuthorization, String transactionId) {
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
headers.put(TRANSACTION_ID, Collections.singletonList(transactionId));
headers.put(FROM_APP_ID, Collections.singletonList(APP_NAME));
+ headers.put(AUTHORIZATION, Collections.singletonList(aaiBasicAuthorization));
return headers;
}
- private static String getResource(RestClient client, String url, String transId, MediaType mediaType)
+ private static String getResource(RestClient client, String url, String aaiBasicAuthorization, String transId, MediaType mediaType)
throws AuditException {
- OperationResult result = client.get(url, buildHeaders(transId), MediaType.valueOf(MediaType.APPLICATION_JSON));
+ OperationResult result = client.get(url, buildHeaders(aaiBasicAuthorization, transId), MediaType.valueOf(MediaType.APPLICATION_JSON));
if (result.getResultCode() == 200) {
return result.getResult();