use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_inCaseOfMultipleAuthConfigsOnSuccessfulAuthenticationShouldNotTryAuthenticatingUserUsingRemainingAuthConfig.
@Test
public void authenticate_inCaseOfMultipleAuthConfigsOnSuccessfulAuthenticationShouldNotTryAuthenticatingUserUsingRemainingAuthConfig() {
Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
SecurityAuthConfig githubPublic = new SecurityAuthConfig("github_public", pluginId);
SecurityAuthConfig githubEnterprise = new SecurityAuthConfig("github_enterprise", pluginId);
PluginRoleConfig adminRole = new PluginRoleConfig("admin", githubPublic.getId(), new ConfigurationProperty());
PluginRoleConfig operatorRole = new PluginRoleConfig("operator", githubEnterprise.getId(), new ConfigurationProperty());
securityConfig.securityAuthConfigs().clear();
securityConfig.securityAuthConfigs().add(githubPublic);
securityConfig.securityAuthConfigs().add(githubEnterprise);
securityConfig.addRole(adminRole);
securityConfig.addRole(operatorRole);
PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
when(authorizationExtension.authenticateUser(pluginId, credentials, Collections.singletonList(githubPublic), Collections.singletonList(adminRole))).thenReturn(new AuthenticationResponse(user, asList("admin")));
PreAuthenticatedAuthenticationToken authenticate = (PreAuthenticatedAuthenticationToken) authenticationProvider.authenticate(authenticationToken);
assertThat(authenticate.getCredentials(), is(credentials));
assertThat(authenticate.getPluginId(), is(pluginId));
assertThat(authenticate.getAuthorities(), is(authorities));
assertThat(authenticate.isAuthenticated(), is(true));
verify(authorizationExtension).authenticateUser(pluginId, credentials, Collections.singletonList(githubPublic), Collections.singletonList(adminRole));
verify(authorizationExtension, never()).authenticateUser(pluginId, credentials, Collections.singletonList(githubEnterprise), Collections.singletonList(operatorRole));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class CreateAgentMessageTest method shouldGetPluginId.
@Test
public void shouldGetPluginId() {
List<ConfigurationProperty> properties = Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")));
ElasticProfile jobAgentConfig = new ElasticProfile("foo", "plugin-id", properties);
CreateAgentMessage message = new CreateAgentMessage("key", "env", jobAgentConfig, null);
assertThat(message.pluginId(), is(jobAgentConfig.getPluginId()));
Map<String, String> configurationAsMap = jobAgentConfig.getConfigurationAsMap(true);
assertThat(message.configuration(), is(configurationAsMap));
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class ConfigurationPropertyBuilder method create.
public ConfigurationProperty create(String key, String value, String encryptedValue, Boolean isSecure) {
ConfigurationProperty configurationProperty = new ConfigurationProperty();
configurationProperty.setConfigurationKey(new ConfigurationKey(key));
if (isNotBlank(value) && isNotBlank(encryptedValue)) {
configurationProperty.addError("configurationValue", "You may only specify `value` or `encrypted_value`, not both!");
configurationProperty.addError("encryptedValue", "You may only specify `value` or `encrypted_value`, not both!");
configurationProperty.setConfigurationValue(new ConfigurationValue(value));
configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue));
return configurationProperty;
}
if (isSecure) {
if (isNotBlank(encryptedValue)) {
configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue));
}
if (isNotBlank(value)) {
configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encrypt(value)));
}
} else {
if (isNotBlank(encryptedValue)) {
configurationProperty.addError("encryptedValue", "encrypted_value cannot be specified to a unsecured property.");
configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue));
}
if (isNotBlank(value)) {
configurationProperty.setConfigurationValue(new ConfigurationValue(value));
}
}
return configurationProperty;
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class SecurityAuthConfigService method mapErrors.
private void mapErrors(VerifyConnectionResponse response, SecurityAuthConfig authConfig) {
com.thoughtworks.go.plugin.domain.common.ValidationResult validationResult = response.getValidationResult();
if (validationResult == null) {
return;
}
for (ValidationError error : validationResult.getErrors()) {
ConfigurationProperty property = authConfig.getProperty(error.getKey());
if (property == null) {
authConfig.addNewConfiguration(error.getKey(), false);
property = authConfig.getProperty(error.getKey());
}
property.addError(error.getKey(), error.getMessage());
}
}
use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.
the class PackageDefinitionService method addErrorsToConfiguration.
private void addErrorsToConfiguration(ValidationResult validationResult, PackageDefinition packageDefinition) {
for (ValidationError validationError : validationResult.getErrors()) {
ConfigurationProperty property = packageDefinition.getConfiguration().getProperty(validationError.getKey());
if (property != null) {
property.addError(validationError.getKey(), validationError.getMessage());
} else {
String validationErrorKey = StringUtils.isBlank(validationError.getKey()) ? PackageDefinition.CONFIGURATION : validationError.getKey();
packageDefinition.addError(validationErrorKey, validationError.getMessage());
}
}
}
Aggregations