use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.
the class IntegrationTest method synchronize_groups.
@Test
public void synchronize_groups() throws InterruptedException {
mapSettings.setProperty(GITLAB_AUTH_SYNC_USER_GROUPS, "true");
OAuth2IdentityProvider.CallbackContext callbackContext = Mockito.mock(OAuth2IdentityProvider.CallbackContext.class);
when(callbackContext.getCallbackUrl()).thenReturn("http://server/callback");
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getParameter("code")).thenReturn(ANY_CODE_VALUE);
when(callbackContext.getRequest()).thenReturn(httpServletRequest);
gitlab.enqueue(new MockResponse().setBody("{\n" + " \"access_token\": \"de6780bc506a0446309bd9362820ba8aed28aa506c71eedbe1c5c4f9dd350e54\",\n" + " \"token_type\": \"bearer\",\n" + " \"expires_in\": 7200,\n" + " \"refresh_token\": \"8257e65c97202ed1726cf9571600918f3bffb2544b26e00a61df9897668c33a1\"\n" + "}"));
// response of /user
gitlab.enqueue(new MockResponse().setBody("{\"id\": 123, \"username\": \"username\", \"name\": \"name\"}"));
// response of /groups
gitlab.enqueue(new MockResponse().setBody("[{\"full_path\": \"group1\"}, {\"full_path\": \"group2\"}]"));
gitLabIdentityProvider.callback(callbackContext);
ArgumentCaptor<UserIdentity> captor = ArgumentCaptor.forClass(UserIdentity.class);
verify(callbackContext).authenticate(captor.capture());
UserIdentity value = captor.getValue();
assertThat(value.getGroups()).contains("group1", "group2");
assertThat(gitlab.takeRequest().getPath()).isEqualTo("/oauth/token");
assertThat(gitlab.takeRequest().getPath()).isEqualTo("/api/v4/user");
assertThat(gitlab.takeRequest().getPath()).isEqualTo("/api/v4/groups?min_access_level=10&per_page=100");
}
use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.
the class BitbucketIdentityProvider method onCallback.
private void onCallback(CallbackContext context) throws InterruptedException, ExecutionException, IOException {
HttpServletRequest request = context.getRequest();
OAuth20Service scribe = newScribeBuilder(context).build(scribeApi);
String code = request.getParameter(OAuthConstants.CODE);
OAuth2AccessToken accessToken = scribe.getAccessToken(code);
GsonUser gsonUser = requestUser(scribe, accessToken);
GsonEmails gsonEmails = requestEmails(scribe, accessToken);
checkTeamRestriction(scribe, accessToken, gsonUser);
UserIdentity userIdentity = userIdentityFactory.create(gsonUser, gsonEmails);
context.authenticate(userIdentity);
context.redirectToRequestedPage();
}
use of org.sonar.api.server.authentication.UserIdentity in project sonarqube by SonarSource.
the class UserRegistrarImplTest method authenticate_new_user_sets_external_id_to_provider_login_when_id_is_null.
@Test
public void authenticate_new_user_sets_external_id_to_provider_login_when_id_is_null() {
UserIdentity newUser = UserIdentity.builder().setProviderId(null).setProviderLogin("johndoo").setName("JOhn").build();
UserDto user = underTest.register(newUserRegistration(newUser));
assertThat(db.users().selectUserByLogin(user.getLogin()).get()).extracting(UserDto::getLogin, UserDto::getExternalId, UserDto::getExternalLogin).contains(user.getLogin(), "johndoo", "johndoo");
}
Aggregations