Search in sources :

Example 16 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class PDSInfraScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    Set<URI> targetURIs = info.getURIs();
    if (targetURIs.isEmpty()) {
        /* no targets defined */
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    /* we reuse config support created inside customize method */
    PDSExecutorConfigSuppport configSupport = (PDSExecutorConfigSuppport) data.getNetworkTargetDataProvider();
    if (configSupport.isTargetTypeForbidden(targetType)) {
        LOG.info("pds adapter does not accept target type:{} so cancel execution");
        return Collections.emptyList();
    }
    LOG.debug("Trigger pds infra scan adapter execution for target {}", targetType);
    List<ProductResult> results = new ArrayList<>();
    SecHubExecutionContext context = data.getSechubExecutionContext();
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    for (URI targetURI : targetURIs) {
        /* @formatter:off */
        /* special behavior, because having multiple results here, we must find former result corresponding to
             * target URI.
             */
        executorContext.useFirstFormerResultHavingMetaData(PDSMetaDataID.KEY_TARGET_URI, targetURI);
        PDSInfraScanConfig pdsInfraScanConfig = PDSInfraScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(configSupport, data.getCurrentNetworkTargetInfo().getTargetType())).setTargetIPs(info.getIPs()).setTargetURIs(info.getURIs()).build();
        /* @formatter:on */
        /* execute PDS by adapter and return product result */
        String xml = pdsAdapter.start(pdsInfraScanConfig, executorContext.getCallback());
        ProductResult currentProductResult = executorContext.getCurrentProductResult();
        currentProductResult.setResult(xml);
        results.add(currentProductResult);
    }
    return results;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) ArrayList(java.util.ArrayList) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) PDSInfraScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSInfraScanConfig) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)

Example 17 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class DownloadSpdxScanReportService method getScanSpdxJsonReport.

public String getScanSpdxJsonReport(String projectId, UUID jobUUID) {
    /* validate */
    assertion.assertIsValidProjectId(projectId);
    assertion.assertIsValidJobUUID(jobUUID);
    scanAssertService.assertUserHasAccessToProject(projectId);
    scanAssertService.assertProjectAllowsReadAccess(projectId);
    /* audit */
    auditLogService.log("starts download of SPDX Json report for job: {}", jobUUID);
    List<ProductResult> productResults = productResultRepository.findAllProductResults(jobUUID, ProductIdentifier.SERECO);
    if (productResults.size() != 1) {
        throw new SecHubRuntimeException("Did not found exactly one SERECO product result. Instead, " + productResults.size() + " product results were found.");
    }
    ProductResult productResult = productResults.iterator().next();
    String spdxJson = spdxJsonResolver.resolveSpdxJson(productResult);
    if (spdxJson == null) {
        throw new NotFoundException("There was no JSON SPDX report available for job: " + jobUUID);
    }
    return spdxJson;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)

Example 18 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class ReportTestHelper method transform.

private static ReportTransformationResult transform(String xml, ProductIdentifier productIdentifier, String sechubJobUUID, ProductResultImporter importer) throws IOException, SecHubExecutionException {
    ProductExecutorConfigInfo info = mock(ProductExecutorConfigInfo.class);
    when(info.getProductIdentifier()).thenReturn(productIdentifier);
    // import from SARIF to SERECO format
    SerecoMetaData serecoMetaData = importer.importResult(xml);
    String serecoJSon = JSONConverter.get().toJSON(serecoMetaData);
    // transform SERECO JSON to SecHub report transformation result
    ProductResult productResult = new ProductResult(UUID.fromString(sechubJobUUID), "project-1", info, serecoJSon);
    ReportTransformationResult result = transfomer.transform(productResult);
    return result;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) ProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigInfo) ReportTransformationResult(com.mercedesbenz.sechub.domain.scan.ReportTransformationResult) SerecoMetaData(com.mercedesbenz.sechub.sereco.metadata.SerecoMetaData)

Example 19 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class SerecoReportProductExecutor method createReport.

private ProductResult createReport(SecHubExecutionContext context, ProductExecutorContext executorContext) {
    if (context == null) {
        throw new IllegalArgumentException("context may not be null!");
    }
    String projectId = context.getConfiguration().getProjectId();
    UUID secHubJobUUID = context.getSechubJobUUID();
    UUIDTraceLogID traceLogId = UUIDTraceLogID.traceLogID(secHubJobUUID);
    LOG.debug("{} start sereco execution", traceLogId);
    /* load the results by job uuid */
    ProductIdentifier[] supportedProducts = getSupportedProducts();
    List<ProductResult> foundProductResults = productResultRepository.findAllProductResults(secHubJobUUID, supportedProducts);
    if (foundProductResults.isEmpty()) {
        LOG.warn("{} no product results for {} found, will return an empty sereco JSON as result! ", traceLogId, getSupportedProducts());
        return new ProductResult(secHubJobUUID, projectId, executorContext.getExecutorConfig(), "{}");
    }
    return createReport(projectId, secHubJobUUID, traceLogId, executorContext, foundProductResults);
}
Also used : UUIDTraceLogID(com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) ProductIdentifier(com.mercedesbenz.sechub.domain.scan.product.ProductIdentifier) UUID(java.util.UUID)

Example 20 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class SerecoReportProductExecutor method createReport.

private ProductResult createReport(String projectId, UUID secHubJobUUID, UUIDTraceLogID traceLogId, ProductExecutorContext executorContext, List<ProductResult> foundProductResults) {
    Workspace workspace = sechubReportCollector.createWorkspace(projectId);
    for (ProductResult productResult : foundProductResults) {
        importProductResult(traceLogId, workspace, productResult);
    }
    String json = workspace.createReport();
    /* fetch + return all vulnerabilities as JSON */
    return new ProductResult(secHubJobUUID, projectId, executorContext.getExecutorConfig(), json);
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) Workspace(com.mercedesbenz.sechub.sereco.Workspace)

Aggregations

ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)30 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)10 ArrayList (java.util.ArrayList)10 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)8 UUID (java.util.UUID)8 InputStream (java.io.InputStream)6 URI (java.net.URI)6 WithoutProductExecutorConfigInfo (com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo)5 MetaDataInspection (com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection)5 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)4 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)4 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)4 TargetType (com.mercedesbenz.sechub.domain.scan.TargetType)4 WebConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)4 Test (org.junit.Test)4 AdapterMetaData (com.mercedesbenz.sechub.adapter.AdapterMetaData)3 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)3 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)3 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)3 Test (org.junit.jupiter.api.Test)3