Search in sources :

Example 6 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class PluginProfilesService method validatePluginProperties.

private void validatePluginProperties(PluginProfileCommand command, PluginProfile newPluginProfile) {
    try {
        ValidationResult result = command.validateUsingExtension(newPluginProfile.getPluginId(), newPluginProfile.getConfigurationAsMap(true));
        addErrorsToConfiguration(result, newPluginProfile);
    } catch (PluginNotFoundException e) {
        newPluginProfile.addError("pluginId", String.format("Plugin with id `%s` is not found.", newPluginProfile.getPluginId()));
    } catch (Exception e) {
    // Ignore - it will be the invalid cipher text exception for an encrypted value. This will be validated later during entity update
    }
}
Also used : PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException)

Example 7 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class RoleConfigCommand method validate.

private void validate(CruiseConfig preprocessedConfig) {
    if (role instanceof PluginRoleConfig) {
        PluginRoleConfig role = (PluginRoleConfig) this.role;
        PluginRoleConfig preprocessedRole = (PluginRoleConfig) this.preprocessedRole;
        SecurityAuthConfig securityAuthConfig = preprocessedConfig.server().security().securityAuthConfigs().find(role.getAuthConfigId());
        if (securityAuthConfig == null) {
            role.addError("authConfigId", "No such security auth configuration present " + role.getAuthConfigId());
            return;
        }
        try {
            ValidationResult result = extension.validateRoleConfiguration(securityAuthConfig.getPluginId(), role.getConfigurationAsMap(true));
            if (!result.isSuccessful()) {
                for (ValidationError validationError : result.getErrors()) {
                    ConfigurationProperty property = preprocessedRole.getProperty(validationError.getKey());
                    if (property == null) {
                        role.addNewConfiguration(validationError.getKey(), false);
                        preprocessedRole.addNewConfiguration(validationError.getKey(), false);
                        property = preprocessedRole.getProperty(validationError.getKey());
                    }
                    property.addError(validationError.getKey(), validationError.getMessage());
                }
            }
        } catch (PluginNotFoundException e) {
            role.addError("authConfigId", "Could not find a security authorization config with id '" + role.getAuthConfigId() + "'.");
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 8 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class SecurityAuthConfigServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating.

@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating() throws Exception {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("some-id", "non-existent-plugin", create("key", false, "value"));
    Username username = new Username("username");
    when(extension.validateAuthConfig(securityAuthConfig.getPluginId(), securityAuthConfig.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException("some error"));
    securityAuthConfigService.create(username, securityAuthConfig, new HttpLocalizedOperationResult());
    assertThat(securityAuthConfig.errors().isEmpty(), is(false));
    assertThat(securityAuthConfig.errors().on("pluginId"), is("Plugin with id `non-existent-plugin` is not found."));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) Test(org.junit.Test)

Example 9 with PluginNotFoundException

use of com.thoughtworks.go.plugin.access.PluginNotFoundException in project gocd by gocd.

the class RoleConfigurationValidatorTest method shouldAddErrorsInAbsenceOfPlugin.

@Test
public void shouldAddErrorsInAbsenceOfPlugin() throws Exception {
    ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("view"));
    PluginRoleConfig roleConfig = new PluginRoleConfig("admin", "auth_id", property);
    when(extension.validateRoleConfiguration("pluginId", Collections.singletonMap("username", "view"))).thenThrow(new PluginNotFoundException("not found"));
    validator.validate(roleConfig, "pluginId");
    assertTrue(roleConfig.hasErrors());
    assertThat(roleConfig.errors().get("pluginRole").get(0), is("Unable to validate `pluginRole` configuration, missing plugin: pluginId"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.Test)

Aggregations

PluginNotFoundException (com.thoughtworks.go.plugin.access.PluginNotFoundException)9 Test (org.junit.Test)6 Username (com.thoughtworks.go.server.domain.Username)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)3 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)3 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)2 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)2 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)1 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)1 ValidationResult (com.thoughtworks.go.plugin.domain.common.ValidationResult)1 VerifyConnectionResponse (com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse)1