Search in sources :

Example 1 with NamePatternIdProvider

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

the class DefaultExecutorConfigSupport method getNamePatternIdProvider.

/**
 * Resolves a name pattern provider for given id
 *
 * @param id
 * @param failWhenNotConfigured when <code>false</code> missing name provider
 *                              will be replaced by fallback implementation
 *                              returning always null (nothing configured)
 * @return provider never <code>null</code>
 * @throws SecHubRuntimeException when name pattern provider cannot be resolved
 */
public NamePatternIdProvider getNamePatternIdProvider(String id, boolean failWhenNotConfigured) {
    NamePatternIdProvider provider = namePatternIdProviders.get(id);
    if (provider != null) {
        return provider;
    }
    String parameterValue = getParameter(id);
    if (parameterValue == null) {
        if (failWhenNotConfigured) {
            throw new SecHubRuntimeException("No parameter found for necessary mapping key:" + id);
        } else {
            return FALLBACK_NOT_FOUND_PROVIDER;
        }
    }
    NamePatternIdProvider newProvider = providerFactory.createProvider(id, parameterValue);
    namePatternIdProviders.put(id, newProvider);
    LOG.debug("Created NamePatternIdProvider:{}", newProvider.getProviderId());
    return newProvider;
}
Also used : SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) NamePatternIdProvider(com.mercedesbenz.sechub.domain.scan.config.NamePatternIdProvider)

Example 2 with NamePatternIdProvider

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

the class NamePatternIdProviderFactory method createProvider.

public NamePatternIdProvider createProvider(String id, String parameterValue) {
    NamePatternIdProvider provider;
    MappingData mappingData = MappingData.fromString(parameterValue);
    List<NamePatternToIdEntry> entries = converter.convert(mappingData);
    provider = new NamePatternIdProvider(id);
    for (NamePatternToIdEntry entry : entries) {
        provider.add(entry);
    }
    return provider;
}
Also used : NamePatternToIdEntry(com.mercedesbenz.sechub.domain.scan.config.NamePatternToIdEntry) NamePatternIdProvider(com.mercedesbenz.sechub.domain.scan.config.NamePatternIdProvider) MappingData(com.mercedesbenz.sechub.sharedkernel.mapping.MappingData)

Example 3 with NamePatternIdProvider

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

the class ScanMappingConfigurationTestJSONasNamePatternDialogAction method execute.

@Override
protected void execute(ActionEvent e) throws Exception {
    /* convert to rows */
    String json = getMappingUI().getJSON();
    MappingIdentifier identifier = resolveMappingIdentifier();
    ScanMappingConfiguration config = createScanConfig(json, identifier);
    DeveloperToolsScanMappingConfigurationService scanMappingConfigurationService = new DeveloperToolsScanMappingConfigurationService();
    scanMappingConfigurationService.switchConfigurationIfChanged(config);
    NamePatternIdProvider provider = scanMappingConfigurationService.getNamePatternIdProvider(identifier);
    boolean ongoing = true;
    while (ongoing) {
        /* ui */
        Optional<String> value = getDialogUI().getContext().getDialogUI().getUserInput("Enter a name to check", "pattern");
        if (!value.isPresent()) {
            return;
        }
        String pattern = value.get();
        String id = provider.getIdForName(pattern);
        ongoing = getDialogUI().getContext().getDialogUI().confirm("Pattern '" + pattern + "' results in '" + id + "'\n\nDo you want to test another value?");
    }
}
Also used : MappingIdentifier(com.mercedesbenz.sechub.sharedkernel.mapping.MappingIdentifier) DeveloperToolsScanMappingConfigurationService(com.mercedesbenz.sechub.domain.scan.config.DeveloperToolsScanMappingConfigurationService) NamePatternIdProvider(com.mercedesbenz.sechub.domain.scan.config.NamePatternIdProvider) ScanMappingConfiguration(com.mercedesbenz.sechub.domain.scan.config.ScanMappingConfiguration)

Example 4 with NamePatternIdProvider

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

the class IntegrationTestScanRestController method getIdForNameByProvider.

@SuppressWarnings("deprecation")
@RequestMapping(path = APIConstants.API_ANONYMOUS + "integrationtest/config/namepattern/{namePatternProviderId}/{name}", method = RequestMethod.GET)
public String getIdForNameByProvider(@PathVariable("namePatternProviderId") String namePatternProviderId, @PathVariable("name") String name) {
    NamePatternIdProvider provider = scanMappingConfigurationService.getNamePatternIdProvider(namePatternProviderId);
    if (provider == null) {
        return null;
    }
    String id = provider.getIdForName(name);
    return id;
}
Also used : NamePatternIdProvider(com.mercedesbenz.sechub.domain.scan.config.NamePatternIdProvider) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with NamePatternIdProvider

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

the class ScanConfigTestJSONasNamePatternDialogAction method execute.

@Override
protected void execute(ActionEvent e) throws Exception {
    /* convert to rows */
    String json = getMappingUI().getJSON();
    MappingIdentifier identifier = resolveMappingIdentifier();
    ScanConfig config = createScanConfig(json, identifier);
    DeveloperToolsScanConfigService scanConfigService = new DeveloperToolsScanConfigService();
    scanConfigService.switchConfigurationIfChanged(config);
    NamePatternIdprovider provider = scanConfigService.getNamePatternIdProvider(identifier);
    boolean ongoing = true;
    while (ongoing) {
        /* ui */
        Optional<String> value = getDialogUI().getContext().getDialogUI().getUserInput("Enter a name to check", "pattern");
        if (!value.isPresent()) {
            return;
        }
        String pattern = value.get();
        String id = provider.getIdForName(pattern);
        ongoing = getDialogUI().getContext().getDialogUI().confirm("Pattern '" + pattern + "' results in '" + id + "'\n\nDo you want to test another value?");
    }
}
Also used : MappingIdentifier(com.mercedesbenz.sechub.sharedkernel.mapping.MappingIdentifier) ScanConfig(com.mercedesbenz.sechub.domain.scan.config.ScanConfig) DeveloperToolsScanConfigService(com.mercedesbenz.sechub.domain.scan.config.DeveloperToolsScanConfigService) NamePatternIdprovider(com.mercedesbenz.sechub.domain.scan.config.NamePatternIdprovider)

Aggregations

NamePatternIdProvider (com.mercedesbenz.sechub.domain.scan.config.NamePatternIdProvider)4 MappingIdentifier (com.mercedesbenz.sechub.sharedkernel.mapping.MappingIdentifier)2 SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)1 DeveloperToolsScanConfigService (com.mercedesbenz.sechub.domain.scan.config.DeveloperToolsScanConfigService)1 DeveloperToolsScanMappingConfigurationService (com.mercedesbenz.sechub.domain.scan.config.DeveloperToolsScanMappingConfigurationService)1 NamePatternIdprovider (com.mercedesbenz.sechub.domain.scan.config.NamePatternIdprovider)1 NamePatternToIdEntry (com.mercedesbenz.sechub.domain.scan.config.NamePatternToIdEntry)1 ScanConfig (com.mercedesbenz.sechub.domain.scan.config.ScanConfig)1 ScanMappingConfiguration (com.mercedesbenz.sechub.domain.scan.config.ScanMappingConfiguration)1 MappingData (com.mercedesbenz.sechub.sharedkernel.mapping.MappingData)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1