Search in sources :

Example 1 with WebConfigBuilderStrategy

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

the class NetsparkerProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    URI targetURI = info.getURI();
    if (targetURI == null) {
        /* no targets defined */
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    LOG.debug("Trigger netsparker adapter execution for target {}", targetType);
    List<ProductResult> results = new ArrayList<>();
    /* NETSPARKER is not able to scan multiple targets */
    /*
         * special behavior, because having multiple results here, we must find former
         * result corresponding to target URI.
         */
    /* @formatter:off */
    ProductExecutorContext productExecutorContext = data.getProductExecutorContext();
    productExecutorContext.useFirstFormerResultHavingMetaData(NetsparkerMetaDataID.KEY_TARGET_URI, targetURI);
    NetsparkerAdapterConfig netsparkerConfig = NetsparkerConfig.builder().configure(new SecHubAdapterOptionsBuilderStrategy(data, getScanType())).configure(new WebConfigBuilderStrategy(data.getSechubExecutionContext())).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(installSetup, targetType)).setTimeToWaitForNextCheckOperationInMinutes(installSetup.getScanResultCheckPeriodInMinutes()).setTimeOutInMinutes(installSetup.getScanResultCheckTimeOutInMinutes()).setTraceID(data.getTraceLogIdAsString()).setAgentName(installSetup.getAgentName()).setAgentGroupName(data.getNetworkTargetProductServerDataSupport().getIdentifier(targetType)).setPolicyID(installSetup.getDefaultPolicyId()).setLicenseID(installSetup.getNetsparkerLicenseId()).setTargetType(info.getTargetType().name()).setTargetURI(targetURI).build();
    /* @formatter:on */
    /* execute NETSPARKER by adapter and return product result */
    String xml = netsparkerAdapter.start(netsparkerConfig, productExecutorContext.getCallback());
    ProductResult currentProductResult = productExecutorContext.getCurrentProductResult();
    currentProductResult.setResult(xml);
    results.add(currentProductResult);
    return results;
}
Also used : NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubAdapterOptionsBuilderStrategy(com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) ArrayList(java.util.ArrayList) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) NetsparkerAdapterConfig(com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapterConfig)

Example 2 with WebConfigBuilderStrategy

use of com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy 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)

Example 3 with WebConfigBuilderStrategy

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

the class PDSWebScanProductExecutor method executeWithAdapter.

@Override
protected List<ProductResult> executeWithAdapter(SecHubExecutionContext context, ProductExecutorContext executorContext, PDSInstallSetup setup, TargetRegistryInfo info) throws Exception {
    PDSExecutorConfigSuppport configSupport = PDSExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    URI targetURI = info.getURI();
    if (targetURI == null) {
        /* no targets defined */
        return Collections.emptyList();
    }
    TargetType 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<>();
    String projectId = context.getConfiguration().getProjectId();
    Map<String, String> jobParameters = configSupport.createJobParametersToSendToPDS(context.getConfiguration());
    /* @formatter:off */
    executorContext.useFirstFormerResultHavingMetaData(PDSMetaDataID.KEY_TARGET_URI, targetURI);
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        PDSWebScanConfig pdsWebScanConfig = PDSWebScanConfigImpl.builder().setPDSProductIdentifier(configSupport.getPDSProductIdentifier()).setTrustAllCertificates(configSupport.isTrustAllCertificatesEnabled()).setProductBaseUrl(configSupport.getProductBaseURL()).setSecHubJobUUID(context.getSechubJobUUID()).setSecHubConfigModel(context.getConfiguration()).configure(createAdapterOptionsStrategy(context)).configure(new WebConfigBuilderStrategy(context)).setTimeToWaitForNextCheckOperationInMilliseconds(configSupport.getTimeToWaitForNextCheckOperationInMilliseconds(setup)).setTimeOutInMinutes(configSupport.getTimeoutInMinutes(setup)).setUser(configSupport.getUser()).setPasswordOrAPIToken(configSupport.getPasswordOrAPIToken()).setProjectId(projectId).setTraceID(context.getTraceLogIdAsString()).setJobParameters(jobParameters).setTargetURI(targetURI).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) TargetType(com.mercedesbenz.sechub.domain.scan.TargetType) ArrayList(java.util.ArrayList) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy) URI(java.net.URI) PDSWebScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSWebScanConfig)

Example 4 with WebConfigBuilderStrategy

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

the class NetsparkerProductExecutor method executeWithAdapter.

@Override
protected List<ProductResult> executeWithAdapter(SecHubExecutionContext context, ProductExecutorContext executorContext, NetsparkerInstallSetup setup, TargetRegistryInfo info) throws Exception {
    URI targetURI = info.getURI();
    if (targetURI == null) {
        /* no targets defined */
        return Collections.emptyList();
    }
    TargetType targetType = info.getTargetType();
    LOG.debug("Trigger netsparker adapter execution for target {} and setup {} ", targetType, setup);
    List<ProductResult> results = new ArrayList<>();
    /* NETSPARKER is not able to scan multiple targets */
    /*
         * special behavior, because having multiple results here, we must find former
         * result corresponding to target URI.
         */
    /* @formatter:off */
    executorContext.useFirstFormerResultHavingMetaData(NetsparkerMetaDataID.KEY_TARGET_URI, targetURI);
    NetsparkerAdapterConfig netsparkerConfig = NetsparkerConfig.builder().configure(createAdapterOptionsStrategy(context)).configure(new WebConfigBuilderStrategy(context)).configure(new OneInstallSetupConfigBuilderStrategy(setup)).setTimeToWaitForNextCheckOperationInMinutes(setup.getScanResultCheckPeriodInMinutes()).setTimeOutInMinutes(setup.getScanResultCheckTimeOutInMinutes()).setTraceID(context.getTraceLogIdAsString()).setAgentName(setup.getAgentName()).setAgentGroupName(setup.getIdentifier(targetType)).setPolicyID(setup.getDefaultPolicyId()).setLicenseID(setup.getNetsparkerLicenseId()).setTargetURI(targetURI).build();
    /* @formatter:on */
    /* execute NETSPARKER by adapter and return product result */
    String xml = netsparkerAdapter.start(netsparkerConfig, executorContext.getCallback());
    ProductResult currentProductResult = executorContext.getCurrentProductResult();
    currentProductResult.setResult(xml);
    results.add(currentProductResult);
    return results;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) OneInstallSetupConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.OneInstallSetupConfigBuilderStrategy) TargetType(com.mercedesbenz.sechub.domain.scan.TargetType) ArrayList(java.util.ArrayList) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy) URI(java.net.URI) NetsparkerAdapterConfig(com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapterConfig)

Aggregations

WebConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)4 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 NetsparkerAdapterConfig (com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapterConfig)2 PDSWebScanConfig (com.mercedesbenz.sechub.adapter.pds.PDSWebScanConfig)2 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)2 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)2 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)2 TargetType (com.mercedesbenz.sechub.domain.scan.TargetType)2 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)2 OneInstallSetupConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.OneInstallSetupConfigBuilderStrategy)1 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)1 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 InputStream (java.io.InputStream)1