Search in sources :

Example 71 with SecurityAuthConfig

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

the class SecurityAuthConfigUpdateCommandTest method shouldUpdateExistingProfile.

@Test
public void shouldUpdateExistingProfile() throws Exception {
    SecurityAuthConfig oldAuthConfig = new SecurityAuthConfig("foo", "ldap");
    SecurityAuthConfig newAuthConfig = new SecurityAuthConfig("foo", "github");
    cruiseConfig.server().security().securityAuthConfigs().add(oldAuthConfig);
    SecurityAuthConfigUpdateCommand command = new SecurityAuthConfigUpdateCommand(null, newAuthConfig, null, null, null, null, null);
    command.update(cruiseConfig);
    assertThat(cruiseConfig.server().security().securityAuthConfigs().find("foo"), is(equalTo(newAuthConfig)));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) Test(org.junit.jupiter.api.Test)

Example 72 with SecurityAuthConfig

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

the class RevokeStaleAccessTokenServiceTest method shouldRevokeTheTokensWhenTheAuthConfigsIsDeletedFromTheConfig.

@Test
void shouldRevokeTheTokensWhenTheAuthConfigsIsDeletedFromTheConfig() {
    BasicCruiseConfig config = new BasicCruiseConfig();
    config.server().security().securityAuthConfigs().add(authConfig1);
    config.server().security().securityAuthConfigs().add(authConfig2);
    when(goConfigService.getConfigForEditing()).thenReturn(config);
    when(accessTokenService.findAllTokensForAllUsers(AccessTokenFilter.active)).thenReturn(Arrays.asList(authConfig1_token1, authConfig1_token2, authConfig2_token1));
    service.initialize();
    verify(accessTokenService, never()).revokeAccessTokenByGoCD(anyInt(), anyString());
    BasicCruiseConfig updated = new BasicCruiseConfig();
    updated.server().security().securityAuthConfigs().add(authConfig1);
    when(goConfigService.getConfigForEditing()).thenReturn(updated);
    service.onEntityConfigChange(new SecurityAuthConfig());
    verify(accessTokenService).revokeAccessTokenByGoCD(2, "Revoked by GoCD: The authorization configuration 'authConfig2' referenced from the current access token is deleted from GoCD.");
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.jupiter.api.Test)

Example 73 with SecurityAuthConfig

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

the class SecurityAuthConfigServiceTest method shouldReturnAMapOfSecurityAuthConfigs.

@Test
public void shouldReturnAMapOfSecurityAuthConfigs() throws Exception {
    SecurityAuthConfig authConfig = new SecurityAuthConfig("ldap", "cd.go.ldap");
    SecurityConfig securityConfig = new SecurityConfig();
    securityConfig.securityAuthConfigs().add(authConfig);
    when(goConfigService.security()).thenReturn(securityConfig);
    HashMap<String, SecurityAuthConfig> expectedMap = new HashMap<>();
    expectedMap.put("ldap", authConfig);
    Map<String, SecurityAuthConfig> authConfigMap = securityAuthConfigService.listAll();
    assertThat(authConfigMap.size(), is(1));
    assertThat(authConfigMap, is(expectedMap));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Test(org.junit.jupiter.api.Test)

Example 74 with SecurityAuthConfig

use of com.thoughtworks.go.config.SecurityAuthConfig 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 RecordNotFoundException("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."));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Example 75 with SecurityAuthConfig

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

the class SecurityAuthConfigServiceTest method shouldGetAListOfAllConfiguredWebBasedAuthorizationPlugins.

@Test
public void shouldGetAListOfAllConfiguredWebBasedAuthorizationPlugins() {
    Set<AuthorizationPluginInfo> installedWebBasedPlugins = new HashSet<>();
    String githubPluginId = "cd.go.github";
    AuthorizationPluginInfo githubPluginInfo = pluginInfo(githubPluginId, "GitHub Auth Plugin", SupportedAuthType.Web);
    installedWebBasedPlugins.add(githubPluginInfo);
    installedWebBasedPlugins.add(pluginInfo(githubPluginId, "Google Auth Plugin", SupportedAuthType.Web));
    when(authorizationMetadataStore.getPluginsThatSupportsWebBasedAuthentication()).thenReturn(installedWebBasedPlugins);
    when(authorizationMetadataStore.getPluginInfo(githubPluginId)).thenReturn(githubPluginInfo);
    SecurityConfig securityConfig = new SecurityConfig();
    SecurityAuthConfig github = new SecurityAuthConfig("github", githubPluginId);
    SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
    securityConfig.securityAuthConfigs().add(github);
    securityConfig.securityAuthConfigs().add(ldap);
    when(goConfigService.security()).thenReturn(securityConfig);
    List<AuthPluginInfoViewModel> allWebBasedAuthorizationConfigs = securityAuthConfigService.getAllConfiguredWebBasedAuthorizationPlugins();
    assertThat(allWebBasedAuthorizationConfigs.size(), is(1));
    AuthPluginInfoViewModel pluginInfoViewModel = allWebBasedAuthorizationConfigs.get(0);
    assertThat(pluginInfoViewModel.pluginId(), is(githubPluginId));
    assertThat(pluginInfoViewModel.name(), is("GitHub Auth Plugin"));
    assertThat(pluginInfoViewModel.imageUrl(), is("/go/api/plugin_images/cd.go.github/hash"));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) AuthPluginInfoViewModel(com.thoughtworks.go.server.ui.AuthPluginInfoViewModel) 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