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