use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class PluginAuthenticationProvider method getUserDetailsFromAuthenticationPlugins.
private User getUserDetailsFromAuthenticationPlugins(String username, UsernamePasswordAuthenticationToken authentication) {
Set<String> plugins = authenticationPluginRegistry.getPluginsThatSupportsPasswordBasedAuthentication();
for (String pluginId : plugins) {
String password = (String) authentication.getCredentials();
User user = ensureDisplayNamePresent(authenticationExtension.authenticateUser(pluginId, username, password));
if (user != null) {
return user;
}
}
return null;
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class PluginAuthenticationProviderTest method shouldAddUserIfDoesNotExistOnSuccessfulAuthenticationUsingTheAuthenticationPlugin.
@Test
public void shouldAddUserIfDoesNotExistOnSuccessfulAuthenticationUsingTheAuthenticationPlugin() {
String pluginId = "plugin-id-1";
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", pluginId));
when(authenticationPluginRegistry.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList(pluginId)));
when(authenticationExtension.authenticateUser(pluginId, "username", "password")).thenReturn(new User("username", "display-name", "username@example.com"));
provider.retrieveUser("username", authenticationToken);
verify(userService).addUserIfDoesNotExist(new com.thoughtworks.go.domain.User("username", "display-name", "username@example.com"));
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class PluginAuthenticationProviderTest method shouldCreateGoUserPrincipalWhenAnAuthenticationPluginIsAbleToAuthenticateUser.
@Test
public void shouldCreateGoUserPrincipalWhenAnAuthenticationPluginIsAbleToAuthenticateUser() {
String pluginId1 = "plugin-id-1";
String pluginId2 = "plugin-id-2";
when(authenticationPluginRegistry.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList(pluginId1, pluginId2)));
when(authenticationExtension.authenticateUser(pluginId1, "username", "password")).thenReturn(null);
when(authenticationExtension.authenticateUser(pluginId2, "username", "password")).thenReturn(new User("username", null, null));
UserDetails userDetails = provider.retrieveUser("username", authenticationToken);
assertThat(userDetails, is(instanceOf(GoUserPrinciple.class)));
GoUserPrinciple goUserPrincipal = (GoUserPrinciple) userDetails;
assertThat(goUserPrincipal.getUsername(), is("username"));
assertThat(goUserPrincipal.getDisplayName(), is("username"));
assertThat(goUserPrincipal.getAuthorities().length, is(1));
assertThat(goUserPrincipal.getAuthorities()[0], is(userAuthority));
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class PluginAuthenticationProviderTest method shouldCreateGoUserPrincipalWhenAnAuthorizationPluginIsAbleToAuthenticateUser.
@Test
public void shouldCreateGoUserPrincipalWhenAnAuthorizationPluginIsAbleToAuthenticateUser() {
String pluginId1 = "plugin-id-1";
String pluginId2 = "plugin-id-2";
securityConfig.securityAuthConfigs().add(new SecurityAuthConfig("github", pluginId2));
securityConfig.addRole(new PluginRoleConfig("admin", "github", ConfigurationPropertyMother.create("foo")));
when(store.getPluginsThatSupportsPasswordBasedAuthentication()).thenReturn(new HashSet<>(Arrays.asList(pluginId1, pluginId2)));
when(authorizationExtension.authenticateUser(pluginId1, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId1), null)).thenReturn(NULL_AUTH_RESPONSE);
AuthenticationResponse response = new AuthenticationResponse(new User("username", "display-name", "test@test.com"), Collections.emptyList());
when(authorizationExtension.authenticateUser(pluginId2, "username", "password", securityConfig.securityAuthConfigs().findByPluginId(pluginId2), securityConfig.getPluginRoles(pluginId2))).thenReturn(response);
UserDetails userDetails = provider.retrieveUser("username", authenticationToken);
assertThat(userDetails, is(instanceOf(GoUserPrinciple.class)));
GoUserPrinciple goUserPrincipal = (GoUserPrinciple) userDetails;
assertThat(goUserPrincipal.getUsername(), is("username"));
assertThat(goUserPrincipal.getDisplayName(), is("display-name"));
assertThat(goUserPrincipal.getAuthorities().length, is(1));
assertThat(goUserPrincipal.getAuthorities()[0], is(userAuthority));
}
Aggregations