Search in sources :

Example 6 with NetworkTargetInfo

use of com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo 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 7 with NetworkTargetInfo

use of com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo in project sechub by mercedes-benz.

the class PDSWebScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    SecHubExecutionContext context = data.getSechubExecutionContext();
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    /* we reuse config support created inside customize method */
    PDSExecutorConfigSuppport configSupport = (PDSExecutorConfigSuppport) data.getNetworkTargetDataProvider();
    URI targetURI = info.getURI();
    if (targetURI == null) {
        LOG.warn("NO target URI defined for PDS web scan execution");
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    if (configSupport.isTargetTypeForbidden(targetType)) {
        LOG.info("PDS adapter does not accept target type:{} so cancel execution");
        return Collections.emptyList();
    }
    LOG.debug("Trigger PDS adapter execution for target {} ", targetType);
    List<ProductResult> results = new ArrayList<>();
    /* @formatter:off */
    executorContext.useFirstFormerResultHavingMetaData(PDSMetaDataID.KEY_TARGET_URI, targetURI);
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        try (InputStream sourceCodeZipFileInputStreamOrNull = contentProvider.getSourceZipFileInputStreamOrNull()) {
            PDSWebScanConfig pdsWebScanConfig = PDSWebScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setSourceCodeZipFileInputStreamOrNull(sourceCodeZipFileInputStreamOrNull).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).configure(new WebConfigBuilderStrategy(context)).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(configSupport, data.getCurrentNetworkTargetInfo().getTargetType())).setTargetURI(targetURI).setTargetType(info.getTargetType().name()).build();
            /* @formatter:on */
            /* execute PDS by adapter and return product result */
            String pdsResult = pdsAdapter.start(pdsWebScanConfig, executorContext.getCallback());
            ProductResult currentProductResult = executorContext.getCurrentProductResult();
            currentProductResult.setResult(pdsResult);
            return currentProductResult;
        }
    });
    results.add(result);
    return results;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) InputStream(java.io.InputStream) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) ArrayList(java.util.ArrayList) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) PDSWebScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSWebScanConfig) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)

Aggregations

NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)7 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)6 ArrayList (java.util.ArrayList)5 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)4 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)4 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)4 URI (java.net.URI)3 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)2 WebConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)2 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)2 NessusAdapterConfig (com.mercedesbenz.sechub.adapter.nessus.NessusAdapterConfig)1 NetsparkerAdapterConfig (com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapterConfig)1 PDSInfraScanConfig (com.mercedesbenz.sechub.adapter.pds.PDSInfraScanConfig)1 PDSWebScanConfig (com.mercedesbenz.sechub.adapter.pds.PDSWebScanConfig)1 NetworkLocationProvider (com.mercedesbenz.sechub.domain.scan.NetworkLocationProvider)1 NetworkTargetInfoFactory (com.mercedesbenz.sechub.domain.scan.NetworkTargetInfoFactory)1 NetworkTargetProductServerDataProvider (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataProvider)1 NetworkTargetProductServerDataSuppport (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataSuppport)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 InputStream (java.io.InputStream)1