use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class AuthenticationRequestProcessor method process.
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
try {
String version = goPluginApiRequest.apiVersion();
if (!goSupportedVersions.contains(version)) {
throw new RuntimeException(String.format("Unsupported '%s' API version: %s. Supported versions: %s", AUTHENTICATE_USER_REQUEST, version, goSupportedVersions));
}
User user = messageHandlerMap.get(version).responseMessageForAuthenticateUser(goPluginApiRequest.requestBody());
if (user == null) {
throw new RuntimeException(String.format("Could not parse User details. Request Body: %s", goPluginApiRequest.requestBody()));
}
GoUserPrinciple goUserPrincipal = getGoUserPrincipal(user);
Authentication authentication = getAuthenticationToken(goUserPrincipal);
userService.addUserIfDoesNotExist(UserHelper.getUser(authentication));
getSecurityContext().setAuthentication(authentication);
return new DefaultGoApiResponse(200);
} catch (Exception e) {
LOGGER.error("Error occurred while authenticating user", e);
}
return new DefaultGoApiResponse(500);
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class AuthenticationExtensionTest method shouldTalkToPluginToAuthenticateUser.
@Test
public void shouldTalkToPluginToAuthenticateUser() throws Exception {
String username = "username";
String password = "password";
when(jsonMessageHandler.requestMessageForAuthenticateUser(username, password)).thenReturn(REQUEST_BODY);
User response = new User("username", "display-name", "email-id");
when(jsonMessageHandler.responseMessageForAuthenticateUser(RESPONSE_BODY)).thenReturn(response);
User deserializedResponse = authenticationExtension.authenticateUser(PLUGIN_ID, username, password);
assertRequest(requestArgumentCaptor.getValue(), AuthenticationExtension.EXTENSION_NAME, "1.0", AuthenticationExtension.REQUEST_AUTHENTICATE_USER, REQUEST_BODY);
verify(jsonMessageHandler).responseMessageForAuthenticateUser(RESPONSE_BODY);
assertSame(response, deserializedResponse);
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class JsonMessageHandler1_0Test method shouldHandleResponseMessageForSearchUser.
@Test
public void shouldHandleResponseMessageForSearchUser() throws Exception {
String user1Json = "{\"username\":\"username1\",\"display-name\":\"user 1\",\"email-id\":\"test1@test.com\"}";
String user2Json = "{\"username\":\"username2\",\"display-name\":\"user 2\",\"email-id\":\"test2@test.com\"}";
List<User> users = messageHandler.responseMessageForSearchUser(String.format("[%s,%s]", user1Json, user2Json));
assertThat(users, is(Arrays.asList(new User("username1", "user 1", "test1@test.com"), new User("username2", "user 2", "test2@test.com"))));
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class JsonMessageHandler1_0Test method shouldHandleMissingDataInResponseMessageForAuthenticateUser.
@Test
public void shouldHandleMissingDataInResponseMessageForAuthenticateUser() throws Exception {
User user = messageHandler.responseMessageForAuthenticateUser("{\"user\":{\"username\":\"username\"}}");
assertThat(user, is(new User("username", null, null)));
}
use of com.thoughtworks.go.plugin.access.authentication.models.User in project gocd by gocd.
the class JsonMessageHandler1_0Test method shouldHandleResponseMessageForAuthenticateUser.
@Test
public void shouldHandleResponseMessageForAuthenticateUser() throws Exception {
User user = messageHandler.responseMessageForAuthenticateUser("{\"user\":{\"username\":\"username\",\"display-name\":\"display-name\",\"email-id\":\"test@test.com\"}}");
assertThat(user, is(new User("username", "display-name", "test@test.com")));
}
Aggregations