Search in sources :

Example 1 with PreAuthenticatedAuthenticationToken

use of org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken 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);
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) User(com.thoughtworks.go.plugin.access.authentication.models.User) PreAuthenticatedAuthenticationToken(org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) Test(org.junit.Test)

Aggregations

User (com.thoughtworks.go.plugin.access.authentication.models.User)1 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 Test (org.junit.Test)1 PreAuthenticatedAuthenticationToken (org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken)1