use of com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration in project sechub by mercedes-benz.
the class SecHubWebScanConfigurationHelperTest method determines_AuthenticationType_sechub_config_has_basic_auth.
@Test
void determines_AuthenticationType_sechub_config_has_basic_auth() {
/* prepare */
File file = new File("src/test/resources/sechub-config-examples/basic-auth.json");
String sechubConfigJSON = TestFileReader.loadTextFile(file);
SecHubScanConfiguration sechubConfig = SecHubScanConfiguration.createFromJSON(sechubConfigJSON);
SecHubWebScanConfiguration secHubWebScanConfiguration = sechubConfig.getWebScan().get();
/* execute */
AuthenticationType authenticationType = helperToTest.determineAuthenticationType(secHubWebScanConfiguration);
/* test */
assertEquals(authenticationType, AuthenticationType.HTTP_BASIC_AUTHENTICATION);
}
use of com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration in project sechub by mercedes-benz.
the class SecHubWebScanConfigurationHelperTest method determines_AuthenticationType_from_empty_sechub_config_correctly.
@Test
void determines_AuthenticationType_from_empty_sechub_config_correctly() {
/* execute */
AuthenticationType authTypeNewConfig = helperToTest.determineAuthenticationType(new SecHubWebScanConfiguration());
/* test */
assertEquals(authTypeNewConfig, AuthenticationType.UNAUTHENTICATED);
}
use of com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration in project sechub by mercedes-benz.
the class SechubWebConfigProvider method getSecHubWebConfiguration.
public SecHubWebScanConfiguration getSecHubWebConfiguration(File secHubConfigFile) {
TextFileReader fileReader = new TextFileReader();
if (secHubConfigFile == null) {
// can happen when an unauthenticated scan is started with only the target URL
return new SecHubWebScanConfiguration();
}
String sechubConfigJson;
SecHubScanConfiguration sechubConfig;
try {
sechubConfigJson = fileReader.loadTextFile(secHubConfigFile);
sechubConfig = SecHubScanConfiguration.createFromJSON(sechubConfigJson);
} catch (IOException e) {
throw new MustExitRuntimeException("Was not able to read sechub config file: " + secHubConfigFile, e, MustExitCode.SECHUB_CONFIGURATION_INVALID);
}
return getSecHubWebConfiguration(sechubConfig);
}
use of com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration in project sechub by mercedes-benz.
the class WebConfigBuilderStrategy method configureImpl.
private <B extends AbstractWebScanAdapterConfigBuilder<B, C>, C extends AbstractWebScanAdapterConfig> void configureImpl(B configBuilder) {
/* check precondition : login configured */
SecHubConfiguration configuration = context.getConfiguration();
if (configuration == null) {
return;
}
Optional<SecHubWebScanConfiguration> webScan = configuration.getWebScan();
if (!webScan.isPresent()) {
return;
}
SecHubWebScanConfiguration webscanConfig = webScan.get();
configBuilder.setTargetURI(webscanConfig.getUri());
handleMaxScanDuration(configBuilder, webscanConfig);
handleIncludes(configBuilder, webscanConfig);
handleExcludes(configBuilder, webscanConfig);
/* ----------------------- LOGIN ----------------------- */
Optional<WebLoginConfiguration> loginOpt = webscanConfig.getLogin();
if (!loginOpt.isPresent()) {
return;
}
/* handle different web login configurations: */
WebLoginConfiguration loginConfiguration = loginOpt.get();
URL loginUrl = loginConfiguration.getUrl();
/* ------ BASIC --------- */
Optional<BasicLoginConfiguration> basic = loginConfiguration.getBasic();
if (basic.isPresent()) {
configureBasicAuth(configBuilder, loginUrl, basic.get());
return;
}
/* ------ FORM --------- */
Optional<FormLoginConfiguration> formLogin = loginConfiguration.getForm();
if (!formLogin.isPresent()) {
return;
}
FormLoginConfiguration formLoginConfig = formLogin.get();
/* ------ FORM:SCRIPT--------- */
if (formLoginConfig.getScript().isPresent()) {
configureScriptAuth(configBuilder, loginUrl, formLoginConfig.getScript().get());
}
}
use of com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration in project sechub by mercedes-benz.
the class WebScanNetworkLocationProvider method getURIs.
@Override
public List<URI> getURIs() {
/* assert WEBSCAN configuration available */
Optional<SecHubWebScanConfiguration> webscan = config.getWebScan();
if (!webscan.isPresent()) {
throw new IllegalStateException("At this state there must be a webscan setup!");
}
/* Fetch URL */
SecHubWebScanConfiguration secHubWebScanConfiguration = webscan.get();
URI uri = secHubWebScanConfiguration.getUri();
if (uri == null) {
throw new IllegalStateException("At this state the URI must be set - validation failed!");
}
return Arrays.asList(uri);
}
Aggregations