Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / externalapi / servlet / ArtifactExternalServlet.java
index 2bb28dd..b7bc2ce 100644 (file)
@@ -51,8 +51,6 @@ import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
-import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
 import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
 import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -66,7 +64,6 @@ import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
 import org.openecomp.sdc.be.servlets.AbstractValidationsServlet;
 import org.openecomp.sdc.be.servlets.RepresentationUtils;
-import org.openecomp.sdc.be.user.UserBusinessLogic;
 import org.openecomp.sdc.common.api.Constants;
 import org.openecomp.sdc.common.datastructure.Wrapper;
 import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -95,10 +92,10 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
     private HttpServletRequest request;
 
     @Inject
-    public ArtifactExternalServlet(UserBusinessLogic userBusinessLogic, ComponentInstanceBusinessLogic componentInstanceBL,
+    public ArtifactExternalServlet(ComponentInstanceBusinessLogic componentInstanceBL,
                                    ComponentsUtils componentsUtils, ServletUtils servletUtils, ResourceImportManager resourceImportManager,
                                    ArtifactsBusinessLogic artifactsBusinessLogic) {
-        super(userBusinessLogic, componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
+        super(componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
         this.artifactsBusinessLogic = artifactsBusinessLogic;
     }
 
@@ -207,7 +204,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
         @ApiResponse(responseCode = "400", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
         @ApiResponse(responseCode = "400", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
-    @PermissionAllowed({AafPermission.PermNames.WRITE_VALUE})
     public Response uploadArtifact(
         @Parameter(description = "Determines the format of the body of the request", required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
         @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body", required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
@@ -291,7 +287,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
         @ApiResponse(responseCode = "400", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
         @ApiResponse(responseCode = "400", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
-    @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
     public Response uploadArtifactToInstance(
         @Parameter(description = "Determines the format of the body of the request", required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
         @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body", required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
@@ -375,7 +370,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
         @ApiResponse(responseCode = "403", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
         @ApiResponse(responseCode = "409", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
-    @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
     public Response updateArtifact(
         @Parameter(description = "Determines the format of the body of the request", required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
         @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body", required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
@@ -462,7 +456,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
         @ApiResponse(responseCode = "403", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
         @ApiResponse(responseCode = "409", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
-    @PermissionAllowed(AafPermission.PermNames.WRITE_VALUE)
     public Response updateArtifactOnResourceInstance(
         @Parameter(description = "Determines the format of the body of the request", required = true) @HeaderParam(value = Constants.CONTENT_TYPE_HEADER) String contentType,
         @Parameter(description = "The value for this header must be the MD5 checksum over the whole json body", required = true) @HeaderParam(value = Constants.MD5_HEADER) String checksum,
@@ -536,7 +529,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
     @Path("/{assetType}/{uuid}/artifacts/{artifactUUID}")
     @Produces(MediaType.APPLICATION_JSON)
     @Operation(description = "deletes an artifact of a resource or service", method = "DELETE", summary = "deletes an artifact of a resource or service", responses = {
-        @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+        @ApiResponse(description = "default response", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
         @ApiResponse(responseCode = "200", description = "Artifact deleted", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),
@@ -550,7 +543,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
         @ApiResponse(responseCode = "403", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
         @ApiResponse(responseCode = "409", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
-    @PermissionAllowed(AafPermission.PermNames.DELETE_VALUE)
     public Response deleteArtifact(
         @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
@@ -620,7 +612,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
     @Path("{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
     @Produces(MediaType.APPLICATION_JSON)
     @Operation(description = "deletes an artifact of a resource insatnce", method = "DELETE", summary = "deletes an artifact of a resource insatnce", responses = {
-        @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+        @ApiResponse(description = "default response", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
         @ApiResponse(responseCode = "200", description = "Artifact deleted", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ArtifactDefinition.class)))),
         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),
@@ -634,7 +626,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "400", description = "Artifact name is missing in input - SVC4128"),
         @ApiResponse(responseCode = "403", description = "Asset is being edited by different user. Only one user can checkout and edit an asset on given time. The asset will be available for checkout after the other user will checkin the asset - SVC4086"),
         @ApiResponse(responseCode = "409", description = "Restricted Operation – the user provided does not have role of Designer or the asset is being used by another designer - SVC4301")})
-    @PermissionAllowed(AafPermission.PermNames.DELETE_VALUE)
     public Response deleteArtifactOnResourceInstance(
         @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
@@ -712,7 +703,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "405", description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
         @ApiResponse(responseCode = "500", description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),
         @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})
-    @PermissionAllowed(AafPermission.PermNames.DELETE_VALUE)
     public Response downloadComponentArtifact(
         @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
@@ -741,18 +731,23 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
         }
         ResourceCommonInfo resourceCommonInfo = new ResourceCommonInfo(componentTypeValue);
-        try {
-            if (responseWrapper.isEmpty()) {
-                byte[] value = artifactsBusinessLogic.downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, resourceCommonInfo);
-                InputStream is = new ByteArrayInputStream(value);
-                Map<String, String> headers = new HashMap<>();
-                headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
-                responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
-                responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
-            }
+        if (!responseWrapper.isEmpty()) {
+            getComponentsUtils().auditExternalDownloadArtifact(responseFormat,
+                resourceCommonInfo, new DistributionData(instanceIdHeader, requestURI),
+                requestId, artifactUUID, userId);
+            return responseWrapper.getInnerElement();
+        }
+        byte[] value = artifactsBusinessLogic.downloadComponentArtifactByUUIDs(componentType, uuid, artifactUUID, resourceCommonInfo);
+        try (InputStream is = new ByteArrayInputStream(value)) {
+            Map<String, String> headers = new HashMap<>();
+            headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
+            responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+            responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
         } catch (ComponentException e) {
             responseFormat = getComponentsUtils().getResponseFormat(e);
             throw e;
+        } catch (IOException e) {
+            log.debug("close ByteArrayInputStream error");
         } finally {
             getComponentsUtils()
                 .auditExternalDownloadArtifact(responseFormat, resourceCommonInfo, new DistributionData(instanceIdHeader, requestURI), requestId,
@@ -768,7 +763,7 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
     @Path("/{assetType}/{uuid}/resourceInstances/{resourceInstanceName}/artifacts/{artifactUUID}")
     @Produces(MediaType.APPLICATION_OCTET_STREAM)
     @Operation(description = "Download resource instance artifact", method = "GET", summary = "Returns downloaded artifact", responses = {
-        @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+        @ApiResponse(description = "default response", content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
         @ApiResponse(responseCode = "200", description = "Artifact downloaded", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))),
         @ApiResponse(responseCode = "400", description = "Missing  'X-ECOMP-InstanceID'  HTTP header - POL5001"),
         @ApiResponse(responseCode = "401", description = "ECOMP component  should authenticate itself  and  to  re-send  again  HTTP  request  with its Basic  Authentication credentials - POL5002"),
@@ -777,7 +772,6 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
         @ApiResponse(responseCode = "405", description = "Method  Not Allowed: Invalid HTTP method type used (PUT,DELETE,POST will be rejected) - POL4050"),
         @ApiResponse(responseCode = "500", description = "The GET request failed either due to internal SDC problem or Cambria Service failure. ECOMP Component should continue the attempts to get the needed information - POL5000"),
         @ApiResponse(responseCode = "404", description = "Artifact was not found - SVC4505")})
-    @PermissionAllowed(AafPermission.PermNames.READ_VALUE)
     public Response downloadResourceInstanceArtifact(
         @Parameter(description = "The user ID of the DCAE Designer. This user must also have Designer role in SDC", required = true) @HeaderParam(value = Constants.USER_ID_HEADER) final String userId,
         @Parameter(description = "X-ECOMP-RequestID header", required = false) @HeaderParam(value = Constants.X_ECOMP_REQUEST_ID_HEADER) String requestId,
@@ -805,19 +799,23 @@ public class ArtifactExternalServlet extends AbstractValidationsServlet {
             responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.MISSING_X_ECOMP_INSTANCE_ID);
             responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
         }
-        try {
-            if (responseWrapper.isEmpty()) {
-                byte[] value = artifactsBusinessLogic
-                    .downloadResourceInstanceArtifactByUUIDs(componentType, uuid, resourceInstanceName, artifactUUID);
-                InputStream is = new ByteArrayInputStream(value);
-                Map<String, String> headers = new HashMap<>();
-                headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
-                responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
-                responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
-            }
+        if (!responseWrapper.isEmpty()) {
+            getComponentsUtils().auditExternalDownloadArtifact(responseFormat, new ResourceCommonInfo(resourceInstanceName, componentTypeValue),
+                new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);
+            return responseWrapper.getInnerElement();
+        }
+        byte[] value = artifactsBusinessLogic
+            .downloadResourceInstanceArtifactByUUIDs(componentType, uuid, resourceInstanceName, artifactUUID);
+        try (InputStream is = new ByteArrayInputStream(value)) {
+            Map<String, String> headers = new HashMap<>();
+            headers.put(Constants.MD5_HEADER, GeneralUtility.calculateMD5Base64EncodedByByteArray(value));
+            responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.OK);
+            responseWrapper.setInnerElement(buildOkResponse(responseFormat, is, headers));
         } catch (ComponentException e) {
             responseFormat = getComponentsUtils().getResponseFormat(e);
             throw e;
+        } catch (IOException e) {
+            log.debug("close ByteArrayInputStream error");
         } finally {
             getComponentsUtils().auditExternalDownloadArtifact(responseFormat, new ResourceCommonInfo(resourceInstanceName, componentTypeValue),
                 new DistributionData(instanceIdHeader, requestURI), requestId, artifactUUID, userId);