Search in sources :

Example 6 with Userinfoplus

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();
}
Also used : Userinfoplus(com.google.api.services.oauth2.model.Userinfoplus) Test(org.junit.Test)

Example 7 with Userinfoplus

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);
}
Also used : Userinfoplus(com.google.api.services.oauth2.model.Userinfoplus) ApiException(org.pmiops.workbench.firecloud.ApiException) Test(org.junit.Test)

Example 8 with Userinfoplus

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());
}
Also used : Oauth2(com.google.api.services.oauth2.Oauth2) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential)

Aggregations

Userinfoplus (com.google.api.services.oauth2.model.Userinfoplus)7 Test (org.junit.Test)5 Oauth2 (com.google.api.services.oauth2.Oauth2)2 ApiException (org.pmiops.workbench.firecloud.ApiException)2 Me (org.pmiops.workbench.firecloud.model.Me)2 UserInfo (org.pmiops.workbench.firecloud.model.UserInfo)2 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 HttpResponseException (com.google.api.client.http.HttpResponseException)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Authorization (io.swagger.annotations.Authorization)1 IOException (java.io.IOException)1 UserAuthentication (org.pmiops.workbench.auth.UserAuthentication)1 WorkbenchConfig (org.pmiops.workbench.config.WorkbenchConfig)1 User (org.pmiops.workbench.db.model.User)1 ForbiddenException (org.pmiops.workbench.exceptions.ForbiddenException)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1