diff options
author | Mohammadreza Pasandideh <mohammadreza.pasandideh@amdocs.com> | 2018-09-26 10:08:03 -0400 |
---|---|---|
committer | Mohammadreza Pasandideh <mohammadreza.pasandideh@amdocs.com> | 2018-09-26 11:45:46 -0400 |
commit | bfd0a3f241312a35d5bb30152a0b7742a429a9b8 (patch) | |
tree | 2f097894470217a0bd53160b59cee6dffbc1ee6b /pomba/service-decomposition | |
parent | 20289e87771520272f289093f0372460231a35c8 (diff) |
Add Authentication to AAI for POMBA SD
Issue-ID: LOG-696
Change-Id: If63697980dcc8d732d8514dbebd1cb9959700a73
Signed-off-by: Mohammadreza Pasandideh <mohammadreza.pasandideh@amdocs.com>
Diffstat (limited to 'pomba/service-decomposition')
4 files changed, 63 insertions, 20 deletions
diff --git a/pomba/service-decomposition/config/application.properties b/pomba/service-decomposition/config/application.properties index 116db83..d5add3a 100644 --- a/pomba/service-decomposition/config/application.properties +++ b/pomba/service-decomposition/config/application.properties @@ -19,12 +19,14 @@ basicAuth.username=admin basicAuth.password=OBF:1u2a1toa1w8v1tok1u30 # AAI REST Client Configuration -aai.serviceName=135.63.125.59 +aai.serviceName=10.12.6.118 aai.servicePort=8443 -aai.httpProtocol=http +aai.username=AAI +aai.password=OBF:1gfr1ev31gg7 +aai.httpProtocol=https aai.securityProtocol=TLS -aai.connectionTimeout=5000 -aai.readTimeout=1000 +aai.connectionTimeout=15000 +aai.readTimeout=15000 aai.resourceList=vnfc,vserver,l3-network aai.serviceInstancePath=/aai/v13/nodes/service-instance/{0} diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java index 6febf42..a163d2d 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/AAIConfiguration.java @@ -17,6 +17,8 @@ */ package org.onap.sdnc.apps.pomba.servicedecomposition; +import java.util.Base64; +import org.eclipse.jetty.util.security.Password; import org.onap.aai.restclient.client.RestClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -30,6 +32,12 @@ public class AAIConfiguration { @Value("${aai.servicePort}") private String port; + @Value("${aai.username}") + private String aaiUsername; + + @Value("${aai.password}") + private String aaiPassword; + @Value("${aai.httpProtocol}") private String httpProtocol; @@ -48,11 +56,29 @@ public class AAIConfiguration { @Value("${aai.resourceList}") private String resourceList; + @Value("${basicAuth.username:admin}") + private String username; + + @Value("${basicAuth.password:OBF:1u2a1toa1w8v1tok1u30}") + private String password; + + @Bean(name="aaiBasicAuthorization") + public String getAAIBasicAuth() { + return "Basic " + Base64.getEncoder().encodeToString((this.aaiUsername + ":" + Password.deobfuscate(this.aaiPassword)).getBytes()); + } + + @Bean(name="basicAuthHeader") + public String getSdBasicAuthHeader() { + return "Basic " + Base64.getEncoder().encodeToString((this.username + ":" + Password.deobfuscate(this.password)).getBytes()); + } + @Bean(name="aaiClient") public RestClient restClient() { return new RestClient() .validateServerHostname(false) .validateServerCertChain(false) + .basicAuthPassword(aaiUsername) + .basicAuthPassword(Password.deobfuscate(aaiPassword)) .connectTimeoutMs(this.connectionTimeout) .readTimeoutMs(this.readTimeout); } diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java index 384115e..56685ad 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/service/SpringServiceImpl.java @@ -25,6 +25,7 @@ import org.onap.sdnc.apps.pomba.servicedecomposition.util.RestUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import static org.onap.sdnc.apps.pomba.servicedecomposition.exception.DiscoveryException.Error.*; @org.springframework.stereotype.Service @@ -39,6 +40,9 @@ public class SpringServiceImpl implements SpringService { private String aaiBaseUrl; @Autowired + private String aaiBasicAuthorization; + + @Autowired private String aaiServiceInstancePath; @Autowired @@ -52,8 +56,16 @@ public class SpringServiceImpl implements SpringService { log.info("Querying A&AI for service instance " + serviceInstanceId); - JSONObject serviceInstance = RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiServiceInstancePath, aaiResourceList, - transactionId, serviceInstanceId, adapter); + JSONObject serviceInstance = null; + + try { + serviceInstance = RestUtil.retrieveAAIModelData(aaiClient, aaiBaseUrl, aaiBasicAuthorization, aaiServiceInstancePath, aaiResourceList, + transactionId, serviceInstanceId, adapter); + } catch (DiscoveryException de) { + throw de; + } catch (Exception e) { + throw new DiscoveryException(GENERAL_FAILURE, e , e.getLocalizedMessage()); + } return serviceInstance.toString(); } diff --git a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java index 99a929a..ffd7bf8 100644 --- a/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java +++ b/pomba/service-decomposition/src/main/java/org/onap/sdnc/apps/pomba/servicedecomposition/util/RestUtil.java @@ -51,6 +51,7 @@ public class RestUtil { private static final String TRANSACTION_ID = "X-TransactionId"; private static final String FROM_APP_ID = "X-FromAppId"; private static final String APP_NAME = "aaiCtxBuilder"; + private static final String AUTHORIZATION = "Authorization"; private static final Resource GENERIC_VNF = new Resource("generic-vnf"); @@ -104,22 +105,23 @@ public class RestUtil { /** * @param aaiClient * @param baseURL + * @param aaiBasicAuthorization * @param aaiServiceInstancePath + * @param aaiResourceList * @param transactionId * @param serviceInstanceId - * @param modelVersionId - * @param modelInvariantId + * @param adapter * @return * @throws DiscoveryException */ - public static JSONObject retrieveAAIModelData(RestClient aaiClient, String baseURL, String aaiServiceInstancePath, String aaiResourceList, + public static JSONObject retrieveAAIModelData(RestClient aaiClient, String baseURL, String aaiBasicAuthorization, String aaiServiceInstancePath, String aaiResourceList, String transactionId, String serviceInstanceId, ONAPLogAdapter adapter) throws DiscoveryException { // Follow two variables for transform purpose String url = baseURL + generateServiceInstanceURL(aaiServiceInstancePath, serviceInstanceId); // Response from service instance API call JSONObject serviceInstancePayload = new JSONObject( - getResource(aaiClient, url, transactionId)); + getResource(aaiClient, url, aaiBasicAuthorization, transactionId)); // Handle the case if the service instance is not found in AAI if (serviceInstancePayload == null || serviceInstancePayload.length() == 0) { logger.info("Service Instance " + serviceInstanceId + " is not found from AAI"); @@ -131,7 +133,7 @@ public class RestUtil { logger.info("The number of the relationships for service instance id {} is: {}", serviceInstanceId, relationMap.size()); - JSONObject response = processVNFRelationMap(aaiClient, aaiResourceList, baseURL, transactionId, relationMap, serviceInstancePayload); + JSONObject response = processVNFRelationMap(aaiClient, aaiResourceList, baseURL, aaiBasicAuthorization, transactionId, relationMap, serviceInstancePayload); return response; } @@ -143,7 +145,7 @@ public class RestUtil { * @param relationMap * @throws DiscoveryException */ - private static JSONObject processVNFRelationMap(RestClient aaiClient, String aaiResourceList, String baseURL, String transactionId, + private static JSONObject processVNFRelationMap(RestClient aaiClient, String aaiResourceList, String baseURL, String aaiBasicAuthorization, String transactionId, HashMap<String, List<String>> relationMap, JSONObject serviceInstancePayload) throws DiscoveryException { List<JSONObject> vnfLst = new ArrayList<JSONObject>(); // List of the VNF JSON along with related resources @@ -152,7 +154,7 @@ public class RestUtil { List<Resource> resourceTypes = getResourceTypes(aaiResourceList); if (relationMap.get(GENERIC_VNF.getResourceName()) != null) { - List<JSONObject> vnfList = processResourceList(aaiClient, baseURL, transactionId, GENERIC_VNF.getResourceName(), + List<JSONObject> vnfList = processResourceList(aaiClient, baseURL, aaiBasicAuthorization, transactionId, GENERIC_VNF.getResourceName(), relationMap.get(GENERIC_VNF.getResourceName())); // Logic to Create the Generic VNF JSON and extract further relationships for (JSONObject vnfPayload : vnfList) { @@ -160,7 +162,7 @@ public class RestUtil { List<String> vnfcLinkLst = extractRelatedLink(vnfPayload, resourceType.getResourceName()); if (vnfcLinkLst != null && !vnfcLinkLst.isEmpty()) { logger.info("The number of the API call for vnfc is:" + vnfcLinkLst.size()); - List<JSONObject> vnfcList = processResourceList(aaiClient, baseURL, transactionId, + List<JSONObject> vnfcList = processResourceList(aaiClient, baseURL, aaiBasicAuthorization, transactionId, resourceType.getResourceName(), vnfcLinkLst); if (vnfcList != null) { vnfPayload.put(resourceType.getCollectionName(), vnfcList); @@ -194,7 +196,7 @@ public class RestUtil { * @return * @throws DiscoveryException */ - private static List<JSONObject> processResourceList(RestClient aaiClient, String aaiBaseURL, String transactionId, + private static List<JSONObject> processResourceList(RestClient aaiClient, String aaiBaseURL, String aaiBasicAuthorization, String transactionId, String resourceType, List<String> resourceList) throws DiscoveryException { List<JSONObject> resourcePayloadList = new ArrayList<JSONObject>(); for (String resourceLink : resourceList) { @@ -207,7 +209,7 @@ public class RestUtil { // Response from generic VNF API call JSONObject resourcePayload = new JSONObject( - getResource(aaiClient, resourceURL, transactionId)); + getResource(aaiClient, resourceURL, aaiBasicAuthorization, transactionId)); if (resourcePayload == null || resourcePayload.length() == 0) { logger.info("Resource with url " + resourceLink + " is not found from AAI"); } else { @@ -265,14 +267,14 @@ public class RestUtil { /** * @param client * @param url + * @param aaiBasicAuthorization * @param transId - * @param mediaType * @return * @throws DiscoveryException */ - private static String getResource(RestClient client, String url, String transId) + private static String getResource(RestClient client, String url, String aaiBasicAuthorization, String transId) throws DiscoveryException { - 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) { String jsonString = result.getResult(); @@ -340,10 +342,11 @@ public class RestUtil { - 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; } |