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