From 7687e9920ba9b02ec339d51e5433c01334c7de9e Mon Sep 17 00:00:00 2001 From: Grzegorz Siewruk Date: Sun, 28 Jul 2024 23:53:14 +0200 Subject: [PATCH] auto discovery on SCA after adding repository --- .../api/project/controller/OperateOnAssets.java | 5 +++-- .../api/project/service/OperateOnAssetsService.java | 13 ++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/mixeway/api/project/controller/OperateOnAssets.java b/src/main/java/io/mixeway/api/project/controller/OperateOnAssets.java index 02447a81..4e482f3a 100644 --- a/src/main/java/io/mixeway/api/project/controller/OperateOnAssets.java +++ b/src/main/java/io/mixeway/api/project/controller/OperateOnAssets.java @@ -20,7 +20,8 @@ import org.springframework.web.bind.annotation.*; import java.io.IOException; -import java.security.Principal; +import java.security.*; +import java.security.cert.CertificateException; import java.util.List; import java.util.Optional; @@ -38,7 +39,7 @@ public class OperateOnAssets { @PreAuthorize("hasAuthority('ROLE_PROJECT_OWNER')") @PostMapping("/create/project/{id}") - public ResponseEntity processAsset(@RequestBody String json, @PathVariable("id") Long id, Principal principal) throws IOException { + public ResponseEntity processAsset(@RequestBody String json, @PathVariable("id") Long id, Principal principal) throws IOException, UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { Optional project = findProjectService.findProjectById(id); if(project.isPresent() && permissionFactory.canUserAccessProject(principal, project.get())) { JsonNode rootNode = objectMapper.readTree(json); diff --git a/src/main/java/io/mixeway/api/project/service/OperateOnAssetsService.java b/src/main/java/io/mixeway/api/project/service/OperateOnAssetsService.java index 5987a037..7618a991 100644 --- a/src/main/java/io/mixeway/api/project/service/OperateOnAssetsService.java +++ b/src/main/java/io/mixeway/api/project/service/OperateOnAssetsService.java @@ -21,6 +21,7 @@ import io.mixeway.domain.service.scanmanager.webapp.UpdateWebAppService; import io.mixeway.domain.service.vulnhistory.OperateOnVulnHistoryService; import io.mixeway.domain.service.vulnmanager.VulnTemplate; +import io.mixeway.scanmanager.service.opensource.OpenSourceScanService; import io.mixeway.utils.PermissionFactory; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; @@ -28,7 +29,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import java.security.Principal; +import java.io.IOException; +import java.security.*; +import java.security.cert.CertificateException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -58,11 +61,15 @@ public class OperateOnAssetsService { private final FindCiOperationsService findCiOperationsService; private final GetAssetDashboardService getAssetDashboardService; private final FindAssetHistoryService findAssetHistoryService; + private final OpenSourceScanService openSourceScanService; - public CodeProject createCodeProject(JsonNode rootNode, Project project, Principal principal) { + public CodeProject createCodeProject(JsonNode rootNode, Project project, Principal principal) throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException { String repositoryType = rootNode.path("repositoryType").asText(); if (repositoryType.equals("single")) { - return createSingleCodeProject(rootNode, project, principal); + CodeProject codeProject = createSingleCodeProject(rootNode, project, principal); + openSourceScanService.createProjectOnOpenSourceScanner(codeProject); + + return codeProject; } else if (repositoryType.equals("multiple")) { return createMultipleCodeProject(rootNode, project, principal); }