Search in sources :

Example 61 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.

the class AuthorizationMessageConverterV2Test method shouldReturnRequestBodyForGetUserRolesRequest.

@Test
void shouldReturnRequestBodyForGetUserRolesRequest() {
    SecurityAuthConfig authConfig = new SecurityAuthConfig("p1", "ldap", create("key1", false, "value2"));
    List<PluginRoleConfig> roleConfigs = singletonList(new PluginRoleConfig("role1", "p1", create("key2", false, "value2")));
    String requestBody = converter.getUserRolesRequestBody("foo", authConfig, roleConfigs);
    assertThatJson(requestBody).isEqualTo("{\n" + "  \"auth_config\": {\n" + "      \"configuration\": {\n" + "        \"key1\": \"value2\"\n" + "      },\n" + "      \"id\": \"p1\"\n" + "    },\n" + "  \"username\": \"foo\",\n" + "  \"role_configs\": [\n" + "    {\n" + "      \"auth_config_id\": \"p1\",\n" + "      \"configuration\": {\n" + "        \"key2\": \"value2\"\n" + "      },\n" + "      \"name\": \"role1\"\n" + "    }\n" + "  ]\n" + "}");
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) Test(org.junit.jupiter.api.Test)

Example 62 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.

the class SecurityAuthConfigService method getAllConfiguredWebBasedAuthorizationPlugins.

public List<AuthPluginInfoViewModel> getAllConfiguredWebBasedAuthorizationPlugins() {
    ArrayList<AuthPluginInfoViewModel> result = new ArrayList();
    Set<AuthorizationPluginInfo> loadedWebBasedAuthPlugins = authorizationMetadataStore.getPluginsThatSupportsWebBasedAuthentication();
    SecurityAuthConfigs configuredAuthPluginProfiles = getPluginProfiles();
    for (SecurityAuthConfig authConfig : configuredAuthPluginProfiles) {
        AuthorizationPluginInfo authorizationPluginInfo = loadedWebBasedAuthPlugins.stream().filter(authorizationPluginInfo1 -> authorizationPluginInfo1.getDescriptor().id().equals(authConfig.getPluginId())).findFirst().orElse(null);
        if (authorizationPluginInfo != null) {
            result.add(new AuthPluginInfoViewModel(authorizationPluginInfo));
        }
    }
    return result;
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ArrayList(java.util.ArrayList) AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) SecurityAuthConfigs(com.thoughtworks.go.config.SecurityAuthConfigs) AuthPluginInfoViewModel(com.thoughtworks.go.server.ui.AuthPluginInfoViewModel)

Example 63 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.

the class SecurityAuthConfigCreateCommandTest method shouldInvokePluginValidationsBeforeSave.

@Test
public void shouldInvokePluginValidationsBeforeSave() throws Exception {
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("key", "error"));
    when(extension.validateAuthConfig(eq("aws"), anyMap())).thenReturn(validationResult);
    SecurityAuthConfig newProfile = new SecurityAuthConfig("foo", "aws", new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("val")));
    PluginProfileCommand command = new SecurityAuthConfigCreateCommand(mock(GoConfigService.class), newProfile, extension, null, new HttpLocalizedOperationResult());
    BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
    assertThatThrownBy(() -> command.isValid(cruiseConfig)).isInstanceOf(RecordNotFoundException.class).hasMessageContaining(EntityType.SecurityAuthConfig.notFoundMessage(newProfile.getId()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.jupiter.api.Test)

Example 64 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.

the class SecurityAuthConfigCommandTest method shouldNotContinueWithConfigSaveIfUserIsGroupAdmin.

@Test
public void shouldNotContinueWithConfigSaveIfUserIsGroupAdmin() throws Exception {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("blackbird", "ldap");
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    when(goConfigService.isGroupAdministrator(currentUser)).thenReturn(true);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, currentUser, result);
    assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), nullValue());
    assertThat(command.canContinue(cruiseConfig), is(false));
    assertThat(result.message(), is(EntityType.SecurityAuthConfig.forbiddenToEdit(securityAuthConfig.getId(), currentUser.getUsername())));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.jupiter.api.Test)

Example 65 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig in project gocd by gocd.

the class SecurityAuthConfigCommandTest method shouldContinueWithConfigSaveIfUserIsGroupAdmin.

@Test
public void shouldContinueWithConfigSaveIfUserIsGroupAdmin() throws Exception {
    SecurityAuthConfig securityAuthConfig = new SecurityAuthConfig("blackbird", "ldap");
    when(goConfigService.isUserAdmin(currentUser)).thenReturn(false);
    when(goConfigService.isGroupAdministrator(currentUser.getUsername())).thenReturn(true);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    SecurityAuthConfigCommand command = new SecurityAuthConfigCommandTest.StubCommand(goConfigService, securityAuthConfig, extension, currentUser, result);
    assertThat(cruiseConfig.server().security().securityAuthConfigs().find("ldap"), nullValue());
    assertThat(command.canContinue(cruiseConfig), is(false));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)81 Test (org.junit.jupiter.api.Test)46 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)28 Test (org.junit.Test)16 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)14 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)14 User (com.thoughtworks.go.plugin.access.authorization.models.User)11 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)9 Username (com.thoughtworks.go.server.domain.Username)9 UserDetails (org.springframework.security.userdetails.UserDetails)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)7 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)5 VerifyConnectionResponse (com.thoughtworks.go.plugin.domain.common.VerifyConnectionResponse)5 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)4 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)4 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)4 ValidationResult (com.thoughtworks.go.plugin.domain.common.ValidationResult)4 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)4