use of com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse in project gocd by gocd.
the class PreAuthenticatedAuthenticationProviderTest method authenticate_shouldEnsureUserDetailsInAuthTokenHasDisplayName.
@Test
public void authenticate_shouldEnsureUserDetailsInAuthTokenHasDisplayName() {
Map<String, String> credentials = Collections.singletonMap("access_token", "some_token");
PreAuthenticatedAuthenticationToken authenticationToken = new PreAuthenticatedAuthenticationToken(null, credentials, pluginId);
AuthenticationResponse authenticationResponse = new AuthenticationResponse(new User("username", null, "email"), asList("admin"));
when(authorizationExtension.authenticateUser(any(String.class), any(Map.class), any(List.class), any(List.class))).thenReturn(authenticationResponse);
PreAuthenticatedAuthenticationToken authenticate = (PreAuthenticatedAuthenticationToken) authenticationProvider.authenticate(authenticationToken);
GoUserPrinciple principal = (GoUserPrinciple) authenticate.getPrincipal();
assertThat(principal.getDisplayName(), is(authenticationResponse.getUser().getUsername()));
}
use of com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse in project gocd by gocd.
the class PreAuthenticatedAuthenticationProvider method doAuthenticate.
private Authentication doAuthenticate(PreAuthenticatedAuthenticationToken preAuthToken) {
String pluginId = preAuthToken.getPluginId();
AuthenticationResponse response = null;
try {
response = authenticateUser(preAuthToken);
} catch (Exception e) {
handleUnSuccessfulAuthentication(preAuthToken);
}
if (!isAuthenticated(response)) {
handleUnSuccessfulAuthentication(preAuthToken);
}
validateUser(response.getUser());
assignRoles(pluginId, response.getUser().getUsername(), response.getRoles());
UserDetails userDetails = getUserDetails(response.getUser());
userService.addUserIfDoesNotExist(toDomainUser(response.getUser()));
PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(userDetails, preAuthToken.getCredentials(), pluginId, userDetails.getAuthorities());
result.setAuthenticated(true);
return result;
}
use of com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse in project gocd by gocd.
the class AuthenticationResponseTest method shouldAbleToDeserializeJSON.
@Test
public void shouldAbleToDeserializeJSON() throws Exception {
String json = "{\n" + " \"user\": {\n" + " \"username\":\"gocd\",\n" + " \"display_name\": \"GoCD Admin\",\n" + " \"email\": \"gocd@go.cd\"\n" + " },\n" + " \"roles\": [\"admin\",\"blackbird\"]\n" + "}";
AuthenticationResponse authenticationResponse = AuthenticationResponse.fromJSON(json);
assertThat(authenticationResponse.getUser(), is(new User("gocd", "GoCD Admin", "gocd@go.cd")));
assertThat(authenticationResponse.getRoles(), hasSize(2));
assertThat(authenticationResponse.getRoles(), containsInAnyOrder("admin", "blackbird"));
}
Aggregations