use of com.google.api.services.oauth2.model.Userinfoplus in project workbench by all-of-us.
the class AuthInterceptorTest method preHandleGet_noUserRecord.
@Test
public void preHandleGet_noUserRecord() throws Exception {
when(handler.getMethod()).thenReturn(getProfileApiMethod("getBillingProjects"));
when(request.getMethod()).thenReturn(HttpMethods.GET);
when(request.getHeader(HttpHeaders.AUTHORIZATION)).thenReturn("Bearer foo");
Userinfoplus userInfo = new Userinfoplus();
userInfo.setGivenName("Bob");
userInfo.setFamilyName("Jones");
userInfo.setEmail("bob@fake-domain.org");
when(userInfoService.getUserInfo("foo")).thenReturn(userInfo);
when(userDao.findUserByEmail("bob@fake-domain.org")).thenReturn(null);
when(userService.createUser("Bob", "Jones", "bob@fake-domain.org", null)).thenReturn(user);
assertThat(interceptor.preHandle(request, response, handler)).isTrue();
}
use of com.google.api.services.oauth2.model.Userinfoplus in project workbench by all-of-us.
the class AuthInterceptorTest method preHandleGet_firecloudLookupFails.
@Test
public void preHandleGet_firecloudLookupFails() throws Exception {
when(handler.getMethod()).thenReturn(getProfileApiMethod("getBillingProjects"));
when(request.getMethod()).thenReturn(HttpMethods.GET);
when(request.getHeader(HttpHeaders.AUTHORIZATION)).thenReturn("Bearer foo");
Userinfoplus userInfo = new Userinfoplus();
userInfo.setEmail("bob@bad-domain.org");
when(userInfoService.getUserInfo("foo")).thenReturn(userInfo);
when(fireCloudService.getMe()).thenThrow(new ApiException(HttpServletResponse.SC_NOT_FOUND, "blah"));
assertThat(interceptor.preHandle(request, response, handler)).isFalse();
verify(response).sendError(HttpServletResponse.SC_NOT_FOUND);
}
use of com.google.api.services.oauth2.model.Userinfoplus in project workbench by all-of-us.
the class UserInfoService method getUserInfo.
public Userinfoplus getUserInfo(String token) throws IOException {
GoogleCredential credential = new GoogleCredential().setAccessToken(token);
Oauth2 oauth2 = new Oauth2.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
return ExceptionUtils.executeWithRetries(oauth2.userinfo().get());
}
Aggregations