use of com.mercedesbenz.sechub.domain.scan.NetworkTargetType in project sechub by mercedes-benz.
the class AbstractProductExecutor method configureNetworkTargetHandlingIfNecessary.
private void configureNetworkTargetHandlingIfNecessary(ProductExecutorData data) {
if (!isUsingNetworkTargets()) {
return;
}
/* check preconditions */
NetworkTargetProductServerDataProvider networkTargetDataProvider = data.networkTargetDataProvider;
if (networkTargetDataProvider == null) {
throw new IllegalStateException("No network target data provider set, but necessary for scantype: " + scanType + "\nInject this at customize method inside " + getClass().getName());
}
NetworkLocationProvider networkLocationProvider = data.networkLocationProvider;
if (networkLocationProvider == null) {
throw new IllegalStateException("No network location provier set, but necessary for scantype: " + scanType + "\nInject this at customize method inside " + getClass().getName());
}
NetworkTargetProductServerDataSuppport networkTargetProductServerDataSupport = new NetworkTargetProductServerDataSuppport(networkTargetDataProvider);
data.networkTargetProductServerDataSupport = networkTargetProductServerDataSupport;
NetworkTargetInfoFactory targetInfoFactory = new NetworkTargetInfoFactory(targetResolver, getClass().getSimpleName());
List<NetworkTargetInfo> targetRegistryInfoList = new ArrayList<>();
for (NetworkTargetType networkTargetType : NetworkTargetType.values()) {
if (!networkTargetType.isValid()) {
continue;
}
NetworkTargetInfo infoForThisNetworkTargetType = targetInfoFactory.createInfo(networkTargetType, data.traceLogId, networkLocationProvider, networkTargetProductServerDataSupport);
if (infoForThisNetworkTargetType.containsAtLeastOneTarget()) {
targetRegistryInfoList.add(infoForThisNetworkTargetType);
}
}
data.networkTargetInfoList = targetRegistryInfoList;
}
use of com.mercedesbenz.sechub.domain.scan.NetworkTargetType in project sechub by mercedes-benz.
the class TargetRegistryTest method nothing_registered_each_registry_info_contains_no_target.
@Test
public void nothing_registered_each_registry_info_contains_no_target() {
for (NetworkTargetType type : NetworkTargetType.values()) {
NetworkTargetInfo info = registryToTest.createRegistryInfo(type);
assertFalse(info.containsAtLeastOneTarget());
}
}
use of com.mercedesbenz.sechub.domain.scan.NetworkTargetType in project sechub by mercedes-benz.
the class NessusProductExecutor method executeByAdapter.
@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
if (info.getURIs().isEmpty() && info.getIPs().isEmpty()) {
LOG.debug("{} Nessus scan not possible, because no uri or ip defined", data.getTraceLogId());
return Collections.emptyList();
}
NetworkTargetType targetType = info.getTargetType();
LOG.debug("Trigger Nessus adapter execution for target type {}", targetType);
/* @formatter:off */
NessusAdapterConfig nessusConfig = NessusConfig.builder().configure(new SecHubAdapterOptionsBuilderStrategy(data, getScanType())).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(installSetup, targetType)).setTimeToWaitForNextCheckOperationInMinutes(scanResultCheckPeriodInMinutes).setTimeOutInMinutes(scanResultCheckTimeOutInMinutes).setProxyHostname(proxyHostname).setProxyPort(proxyPort).setTraceID(data.getTraceLogIdAsString()).setPolicyID(installSetup.getDefaultPolicyId()).setTargetIPs(info.getIPs()).setTargetURIs(info.getURIs()).build();
/* @formatter:on */
/* execute NESSUS by adapter and return product result */
ProductExecutorContext productExecutorContext = data.getProductExecutorContext();
String xml = nessusAdapter.start(nessusConfig, productExecutorContext.getCallback());
// product result is set by callback
ProductResult productResult = productExecutorContext.getCurrentProductResult();
productResult.setResult(xml);
return Collections.singletonList(productResult);
}
use of com.mercedesbenz.sechub.domain.scan.NetworkTargetType 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;
}
use of com.mercedesbenz.sechub.domain.scan.NetworkTargetType 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;
}
Aggregations