Search in sources :

Example 1 with User

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);
}
Also used : DefaultGoApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse) User(com.thoughtworks.go.plugin.access.authentication.models.User) Authentication(org.springframework.security.Authentication) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)

Example 2 with User

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);
}
Also used : User(com.thoughtworks.go.plugin.access.authentication.models.User) Test(org.junit.Test)

Example 3 with User

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"))));
}
Also used : User(com.thoughtworks.go.plugin.access.authentication.models.User) Test(org.junit.Test)

Example 4 with User

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)));
}
Also used : User(com.thoughtworks.go.plugin.access.authentication.models.User) Test(org.junit.Test)

Example 5 with User

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")));
}
Also used : User(com.thoughtworks.go.plugin.access.authentication.models.User) Test(org.junit.Test)

Aggregations

User (com.thoughtworks.go.plugin.access.authentication.models.User)14 Test (org.junit.Test)10 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)4 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)3 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UserDetails (org.springframework.security.userdetails.UserDetails)2 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 DefaultGoApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse)1 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)1 ArrayList (java.util.ArrayList)1 Authentication (org.springframework.security.Authentication)1 PreAuthenticatedAuthenticationToken (org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken)1