use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class AccessTokenSecurityChecksTest method testInvalidClientResponse.
@SuppressWarnings("unchecked")
@Test
public void testInvalidClientResponse() throws IOException {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("client_id", "APP-0000000000000000");
params.add("client_secret", "clientSecret");
params.add("grant_type", "client_credentials");
params.add("scope", "/read-public");
ClientResponse response = oauthHelper.getResponse(params, APIRequestType.MEMBER);
assertEquals(ClientResponse.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
String result = response.getEntity(String.class);
assertNotNull(result);
HashMap<String, String> error = JsonUtils.readObjectFromJsonString(result, HashMap.class);
assertNotNull(error);
assertEquals("invalid_client", error.get("error"));
assertEquals("Client not found: APP-0000000000000000", error.get("error_description"));
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class InternalAPITest method testGetTokenForInternalScopesFailForMembersAPI.
@Test
public void testGetTokenForInternalScopesFailForMembersAPI() {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("client_id", client1ClientId);
params.add("client_secret", client1ClientSecret);
params.add("grant_type", "client_credentials");
params.add("scope", ScopePathType.INTERNAL_PERSON_LAST_MODIFIED.value());
ClientResponse clientResponse = oauthHelper.getResponse(params, APIRequestType.MEMBER);
assertNotNull(clientResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), clientResponse.getStatus());
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class InternalAPITest method testGetTokenForInternalScopesFailForPublicAPI.
@Test
public void testGetTokenForInternalScopesFailForPublicAPI() {
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("client_id", client1ClientId);
params.add("client_secret", client1ClientSecret);
params.add("grant_type", "client_credentials");
params.add("scope", ScopePathType.INTERNAL_PERSON_LAST_MODIFIED.value());
ClientResponse clientResponse = oauthHelper.getResponse(params, APIRequestType.PUBLIC);
assertNotNull(clientResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), clientResponse.getStatus());
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class OauthGenericCallsController method obtainOauth2TokenPost.
@RequestMapping(value = "/oauth/token", consumes = MediaType.APPLICATION_FORM_URLENCODED, produces = MediaType.APPLICATION_JSON)
public ResponseEntity<?> obtainOauth2TokenPost(HttpServletRequest request) {
String authorization = request.getHeader("Authorization");
Enumeration<String> paramNames = request.getParameterNames();
MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
formParams.add(paramName, request.getParameter(paramName));
}
try {
Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(authorization, formParams);
return ResponseEntity.ok(response.getEntity());
} catch (Exception e) {
OAuthError error = OAuthErrorUtils.getOAuthError(e);
HttpStatus status = HttpStatus.valueOf(error.getResponseStatus().getStatusCode());
return ResponseEntity.status(status).body(error);
}
}
use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class TransformFundRefDataIntoCSV method fetchJsonFromGeoNames.
/**
* Queries GeoNames API for a given geonameId and return the JSON string
* */
private String fetchJsonFromGeoNames(String geoNameId) {
String result = null;
if (cache.containsKey("geoname_json_" + geoNameId)) {
return cache.get("geoname_json_" + geoNameId);
} else {
Client c = Client.create();
WebResource r = c.resource(geonamesApiUrl);
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("geonameId", geoNameId);
params.add("username", apiUser);
result = r.queryParams(params).get(String.class);
cache.put("geoname_json_" + geoNameId, result);
}
return result;
}
Aggregations