use of com.sun.jersey.api.client.Client in project ORCID-Source by ORCID.
the class CrossRefManagerImpl method createResource.
private WebResource createResource(String searchTerms) {
Client client = createClient();
String encoded = null;
try {
encoded = URLEncoder.encode(searchTerms, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.error("search terms: " + searchTerms + "cannot be encoded", e);
}
WebResource resource = client.resource(crossRefUrl + "?" + queryString + encoded);
return resource;
}
use of com.sun.jersey.api.client.Client in project ORCID-Source by ORCID.
the class CrossRefManagerImpl method createClient.
private Client createClient() {
Set<Class<?>> providers = new HashSet<Class<?>>();
providers.add(JacksonJsonProvider.class);
ClientConfig config = new DefaultClientConfig(providers);
config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = ApacheHttpClient4.create(config);
client.setFollowRedirects(true);
client.addFilter(new ContentTypeFromTextToJsonClientFilter());
return client;
}
use of com.sun.jersey.api.client.Client in project ORCID-Source by ORCID.
the class OpenIDConnectTest method checkIDTokenAndUserInfo.
//client must have openid scope.
@Test
public void checkIDTokenAndUserInfo() throws InterruptedException, JSONException, ParseException, URISyntaxException, JOSEException {
//Get id token
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String scope = "openid";
HashMap<String, String> params = new HashMap<String, String>();
params.put("nonce", "yesMate");
String authorizationCode = getAuthorizationCode(clientId, clientRedirectUri, scope, userId, password, true, params);
assertNotNull(authorizationCode);
ClientResponse tokenResponse = getAccessTokenResponse(clientId, clientSecret, clientRedirectUri, authorizationCode);
assertEquals(200, tokenResponse.getStatus());
String body = tokenResponse.getEntity(String.class);
JSONObject tokenJSON = new JSONObject(body);
String id = tokenJSON.getString("id_token");
assertNotNull(id);
SignedJWT signedJWT = SignedJWT.parse(id);
Assert.assertEquals("https://orcid.org", signedJWT.getJWTClaimsSet().getIssuer());
Assert.assertEquals("9999-0000-0000-0004", signedJWT.getJWTClaimsSet().getSubject());
Assert.assertEquals("APP-9999999999999901", signedJWT.getJWTClaimsSet().getAudience().get(0));
Assert.assertEquals("yesMate", signedJWT.getJWTClaimsSet().getClaim("nonce"));
//get JWKS
Client client = Client.create();
WebResource webResource = client.resource(baseUri + "/oauth/jwks");
ClientResponse jwksResponse = webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
String jwkString = jwksResponse.getEntity(String.class);
RSAKey jwk = (RSAKey) JWK.parse(jwkString);
//check sig
JWSVerifier verifier = new RSASSAVerifier(jwk);
Assert.assertTrue(signedJWT.verify(verifier));
//get userinfo
webResource = client.resource(baseUri + "/oauth/userinfo");
ClientResponse userInfo = webResource.header("Authorization", "Bearer " + tokenJSON.getString("access_token")).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
String userInfoString = userInfo.getEntity(String.class);
JSONObject user = new JSONObject(userInfoString);
Assert.assertEquals("9999-0000-0000-0004", user.get("sub"));
Assert.assertEquals("User One Credit name", user.get("name"));
Assert.assertEquals("One", user.get("family_name"));
Assert.assertEquals("User", user.get("given_name"));
}
use of com.sun.jersey.api.client.Client in project incubator-atlas by apache.
the class AtlasBaseClient method initializeState.
void initializeState(Configuration configuration, String[] baseUrls, UserGroupInformation ugi, String doAsUser) {
this.configuration = configuration;
Client client = getClient(configuration, ugi, doAsUser);
if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(basicAuthUser, basicAuthPassword);
client.addFilter(authFilter);
}
String activeServiceUrl = determineActiveServiceURL(baseUrls, client);
atlasClientContext = new AtlasClientContext(baseUrls, client, ugi, doAsUser);
service = client.resource(UriBuilder.fromUri(activeServiceUrl).build());
}
use of com.sun.jersey.api.client.Client in project incubator-atlas by apache.
the class AtlasBaseClient method getClient.
@VisibleForTesting
protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) {
DefaultClientConfig config = new DefaultClientConfig();
// Enable POJO mapping feature
config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000);
int connectTimeout = configuration.getInt("atlas.client.connectTimeoutMSecs", 60000);
if (configuration.getBoolean(TLS_ENABLED, false)) {
// configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory
try {
SecureClientUtils.persistSSLClientConfiguration(configuration);
} catch (Exception e) {
LOG.info("Error processing client configuration.", e);
}
}
final URLConnectionClientHandler handler;
if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) {
if (configuration.getBoolean(TLS_ENABLED, false)) {
handler = SecureClientUtils.getUrlConnectionClientHandler();
} else {
handler = new URLConnectionClientHandler();
}
} else {
handler = SecureClientUtils.getClientConnectionHandler(config, configuration, doAsUser, ugi);
}
Client client = new Client(handler, config);
client.setReadTimeout(readTimeout);
client.setConnectTimeout(connectTimeout);
return client;
}
Aggregations