Search in sources :

Example 6 with ScanReport

use of com.mercedesbenz.sechub.domain.scan.report.ScanReport in project sechub by mercedes-benz.

the class FalsePositiveJobDataService method addJobDataListToConfiguration.

private void addJobDataListToConfiguration(FalsePositiveProjectConfiguration config, FalsePositiveJobDataList jobDataList) {
    List<FalsePositiveJobData> list = jobDataList.getJobData();
    /* we want to load reports only one time, so sort by report job UUID... */
    list.sort(Comparator.comparing(FalsePositiveJobData::getJobUUID));
    ScanSecHubReport report = null;
    for (FalsePositiveJobData data : list) {
        UUID jobUUID = data.getJobUUID();
        if (report == null || !jobUUID.equals(report.getJobUUID())) {
            ScanReport scanReport = scanReportRepository.findBySecHubJobUUID(jobUUID);
            if (scanReport == null) {
                throw new NotFoundException("No report found for job " + jobUUID);
            }
            report = new ScanSecHubReport(scanReport);
        }
        merger.addJobDataWithMetaDataToConfig(report, config, data, userContextService.getUserId());
    }
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException) UUID(java.util.UUID)

Example 7 with ScanReport

use of com.mercedesbenz.sechub.domain.scan.report.ScanReport in project sechub by mercedes-benz.

the class ScanService method startScan.

@IsSendingSyncMessageAnswer(value = MessageID.SCAN_DONE, answeringTo = MessageID.START_SCAN, branchName = "success")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_FAILED, answeringTo = MessageID.START_SCAN, branchName = "failure")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_ABANDONDED, answeringTo = MessageID.START_SCAN, branchName = "failure")
DomainMessageSynchronousResult startScan(DomainMessage request) {
    SecHubExecutionContext context = null;
    try {
        context = createExecutionContext(request);
        executeScan(context, request);
        ScanReport report = reportService.createReport(context);
        DomainMessageSynchronousResult response = new DomainMessageSynchronousResult(MessageID.SCAN_DONE);
        response.set(REPORT_TRAFFIC_LIGHT, report.getTrafficLightAsString());
        return response;
    } catch (ScanReportException e) {
        LOG.error("Execution was possible, but report failed." + traceLogID(request), e);
        return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
    } catch (SecHubExecutionAbandonedException e) {
        LOG.info("Execution abandoned on scan {} - message: {}", traceLogID(request), e.getMessage());
        return new DomainMessageSynchronousResult(MessageID.SCAN_ABANDONDED, e);
    } catch (SecHubExecutionException e) {
        LOG.error("Execution problems on scan." + traceLogID(request), e);
        return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
    } catch (Exception e) {
        LOG.error("Was not able to start scan." + traceLogID(request), e);
        return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
    } finally {
        if (context == null) {
            LOG.warn("No sechub execution context available, so cannot check state or cleanup storage");
        } else {
            if (!context.isAbandonded()) {
                cleanupStorage(context);
            }
        }
    }
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) ScanReportException(com.mercedesbenz.sechub.domain.scan.report.ScanReportException) JSONConverterException(com.mercedesbenz.sechub.commons.model.JSONConverterException) ScanReportException(com.mercedesbenz.sechub.domain.scan.report.ScanReportException) SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) IOException(java.io.IOException) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) IsSendingSyncMessageAnswer(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)

Aggregations

ScanReport (com.mercedesbenz.sechub.domain.scan.report.ScanReport)7 ScanSecHubReport (com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport)6 Test (org.junit.Test)3 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)2 UseCaseUserDownloadsJobReport (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserDownloadsJobReport)2 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)1 ScanReportException (com.mercedesbenz.sechub.domain.scan.report.ScanReportException)1 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)1 SecHubExecutionAbandonedException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException)1 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)1 IsSendingSyncMessageAnswer (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)1 IOException (java.io.IOException)1 UUID (java.util.UUID)1