Search in sources :

Example 6 with MultivaluedMapImpl

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"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 7 with MultivaluedMapImpl

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 8 with MultivaluedMapImpl

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());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 9 with MultivaluedMapImpl

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);
    }
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) OAuthError(org.orcid.core.oauth.OAuthError) HttpStatus(org.springframework.http.HttpStatus) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with MultivaluedMapImpl

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;
}
Also used : WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Client(com.sun.jersey.api.client.Client)

Aggregations

MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)69 JSONObject (org.codehaus.jettison.json.JSONObject)33 Test (org.junit.Test)31 ClientResponse (com.sun.jersey.api.client.ClientResponse)27 WebResource (com.sun.jersey.api.client.WebResource)19 Test (org.testng.annotations.Test)19 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)12 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)11 JSONArray (org.codehaus.jettison.json.JSONArray)9 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)7 Response (javax.ws.rs.core.Response)6 BridgePort (org.midonet.client.resource.BridgePort)5 Router (org.midonet.client.resource.Router)5 Bridge (org.midonet.client.resource.Bridge)4 Route (org.midonet.client.resource.Route)4 RouterPort (org.midonet.client.resource.RouterPort)4 OAuthServiceException (com.sun.identity.oauth.service.OAuthServiceException)3 Client (com.sun.jersey.api.client.Client)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)3