Search in sources :

Example 86 with ConfigurationProperty

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));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) PreAuthenticatedAuthenticationToken(com.thoughtworks.go.server.security.tokens.PreAuthenticatedAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.Test)

Example 87 with ConfigurationProperty

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));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 88 with ConfigurationProperty

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;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey)

Example 89 with 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());
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ValidationError(com.thoughtworks.go.plugin.domain.common.ValidationError)

Example 90 with ConfigurationProperty

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());
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError)

Aggregations

ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)113 Test (org.junit.Test)71 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)51 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)49 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)30 Configuration (com.thoughtworks.go.domain.config.Configuration)29 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)21 Property (com.thoughtworks.go.plugin.api.config.Property)13 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)13 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)11 GoCipher (com.thoughtworks.go.security.GoCipher)11 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)10 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)8 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)8 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)7 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)7 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)7 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)6 ArrayList (java.util.ArrayList)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5