diff options
author | Geora Barsky <georab@amdocs.com> | 2018-08-30 09:54:28 -0400 |
---|---|---|
committer | Geora Barsky <georab@amdocs.com> | 2018-08-30 10:15:52 -0400 |
commit | ae69dc13d976b67c0278890b852444a134e23ca9 (patch) | |
tree | f25d74415edbd6f581b31f74efe942510abd116a | |
parent | 21e55f946f9238a519c0084846f7052b5bab0327 (diff) |
Fix the issue of missing auth header
Issue-ID: LOG-639
Change-Id: I7a3cf856da797f99d94a953a20cd2145c9f74302
Signed-off-by: Geora Barsky <georab@amdocs.com>
4 files changed, 35 insertions, 14 deletions
diff --git a/config/application.properties b/config/application.properties index c1645a2..a3cc78b 100644 --- a/config/application.properties +++ b/config/application.properties @@ -1,8 +1,20 @@ +# Copyright © 2018 Amdocs +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License spring.jersey.type=filter spring.mvc.urls=swagger,docs,prometheus,auditevents,info,heapdump,autoconfig,beans,loggers,dump,env,trace,health,configprops,mappings,metrics,webjars - server.contextPath=/aaicontextbuilder spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration @@ -14,11 +26,11 @@ server.tomcat.max-threads=200 server.tomcat.min-spare-threads=25 # AAI REST Client Configuration -aai.serviceName=10.147.57.139 -aai.servicePort=8080 +aai.serviceName=10.12.6.120 +aai.servicePort=30233 aai.username=AAI aai.password=OBF:1gfr1ev31gg7 -aai.httpProtocol=http +aai.httpProtocol=https aai.connectionTimeout=5000 aai.readTimeout=1000 @@ -29,7 +41,5 @@ http.password=OBF:1u2a1toa1w8v1tok1u30 # {0} = customerId {1} = serviceType {2} = serviceInstanceId aai.serviceInstancePath=/aai/v11/business/customers/customer/{0}/service-subscriptions/service-subscription/{1}/service-instances/service-instance/{2} - - #Servlet context parameters server.context_parameters.p-name=value #context parameter with p-name as key and value as value. 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(); |