diff options
13 files changed, 153 insertions, 39 deletions
diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java index 537de3e238..be5af5d51f 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/tenantIsolation/AaiClientPropertiesImpl.java @@ -49,4 +49,14 @@ public class AaiClientPropertiesImpl implements AAIProperties { public AAIVersion getDefaultVersion() { return AAIVersion.LATEST; } + + @Override + public String getAuth() { + return props.getProperty("aai.auth", null); + } + + @Override + public String getKey() { + return props.getProperty("mso.msoKey", null); + } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java index 3e315a5f04..16fd351b43 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/adapter/vnf/AdapterRestClient.java @@ -21,7 +21,6 @@ package org.openecomp.mso.client.adapter.vnf; import java.net.URI; -import java.security.GeneralSecurityException; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -29,8 +28,6 @@ import java.util.UUID; import javax.ws.rs.client.ClientResponseFilter; import javax.ws.rs.ext.ContextResolver; -import org.apache.commons.codec.binary.Base64; -import org.openecomp.mso.bpmn.common.util.CryptoUtils; import org.openecomp.mso.client.ResponseExceptionMapperImpl; import org.openecomp.mso.client.policy.JettisonStyleMapperProvider; import org.openecomp.mso.client.policy.RestClient; @@ -52,8 +49,7 @@ public class AdapterRestClient extends RestClient { @Override protected void initializeHeaderMap(Map<String, String> headerMap) { - headerMap.put("Authorization", - this.getBasicAuth(props.getAuth(), props.getKey())); + addBasicAuthHeader(props.getAuth(), props.getKey()); } @Override @@ -70,20 +66,4 @@ public class AdapterRestClient extends RestClient { protected ContextResolver<ObjectMapper> getMapper() { return new JettisonStyleMapperProvider(); } - - private String getBasicAuth(String encryptedAuth, String msoKey) { - if ((encryptedAuth == null || encryptedAuth.isEmpty()) || (msoKey == null || msoKey.isEmpty())) { - return null; - } - try { - String auth = CryptoUtils.decrypt(encryptedAuth, msoKey); - byte[] encoded = Base64.encodeBase64(auth.getBytes()); - String encodedString = new String(encoded); - encodedString = "Basic " + encodedString; - return encodedString; - } catch (GeneralSecurityException e) { - this.logger.warn(e.getMessage(), e); - return null; - } - } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java index 27352dc11d..a1ef35a49d 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/restproperties/AAIPropertiesImpl.java @@ -52,4 +52,13 @@ public class AAIPropertiesImpl implements AAIProperties { return AAIVersion.LATEST; } + @Override + public String getAuth() { + return props.get("aai.auth"); + } + + @Override + public String getKey() { + return props.get("mso.msoKey"); + } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy index 7ccc1b0046..6f41879e7d 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateResources.groovy @@ -20,6 +20,7 @@ package org.openecomp.mso.bpmn.infrastructure.scripts +import org.codehaus.jackson.map.ObjectMapper import org.openecomp.mso.bpmn.infrastructure.properties.BPMNProperties import java.util.ArrayList @@ -146,7 +147,28 @@ public class DoCreateResources extends AbstractServiceTaskProcessor execution.setVariable("sequencedResourceList", sequencedResourceList) utils.log("INFO", "sequencedResourceList: " + sequencedResourceList, isDebugEnabled) utils.log("INFO", "======== COMPLETED sequenceResoure Process ======== ", isDebugEnabled) - } + } + + public prepareServiceTopologyRequest(DelegateExecution execution) { + + def isDebugEnabled = execution.getVariable("isDebugLogEnabled") + utils.log("INFO", "======== Start prepareServiceTopologyRequest Process ======== ", isDebugEnabled) + + String serviceDecompose = execution.getVariable("serviceDecomposition") + + execution.setVariable("operationType", "create") + execution.setVariable("resourceType", "") + + String serviceInvariantUuid = jsonUtil.getJsonValue(serviceDecompose, "serviceResources.modelInfo.modelInvariantUuid") + String serviceUuid = jsonUtil.getJsonValue(serviceDecompose, "serviceResources.modelInfo.modelUuid") + String serviceModelName = jsonUtil.getJsonValue(serviceDecompose, "serviceResources.modelInfo.modelName") + + execution.setVariable("modelInvariantUuid", serviceInvariantUuid) + execution.setVariable("modelUuid", serviceUuid) + execution.setVariable("serviceModelName", serviceModelName) + + utils.log("INFO", "======== End prepareServiceTopologyRequest Process ======== ", isDebugEnabled) + } public void getCurrentResoure(DelegateExecution execution){ def isDebugEnabled=execution.getVariable("isDebugLogEnabled") diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateResources.bpmn b/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateResources.bpmn index 9ed1431ed8..5bb3d315b0 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateResources.bpmn +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/subprocess/DoCreateResources.bpmn @@ -20,7 +20,7 @@ def csi = new DoCreateResources() csi.postConfigRequest(execution)]]></bpmn2:script> </bpmn2:scriptTask> <bpmn2:serviceTask id="Task_0io5qby" name="Call Sync SDNC service Create " camunda:class="org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.SdncServiceTopologyOperationTask"> - <bpmn2:incoming>SequenceFlow_1vprtt9</bpmn2:incoming> + <bpmn2:incoming>SequenceFlow_0k0f7lm</bpmn2:incoming> <bpmn2:outgoing>SequenceFlow_11f2zuu</bpmn2:outgoing> </bpmn2:serviceTask> <bpmn2:sequenceFlow id="SequenceFlow_11f2zuu" sourceRef="Task_0io5qby" targetRef="IntermediateThrowEvent_0f2w7aj" /> @@ -85,7 +85,7 @@ ddsi.executeResourceRecipe(execution)]]></bpmn2:script> <bpmn2:incoming>SequenceFlow_11f2zuu</bpmn2:incoming> <bpmn2:linkEventDefinition name="ResourceLoop" /> </bpmn2:intermediateThrowEvent> - <bpmn2:sequenceFlow id="SequenceFlow_1vprtt9" name="yes" sourceRef="ExclusiveGateway_07rr3wp" targetRef="Task_0io5qby"> + <bpmn2:sequenceFlow id="SequenceFlow_1vprtt9" name="yes" sourceRef="ExclusiveGateway_07rr3wp" targetRef="Task_1blaq0f"> <bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression"><![CDATA[#{(execution.getVariable("isContainsWanResource" ) == "true" )}]]></bpmn2:conditionExpression> </bpmn2:sequenceFlow> <bpmn2:intermediateCatchEvent id="IntermediateCatchEvent_05dus9b" name="StartPrepareResource"> @@ -126,6 +126,14 @@ ex.processJavaException(execution)]]></bpmn2:script> <bpmn2:sequenceFlow id="SequenceFlow_0gr9xqj" name="" sourceRef="StartEvent_0x7o2ug" targetRef="ScriptTask_1648adp" /> <bpmn2:sequenceFlow id="SequenceFlow_0a6l29p" name="" sourceRef="ScriptTask_1648adp" targetRef="EndEvent_0lgdyyb" /> </bpmn2:subProcess> + <bpmn2:scriptTask id="Task_1blaq0f" name="Prepare SDNC service Create" scriptFormat="groovy"> + <bpmn2:incoming>SequenceFlow_1vprtt9</bpmn2:incoming> + <bpmn2:outgoing>SequenceFlow_0k0f7lm</bpmn2:outgoing> + <bpmn2:script><![CDATA[import org.openecomp.mso.bpmn.infrastructure.scripts.* +def ddsi = new DoCreateResources() +ddsi.prepareServiceTopologyRequest(execution)]]></bpmn2:script> + </bpmn2:scriptTask> + <bpmn2:sequenceFlow id="SequenceFlow_0k0f7lm" sourceRef="Task_1blaq0f" targetRef="Task_0io5qby" /> </bpmn2:process> <bpmn2:error id="Error_2" name="MSOWorkflowException" errorCode="MSOWorkflowException" /> <bpmn2:error id="Error_1" name="java.lang.Exception" errorCode="java.lang.Exception" /> @@ -144,15 +152,15 @@ ex.processJavaException(execution)]]></bpmn2:script> <dc:Bounds x="1119" y="485" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape id="ServiceTask_0qi8cgg_di" bpmnElement="Task_0io5qby"> - <dc:Bounds x="944" y="353" width="100" height="80" /> + <dc:Bounds x="1047" y="353" width="100" height="80" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge id="SequenceFlow_11f2zuu_di" bpmnElement="SequenceFlow_11f2zuu"> - <di:waypoint xsi:type="dc:Point" x="1044" y="393" /> - <di:waypoint xsi:type="dc:Point" x="1090" y="393" /> - <di:waypoint xsi:type="dc:Point" x="1090" y="300" /> + <di:waypoint xsi:type="dc:Point" x="1147" y="393" /> + <di:waypoint xsi:type="dc:Point" x="1219" y="393" /> + <di:waypoint xsi:type="dc:Point" x="1219" y="300" /> <di:waypoint xsi:type="dc:Point" x="1315" y="300" /> <bpmndi:BPMNLabel> - <dc:Bounds x="1060" y="340.5" width="90" height="12" /> + <dc:Bounds x="1189" y="340.5" width="90" height="12" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNShape id="ScriptTask_1y0los4_di" bpmnElement="ScriptTask_1y0los4"> @@ -243,7 +251,7 @@ ex.processJavaException(execution)]]></bpmn2:script> <bpmndi:BPMNEdge id="SequenceFlow_1vprtt9_di" bpmnElement="SequenceFlow_1vprtt9"> <di:waypoint xsi:type="dc:Point" x="778" y="325" /> <di:waypoint xsi:type="dc:Point" x="778" y="393" /> - <di:waypoint xsi:type="dc:Point" x="944" y="393" /> + <di:waypoint xsi:type="dc:Point" x="861" y="394" /> <bpmndi:BPMNLabel> <dc:Bounds x="784" y="353" width="20" height="12" /> </bpmndi:BPMNLabel> @@ -347,6 +355,16 @@ ex.processJavaException(execution)]]></bpmn2:script> <dc:Bounds x="567.5" y="888" width="0" height="12" /> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ScriptTask_0dh2mj1_di" bpmnElement="Task_1blaq0f"> + <dc:Bounds x="861" y="354" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0k0f7lm_di" bpmnElement="SequenceFlow_0k0f7lm"> + <di:waypoint xsi:type="dc:Point" x="961" y="394" /> + <di:waypoint xsi:type="dc:Point" x="1047" y="393" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1004" y="372.5" width="0" height="12" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </bpmn2:definitions> diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java index 358bbbbbec..c208d6dd5f 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIProperties.java @@ -25,4 +25,6 @@ import org.openecomp.mso.client.RestProperties; public interface AAIProperties extends RestProperties { public AAIVersion getDefaultVersion(); + public String getAuth(); + public String getKey(); } diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java index 9348beb02a..e36033faa0 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClient.java @@ -28,22 +28,31 @@ import java.util.UUID; import javax.ws.rs.client.ClientResponseFilter; import javax.ws.rs.ext.ContextResolver; -import org.openecomp.mso.client.RestProperties; import org.openecomp.mso.client.policy.RestClient; import org.openecomp.mso.client.policy.RestClientSSL; import com.fasterxml.jackson.databind.ObjectMapper; public class AAIRestClient extends RestClientSSL { + + private final AAIProperties props; - protected AAIRestClient(RestProperties props, UUID requestId, URI uri) { + protected AAIRestClient(AAIProperties props, UUID requestId, URI uri) { super(props, requestId, Optional.of(uri)); + this.props = props; headerMap.put("X-TransactionId", requestId.toString()); } @Override protected void initializeHeaderMap(Map<String, String> headerMap) { headerMap.put("X-FromAppId", "MSO"); + + String auth = props.getAuth(); + String key = props.getKey(); + + if (auth != null && !auth.isEmpty() && key != null && !key.isEmpty()) { + addBasicAuthHeader(auth, key); + } } @Override diff --git a/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java b/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java index 354d47af06..3f5bfa97d0 100644 --- a/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java +++ b/common/src/main/java/org/openecomp/mso/client/defaultproperties/DefaultAAIPropertiesImpl.java @@ -65,4 +65,15 @@ public class DefaultAAIPropertiesImpl implements AAIProperties { return AAIVersion.LATEST; } + @Override + public String getAuth() { + Object value = props.get("aai.auth"); + return value == null ? null : value.toString(); + } + + @Override + public String getKey() { + Object value = props.get("mso.msoKey"); + return value == null ? null : value.toString(); + } } diff --git a/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java b/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java index 4e6ffd1c6a..77afe82758 100644 --- a/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java +++ b/common/src/main/java/org/openecomp/mso/client/policy/RestClient.java @@ -23,6 +23,7 @@ package org.openecomp.mso.client.policy; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; +import java.security.GeneralSecurityException; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -41,9 +42,11 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.ext.ContextResolver; +import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import org.openecomp.mso.client.RestProperties; import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.utils.CryptoUtils; import org.springframework.stereotype.Service; import com.fasterxml.jackson.databind.ObjectMapper; @@ -84,8 +87,6 @@ public abstract class RestClient { this(props, requestId, path); this.accept = accept; this.contentType = contentType; - this.requestId = requestId; - } protected RestClient(URL host, UUID requestId, String contentType) { @@ -134,6 +135,21 @@ public abstract class RestClient { protected abstract Optional<ClientResponseFilter> addResponseFilter(); public abstract RestClient addRequestId(UUID requestId); + + /** + * Adds a basic authentication header to the request. + * @param auth the encrypted credentials + * @param key the key for decrypting the credentials + */ + protected void addBasicAuthHeader(String auth, String key) { + try { + byte[] decryptedAuth = CryptoUtils.decrypt(auth, key).getBytes(); + String authHeaderValue = "Basic " + new String(Base64.encodeBase64(decryptedAuth)); + headerMap.put("Authorization", authHeaderValue); + } catch (GeneralSecurityException e) { + logger.warn(e.getMessage(), e); + } + } protected ContextResolver<ObjectMapper> getMapper() { return new CommonObjectMapperProvider(); diff --git a/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java index daf8130cd4..c7cc549130 100644 --- a/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java +++ b/common/src/test/java/org/openecomp/mso/client/aai/AAIResourcesClientTest.java @@ -78,6 +78,21 @@ public class AAIResourcesClientTest { } @Test + public void verifyBasicAuth() { + AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); + wireMockRule.stubFor(get( + urlPathEqualTo("/aai/" + AAIVersion.LATEST + path.build().toString())) + .withHeader("Authorization", equalTo("Basic TVNPOk1TTw==")) + .willReturn( + aResponse() + .withHeader("Content-Type", "application/json") + .withBodyFile("aai/resources/mockObject.json") + .withStatus(200))); + AAIResourcesClient client = new AAIResourcesClient(); + client.get(path); + } + + @Test public void verifyConnect() { AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test2"); AAIResourceUri path2 = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test3"); diff --git a/common/src/test/resources/aai.properties b/common/src/test/resources/aai.properties index 9d9f1bdce9..897659b332 100644 --- a/common/src/test/resources/aai.properties +++ b/common/src/test/resources/aai.properties @@ -1 +1,3 @@ -aai.endpoint=http://localhost:8443
\ No newline at end of file +aai.endpoint=http://localhost:8443 +aai.auth=2630606608347B7124C244AB0FE34F6F +mso.msoKey=07a7159d3bf51a0e53be7a8f89699be7
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java index 03af038574..92e74e8de2 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/AaiClientPropertiesImpl.java @@ -49,4 +49,14 @@ public class AaiClientPropertiesImpl implements AAIProperties { public AAIVersion getDefaultVersion() { return AAIVersion.LATEST; } + + @Override + public String getAuth() { + return props.getProperty("aai.auth", null); + } + + @Override + public String getKey() { + return props.getProperty("mso.msoKey", null); + } } diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java index 27c94f0770..4fb5ebc1f8 100644 --- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java +++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java @@ -93,8 +93,8 @@ public class CatalogDatabase implements Closeable { private static final String MODEL_TYPE = "modelType"; private static final String MODEL_VERSION_ID = "modelVersionId"; private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUuid"; - private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId"; - private static final String NETWORK_SERVICE = "network service"; + private static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUId"; + private static final String NETWORK_SERVICE = "network service"; protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL); @@ -4469,7 +4469,7 @@ public class CatalogDatabase implements Closeable { /** * Return a Network recipe that matches a given MODEL_UUID and ACTION * - * @param modelName + * @param networkModelUuid * @param action * @return NetworkRecipe object or null if none found */ @@ -4484,7 +4484,17 @@ public class CatalogDatabase implements Closeable { } NetworkRecipe recipe = getNetworkRecipeByNameVersion(networkResource.getModelName(), networkResource.getModelVersion(), action); - return recipe; + + if (recipe == null) { + recipe = getDefaultNetworkReceipe(action); + } + + return recipe; + } + + private NetworkRecipe getDefaultNetworkReceipe(String action) { + String modelName = "SDNC_DEFAULT"; + return getNetworkRecipe(modelName, action); } /** |