use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class JsonMessageHandler1_0Test method shouldHandleEmptyResponseMessageForAuthenticateUser.
@Test
public void shouldHandleEmptyResponseMessageForAuthenticateUser() throws Exception {
User user1 = messageHandler.responseMessageForAuthenticateUser("");
assertThat(user1, is(nullValue()));
User user2 = messageHandler.responseMessageForAuthenticateUser("{}");
assertThat(user2, is(nullValue()));
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class JsonMessageHandler1_0 method responseMessageForAuthenticateUser.
@Override
public User responseMessageForAuthenticateUser(String responseBody) {
Map map;
try {
map = parseResponseToMap(responseBody);
} catch (Exception e) {
throw new RuntimeException("User should be returned as a map");
}
if (map == null || map.isEmpty()) {
return null;
}
Map userMap;
try {
userMap = (Map) map.get("user");
} catch (Exception e) {
throw new RuntimeException("User should be returned as a map");
}
User user = toUser(userMap);
return user;
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class AuthenticationRequestProcessorTest method shouldAuthenticateUser.
@Test
public void shouldAuthenticateUser() {
String responseBody = "expected-response-body";
User user = new User("username", "display name", "test@test.com");
when(jsonMessageHandler.responseMessageForAuthenticateUser(responseBody)).thenReturn(user);
AuthenticationRequestProcessor processorSpy = spy(processor);
doReturn(securityContext).when(processorSpy).getSecurityContext();
GoApiResponse response = processorSpy.process(pluginDescriptor, getGoPluginApiRequest("1.0", responseBody));
assertThat(response.responseCode(), is(200));
verify(userService).addUserIfDoesNotExist(new com.thoughtworks.go.domain.User("username", "", ""));
GoUserPrinciple goUserPrincipal = processorSpy.getGoUserPrincipal(user);
assertThat(goUserPrincipal.getUsername(), is("username"));
assertThat(goUserPrincipal.getDisplayName(), is("display name"));
verifyGrantAuthorities(goUserPrincipal.getAuthorities());
PreAuthenticatedAuthenticationToken authenticationToken = processorSpy.getAuthenticationToken(goUserPrincipal);
assertThat(authenticationToken.getPrincipal(), is(goUserPrincipal));
verifyGrantAuthorities(authenticationToken.getAuthorities());
verify(securityContext).setAuthentication(authenticationToken);
}
use of com.thoughtworks.go.plugin.access.authentication.models.User 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"));
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class JsonMessageHandler1_0 method responseMessageForSearchUser.
@Override
public List<User> responseMessageForSearchUser(String responseBody) {
List<Map> list;
try {
list = parseResponseToList(responseBody);
} catch (Exception e) {
throw new RuntimeException("Search results should be returned as a list");
}
List<User> searchResults = new ArrayList<>();
if (list == null || list.isEmpty()) {
return searchResults;
}
for (Map userMap : list) {
User user = toUser(userMap);
searchResults.add(user);
}
return searchResults;
}
Aggregations