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
}
}
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() + "'.");
}
}
}
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."));
}
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"));
}
Aggregations