@Test(expected = Exception.class) public void testLoadUserErrorOnClose() { OAuth2IdPToken idPToken = new OAuth2IdPToken(); idPToken.setAccessToken("google_access_token"); GoogleUserEntity testUser = new GoogleUserEntity(); testUser.setId(RandomStringUtils.randomAlphanumeric(10)); testUser.setName("Some Random Name"); testUser.setEmail("lol@example.com"); doReturn(testUser).when(getResponse) .readEntity(GoogleUserEntity.class); doThrow(Exception.class).when(getResponse).close(); MultivaluedStringMap params = new MultivaluedStringMap(); params.putSingle("code", "valid_code"); googleAuth.loadUserIdentity(idPToken); }
@Override protected OAuth2User loadUserIdentity(final OAuth2IdPToken token) { Response r = getClient() .target("https: .request() .header(HttpHeaders.AUTHORIZATION, HttpUtil.authHeaderBearer(token.getAccessToken())) .get(); try { if (r.getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) { GoogleUserEntity gUser = r.readEntity(GoogleUserEntity.class); if (Strings.isNullOrEmpty(gUser.getId())) { throw new ThirdPartyErrorException(); } return gUser.asGenericUser(); } else { Map<String, String> params = r.readEntity(MAP_TYPE); throw new ThirdPartyErrorException(params); } } catch (ProcessingException e) { throw new ThirdPartyErrorException(); } finally { r.close(); } }
GoogleAuthenticator extends AbstractOAuth2Authenticator { @Override protected OAuth2User loadUserIdentity(final OAuth2IdPToken token) { Response r = getClient() .target("https: .request() .header(HttpHeaders.AUTHORIZATION, HttpUtil.authHeaderBearer(token.getAccessToken())) .get(); try { if (r.getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) { GoogleUserEntity gUser = r.readEntity(GoogleUserEntity.class); if (Strings.isNullOrEmpty(gUser.getId())) { throw new ThirdPartyErrorException(); } return gUser.asGenericUser(); } else { Map<String, String> params = r.readEntity(MAP_TYPE); throw new ThirdPartyErrorException(params); } } catch (ProcessingException e) { throw new ThirdPartyErrorException(); } finally { r.close(); } } }
GoogleAuthenticator extends AbstractOAuth2Authenticator { @Override protected OAuth2User loadUserIdentity(final OAuth2IdPToken token) { Response r = getClient() .target("https: .request() .header(HttpHeaders.AUTHORIZATION, HttpUtil.authHeaderBearer(token.getAccessToken())) .get(); try { if (r.getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) { GoogleUserEntity gUser = r.readEntity(GoogleUserEntity.class); if (Strings.isNullOrEmpty(gUser.getId())) { throw new ThirdPartyErrorException(); } return gUser.asGenericUser(); } else { Map<String, String> params = r.readEntity(MAP_TYPE); throw new ThirdPartyErrorException(params); } } catch (ProcessingException e) { throw new ThirdPartyErrorException(); } finally { r.close(); } }  }
GoogleAuthenticator extends AbstractOAuth2Authenticator { @Override protected OAuth2User loadUserIdentity(final OAuth2IdPToken token) { Response r = getClient() .target("https: .request() .header(HttpHeaders.AUTHORIZATION, HttpUtil.authHeaderBearer(token.getAccessToken())) .get(); try { if (r.getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) { GoogleUserEntity gUser = r.readEntity(GoogleUserEntity.class); if (Strings.isNullOrEmpty(gUser.getId())) { throw new ThirdPartyErrorException(); } return gUser.asGenericUser(); } else { Map<String, String> params = r.readEntity(MAP_TYPE); throw new ThirdPartyErrorException(params); } } catch (ProcessingException e) { throw new ThirdPartyErrorException(); } finally { r.close(); } }   }
GoogleAuthenticator extends AbstractOAuth2Authenticator { @Override protected OAuth2User loadUserIdentity(final OAuth2IdPToken token) { Response r = getClient() .target("https: .request() .header(HttpHeaders.AUTHORIZATION, HttpUtil.authHeaderBearer(token.getAccessToken())) .get(); try { if (r.getStatusInfo().getFamily().equals(Family.SUCCESSFUL)) { GoogleUserEntity gUser = r.readEntity(GoogleUserEntity.class); if (Strings.isNullOrEmpty(gUser.getId())) { throw new ThirdPartyErrorException(); } return gUser.asGenericUser(); } else { Map<String, String> params = r.readEntity(MAP_TYPE); throw new ThirdPartyErrorException(params); } } catch (ProcessingException e) { throw new ThirdPartyErrorException(); } finally { r.close(); } }    }