Search in sources :

Example 86 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class OrcidClientCredentialEndPointDelegatorTest method generateClientCredentialsAccessTokenTest.

@Test
public void generateClientCredentialsAccessTokenTest() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly(CLIENT_ID_1, ScopePathType.ACTIVITIES_UPDATE, ScopePathType.READ_LIMITED);
    MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
    formParams.add("client_id", CLIENT_ID_1);
    formParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
    formParams.add("grant_type", "client_credentials");
    formParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
    formParams.add("scope", "/orcid-profile/create");
    Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(null, formParams);
    assertNotNull(response);
    assertNotNull(response.getEntity());
    DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) response.getEntity();
    assertNotNull(token);
    assertTrue(!PojoUtil.isEmpty(token.getValue()));
    assertNotNull(token.getRefreshToken());
    assertTrue(!PojoUtil.isEmpty(token.getRefreshToken().getValue()));
}
Also used : Response(javax.ws.rs.core.Response) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 87 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class OrcidClientCredentialEndPointDelegatorTest method generateAccessTokenTest.

@Test
public void generateAccessTokenTest() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly(CLIENT_ID_1, ScopePathType.ACTIVITIES_UPDATE, ScopePathType.READ_LIMITED);
    OrcidOauth2AuthoriziationCodeDetail authCode = createAuthorizationCode("code-1", CLIENT_ID_1, "http://www.APP-5555555555555555.com/redirect/oauth", true, "/activities/update");
    MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
    formParams.add("client_id", CLIENT_ID_1);
    formParams.add("client_secret", "DhkFj5EI0qp6GsUKi55Vja+h+bsaKpBx");
    formParams.add("grant_type", "authorization_code");
    formParams.add("redirect_uri", "http://www.APP-5555555555555555.com/redirect/oauth");
    formParams.add("code", authCode.getId());
    Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(null, formParams);
    assertNotNull(response);
    assertNotNull(response.getEntity());
    DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) response.getEntity();
    assertNotNull(token);
    assertTrue(!PojoUtil.isEmpty(token.getValue()));
    assertNotNull(token.getRefreshToken());
    assertTrue(!PojoUtil.isEmpty(token.getRefreshToken().getValue()));
}
Also used : Response(javax.ws.rs.core.Response) OrcidOauth2AuthoriziationCodeDetail(org.orcid.persistence.jpa.entities.OrcidOauth2AuthoriziationCodeDetail) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 88 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class PublicClientTest method testAuthenticateOnPublicAPI.

@Test
public void testAuthenticateOnPublicAPI() throws JSONException, InterruptedException {
    String clientId = getPublicClientId();
    String clientRedirectUri = getPublicClientRedirectUri();
    String clientSecret = getPublicClientSecret();
    String userId = getUser1OrcidId();
    String password = getUser1Password();
    String authorizationCode = getAuthorizationCode(clientId, clientRedirectUri, "/authenticate", userId, password, true);
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("client_id", clientId);
    params.add("client_secret", clientSecret);
    params.add("grant_type", "authorization_code");
    params.add("scope", "/authenticate");
    params.add("redirect_uri", clientRedirectUri);
    params.add("code", authorizationCode);
    ClientResponse response = t1OAuthClient.obtainOauth2TokenPost("client_credentials", params);
    assertEquals(200, response.getStatus());
    String body = response.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    assertNotNull(jsonObject);
    assertNotNull(jsonObject.get("access_token"));
    assertEquals(userId, jsonObject.get("orcid"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 89 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class PublicClientTest method testAuthenticateOnMembersAPI.

@Test
public void testAuthenticateOnMembersAPI() throws JSONException, InterruptedException {
    String clientId = getPublicClientId();
    String clientRedirectUri = getPublicClientRedirectUri();
    String clientSecret = getPublicClientSecret();
    String userId = getUser1OrcidId();
    String password = getUser1Password();
    String authorizationCode = getAuthorizationCode(clientId, clientRedirectUri, "/authenticate", userId, password, true);
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("client_id", clientId);
    params.add("client_secret", clientSecret);
    params.add("grant_type", "authorization_code");
    params.add("scope", "/authenticate");
    params.add("redirect_uri", clientRedirectUri);
    params.add("code", authorizationCode);
    ClientResponse response = t2OAuthClient.obtainOauth2TokenPost("client_credentials", params);
    assertEquals(200, response.getStatus());
    String body = response.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    assertNotNull(jsonObject);
    assertNotNull(jsonObject.get("access_token"));
    assertEquals(userId, jsonObject.get("orcid"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 90 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.

the class InternalAPITest method testGetTokenForInternalScopes.

@Test
public void testGetTokenForInternalScopes() throws JSONException {
    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.INTERNAL);
    assertNotNull(clientResponse);
    assertEquals(Response.Status.OK.getStatusCode(), clientResponse.getStatus());
    String body = clientResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    assertFalse(PojoUtil.isEmpty(accessToken));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Aggregations

MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)131 Test (org.junit.Test)55 ClientResponse (com.sun.jersey.api.client.ClientResponse)48 WebResource (com.sun.jersey.api.client.WebResource)39 JSONObject (org.codehaus.jettison.json.JSONObject)39 Test (org.testng.annotations.Test)35 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)12 List (java.util.List)11 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)11 JSONArray (org.codehaus.jettison.json.JSONArray)9 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 Client (com.sun.jersey.api.client.Client)7 SearchFilter (org.apache.atlas.model.SearchFilter)7 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)7 WebDriverHelper (org.orcid.api.common.WebDriverHelper)7 Response (javax.ws.rs.core.Response)6 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)6 AtlasLineageInfo (org.apache.atlas.model.lineage.AtlasLineageInfo)6 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)6