Search in sources :

Example 6 with WebLoginConfiguration

use of com.mercedesbenz.sechub.commons.model.login.WebLoginConfiguration in project sechub by mercedes-benz.

the class SecHubConfigurationTest method webscan_login_basic_json_has_webconfig_as_expected.

@Test
public void webscan_login_basic_json_has_webconfig_as_expected() throws Exception {
    /* prepare */
    String json = SharedKernelTestFileSupport.getTestfileSupport().loadTestFile("webscan/webscan_login_basic.json");
    /* execute */
    SecHubConfiguration result = SECHUB_CONFIG.fromJSON(json);
    /* test */
    Optional<SecHubWebScanConfiguration> webScanOption = result.getWebScan();
    assertTrue("webscan config must be present", webScanOption.isPresent());
    SecHubWebScanConfiguration secHubWebScanConfiguration = webScanOption.get();
    Optional<WebLoginConfiguration> loginOption = secHubWebScanConfiguration.getLogin();
    assertTrue("login config must be present", loginOption.isPresent());
    WebLoginConfiguration loginConfiguration = loginOption.get();
    assertEquals(new URL("https://productfailure.demo.example.org/login"), loginConfiguration.getUrl());
    /*-- basic --*/
    Optional<BasicLoginConfiguration> basic = loginConfiguration.getBasic();
    assertTrue("basic login config must be present", basic.isPresent());
    assertEquals("realm0", basic.get().getRealm().get());
    assertEquals("user0", new String(basic.get().getUser()));
    assertEquals("pwd0", new String(basic.get().getPassword()));
    /*-- form --*/
    Optional<FormLoginConfiguration> form = loginConfiguration.getForm();
    assertFalse("form login config must NOT be present", form.isPresent());
}
Also used : WebLoginConfiguration(com.mercedesbenz.sechub.commons.model.login.WebLoginConfiguration) SecHubWebScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration) FormLoginConfiguration(com.mercedesbenz.sechub.commons.model.login.FormLoginConfiguration) URL(java.net.URL) BasicLoginConfiguration(com.mercedesbenz.sechub.commons.model.login.BasicLoginConfiguration) Test(org.junit.Test)

Example 7 with WebLoginConfiguration

use of com.mercedesbenz.sechub.commons.model.login.WebLoginConfiguration 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());
    }
}
Also used : WebLoginConfiguration(com.mercedesbenz.sechub.commons.model.login.WebLoginConfiguration) SecHubWebScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration) FormLoginConfiguration(com.mercedesbenz.sechub.commons.model.login.FormLoginConfiguration) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) URL(java.net.URL) BasicLoginConfiguration(com.mercedesbenz.sechub.commons.model.login.BasicLoginConfiguration)

Aggregations

SecHubWebScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration)7 BasicLoginConfiguration (com.mercedesbenz.sechub.commons.model.login.BasicLoginConfiguration)7 WebLoginConfiguration (com.mercedesbenz.sechub.commons.model.login.WebLoginConfiguration)7 FormLoginConfiguration (com.mercedesbenz.sechub.commons.model.login.FormLoginConfiguration)6 URL (java.net.URL)6 Test (org.junit.Test)5 Action (com.mercedesbenz.sechub.commons.model.login.Action)4 Script (com.mercedesbenz.sechub.commons.model.login.Script)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 WebScanDurationConfiguration (com.mercedesbenz.sechub.commons.model.WebScanDurationConfiguration)1 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)1 File (java.io.File)1 Test (org.junit.jupiter.api.Test)1