Search in sources :

Example 1 with SecurityAuthConfig

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

the class PluginAuthenticationProviderTest method shouldAddUserIfDoesNotExistOnSuccessfulAuthenticationUsingTheAuthorizationPlugin.

@Test
public void shouldAddUserIfDoesNotExistOnSuccessfulAuthenticationUsingTheAuthorizationPlugin() {
    String pluginId = "plugin-id-1";
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", pluginId));
    when(authenticationPluginRegistry.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList()));
    when(store.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList(pluginId)));
    AuthenticationResponse response = new AuthenticationResponse(new User("username", "display-name", "username@example.com"), Collections.emptyList());
    when(authorizationExtension.authenticateUser(pluginId, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId), securityConfig.getPluginRoles(pluginId))).thenReturn(response);
    provider.retrieveUser("username", authenticationToken);
    verify(userService).addUserIfDoesNotExist(new com.thoughtworks.go.domain.User("username", "display-name", "username@example.com"));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) User(com.thoughtworks.go.plugin.access.authentication.models.User) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.Test)

Example 2 with SecurityAuthConfig

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

the class WebBasedAuthenticationFilterTest method setUp.

@Before
public void setUp() throws Exception {
    request = mock(HttpServletRequest.class);
    response = mock(HttpServletResponse.class);
    filterChain = mock(FilterChain.class);
    authorizationExtension = mock(AuthorizationExtension.class);
    goConfigService = mock(GoConfigService.class);
    siteUrlProvider = mock(SiteUrlProvider.class);
    securityConfig = new SecurityConfig();
    securityAuthConfig = new SecurityAuthConfig("github", "github.oauth", new ConfigurationProperty());
    securityConfig.securityAuthConfigs().add(securityAuthConfig);
    stub(goConfigService.security()).toReturn(securityConfig);
    filter = new WebBasedAuthenticationFilter(authorizationExtension, goConfigService, siteUrlProvider);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) FilterChain(javax.servlet.FilterChain) SiteUrlProvider(com.thoughtworks.go.server.web.SiteUrlProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Before(org.junit.Before)

Example 3 with SecurityAuthConfig

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

the class PluginAuthenticationProviderTest method shouldUpdatePluginRolesForAUserPostAuthentication.

@Test
public void shouldUpdatePluginRolesForAUserPostAuthentication() {
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", "cd.go.github"));
    String pluginId1 = "cd.go.ldap";
    String pluginId2 = "cd.go.github";
    addPluginSupportingPasswordBasedAuthentication(pluginId1);
    addPluginSupportingPasswordBasedAuthentication(pluginId2);
    when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(new AuthenticationResponse(new User("username", "bob", "bob@example.com"), Arrays.asList("blackbird", "admins")));
    when(authorizationExtension.authenticateUser(pluginId2, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId2), securityConfig.getPluginRoles(pluginId2))).thenReturn(NULL_AUTH_RESPONSE);
    UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(null, "password"));
    assertNotNull(userDetails);
    verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) User(com.thoughtworks.go.plugin.access.authorization.models.User) UserDetails(org.springframework.security.userdetails.UserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.Test)

Example 4 with SecurityAuthConfig

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

the class PluginAuthenticationProviderTest method reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfGoUserPrinciple.

@Test
public void reuthenticationUsingAuthorizationPlugins_shouldFallbackOnUserNameInAbsenceOfGoUserPrinciple() throws Exception {
    String pluginId1 = "cd.go.ldap";
    securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("ldap", "cd.go.ldap"));
    addPluginSupportingPasswordBasedAuthentication(pluginId1);
    when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), securityConfig.getPluginRoles(pluginId1))).thenReturn(new AuthenticationResponse(new User("username", "bob", "bob@example.com"), Arrays.asList("blackbird", "admins")));
    UserDetails userDetails = provider.retrieveUser("username", new UsernamePasswordAuthenticationToken(null, "password"));
    assertNotNull(userDetails);
    verify(pluginRoleService).updatePluginRoles("cd.go.ldap", "username", CaseInsensitiveString.caseInsensitiveStrings(Arrays.asList("blackbird", "admins")));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) User(com.thoughtworks.go.plugin.access.authorization.models.User) UserDetails(org.springframework.security.userdetails.UserDetails) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.Test)

Example 5 with SecurityAuthConfig

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

the class PluginAuthenticationProviderTest method shouldTryAuthenticatingAgainstEachAuthorizationPluginInCaseOfErrors.

@Test
public void shouldTryAuthenticatingAgainstEachAuthorizationPluginInCaseOfErrors() throws Exception {
    SecurityAuthConfig fileAuthConfig = new SecurityAuthConfig("file_based", "file");
    SecurityAuthConfig ldapAuthConfig = new SecurityAuthConfig("ldap_based", "ldap");
    addPluginSupportingPasswordBasedAuthentication("file");
    addPluginSupportingPasswordBasedAuthentication("ldap");
    securityConfig.securityAuthConfigs().add(fileAuthConfig);
    securityConfig.securityAuthConfigs().add(ldapAuthConfig);
    when(authorizationExtension.authenticateUser("file", "username", "password", Collections.singletonList(fileAuthConfig), Collections.emptyList())).thenThrow(new RuntimeException());
    when(authorizationExtension.authenticateUser("ldap", "username", "password", Collections.singletonList(ldapAuthConfig), Collections.emptyList())).thenReturn(new AuthenticationResponse(new User("username", null, null), Collections.emptyList()));
    UserDetails bob = provider.retrieveUser("username", authenticationToken);
    assertThat(bob.getUsername(), is("username"));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) User(com.thoughtworks.go.plugin.access.authorization.models.User) UserDetails(org.springframework.security.userdetails.UserDetails) AuthenticationResponse(com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse) Test(org.junit.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