Search in sources :

Example 96 with MultivaluedMapImpl

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

the class RefreshTokenTest method generateRefreshTokenInPublicAPITest.

@Test
public void generateRefreshTokenInPublicAPITest() throws InterruptedException, JSONException {
    String clientId = getClient1ClientId();
    String clientSecret = getClient1ClientSecret();
    String redirectUri = getClient1RedirectUri();
    String userId = getUser1OrcidId();
    String userPassword = getUser1Password();
    WebDriverHelper webDriverHelper = new WebDriverHelper(webDriver, this.getWebBaseUrl(), redirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    String authorizationCode = oauthHelper.getAuthorizationCode(clientId, ScopePathType.PERSON_UPDATE.value(), userId, userPassword, true);
    assertNotNull(authorizationCode);
    assertFalse(PojoUtil.isEmpty(authorizationCode));
    ClientResponse tokenResponse = oauthHelper.getClientResponse(clientId, clientSecret, null, redirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    String refreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshToken);
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("client_id", clientId);
    params.add("client_secret", clientSecret);
    params.add("refresh_token", refreshToken);
    params.add("grant_type", "refresh_token");
    tokenResponse = oauthHelper.getOauthT1Client().obtainOauth2RefreshTokenPost("refresh_token", accessToken, params);
    assertNotNull(tokenResponse);
    assertEquals(200, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String refreshedAccessToken = (String) jsonObject.get("access_token");
    assertNotNull(refreshedAccessToken);
    String refreshedRefreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshedRefreshToken);
    assertFalse(refreshedAccessToken.equals(accessToken));
    assertFalse(refreshedRefreshToken.equals(refreshToken));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebDriverHelper(org.orcid.api.common.WebDriverHelper) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 97 with MultivaluedMapImpl

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

the class RefreshTokenTest method generateRefreshTokenInMemberWithBasicAuthMemberAPITest.

@Test
public void generateRefreshTokenInMemberWithBasicAuthMemberAPITest() throws InterruptedException, JSONException {
    String clientId = getClient1ClientId();
    String clientSecret = getClient1ClientSecret();
    String redirectUri = getClient1RedirectUri();
    String userId = getUser1OrcidId();
    String userPassword = getUser1Password();
    WebDriverHelper webDriverHelper = new WebDriverHelper(webDriver, this.getWebBaseUrl(), redirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    String authorizationCode = oauthHelper.getAuthorizationCode(clientId, ScopePathType.ACTIVITIES_UPDATE.value(), userId, userPassword, true);
    assertNotNull(authorizationCode);
    assertFalse(PojoUtil.isEmpty(authorizationCode));
    ClientResponse tokenResponse = oauthHelper.getClientResponse(clientId, clientSecret, null, redirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    String refreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshToken);
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("refresh_token", refreshToken);
    params.add("grant_type", "refresh_token");
    tokenResponse = oauthHelper.getOauthT2Client().obtainOauth2RefreshTokenPostWithBasicAuth("refresh_token", clientId, clientSecret, params);
    assertNotNull(tokenResponse);
    assertEquals(200, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String refreshedAccessToken = (String) jsonObject.get("access_token");
    assertNotNull(refreshedAccessToken);
    String refreshedRefreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshedRefreshToken);
    assertFalse(refreshedAccessToken.equals(accessToken));
    assertFalse(refreshedRefreshToken.equals(refreshToken));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebDriverHelper(org.orcid.api.common.WebDriverHelper) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 98 with MultivaluedMapImpl

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

the class RefreshTokenTest method generateRefreshTokenInMemberWithoutOriginalTokenAPITest.

@Test
public void generateRefreshTokenInMemberWithoutOriginalTokenAPITest() throws InterruptedException, JSONException {
    String clientId = getClient1ClientId();
    String clientSecret = getClient1ClientSecret();
    String redirectUri = getClient1RedirectUri();
    String userId = getUser1OrcidId();
    String userPassword = getUser1Password();
    WebDriverHelper webDriverHelper = new WebDriverHelper(webDriver, this.getWebBaseUrl(), redirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    String authorizationCode = oauthHelper.getAuthorizationCode(clientId, ScopePathType.ACTIVITIES_UPDATE.value(), userId, userPassword, true);
    assertNotNull(authorizationCode);
    assertFalse(PojoUtil.isEmpty(authorizationCode));
    ClientResponse tokenResponse = oauthHelper.getClientResponse(clientId, clientSecret, null, redirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    String refreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshToken);
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("client_id", clientId);
    params.add("client_secret", clientSecret);
    params.add("refresh_token", refreshToken);
    params.add("grant_type", "refresh_token");
    tokenResponse = oauthHelper.getOauthT2Client().obtainOauth2RefreshTokenPost("refresh_token", null, params);
    assertNotNull(tokenResponse);
    assertEquals(200, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String refreshedAccessToken = (String) jsonObject.get("access_token");
    assertNotNull(refreshedAccessToken);
    String refreshedRefreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshedRefreshToken);
    assertFalse(refreshedAccessToken.equals(accessToken));
    assertFalse(refreshedRefreshToken.equals(refreshToken));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebDriverHelper(org.orcid.api.common.WebDriverHelper) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 99 with MultivaluedMapImpl

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

the class RefreshTokenTest method generateRefreshTokenWithNoClientCredentialsInMemberAPITest.

@Test
public void generateRefreshTokenWithNoClientCredentialsInMemberAPITest() throws InterruptedException, JSONException {
    String clientId = getClient1ClientId();
    String clientSecret = getClient1ClientSecret();
    String redirectUri = getClient1RedirectUri();
    String userId = getUser1OrcidId();
    String userPassword = getUser1Password();
    WebDriverHelper webDriverHelper = new WebDriverHelper(webDriver, this.getWebBaseUrl(), redirectUri);
    oauthHelper.setWebDriverHelper(webDriverHelper);
    String authorizationCode = oauthHelper.getAuthorizationCode(clientId, ScopePathType.ACTIVITIES_UPDATE.value(), userId, userPassword, true);
    assertNotNull(authorizationCode);
    assertFalse(PojoUtil.isEmpty(authorizationCode));
    ClientResponse tokenResponse = oauthHelper.getClientResponse(clientId, clientSecret, null, redirectUri, authorizationCode);
    assertEquals(200, tokenResponse.getStatus());
    String body = tokenResponse.getEntity(String.class);
    JSONObject jsonObject = new JSONObject(body);
    String accessToken = (String) jsonObject.get("access_token");
    assertNotNull(accessToken);
    String refreshToken = (String) jsonObject.get("refresh_token");
    assertNotNull(refreshToken);
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("refresh_token", refreshToken);
    params.add("grant_type", "refresh_token");
    tokenResponse = oauthHelper.getOauthT2Client().obtainOauth2RefreshTokenPost("refresh_token", null, params);
    assertNotNull(tokenResponse);
    assertEquals(401, tokenResponse.getStatus());
    body = tokenResponse.getEntity(String.class);
    jsonObject = new JSONObject(body);
    String error = (String) jsonObject.get("error");
    assertEquals("unauthorized", error);
    String errorDescription = (String) jsonObject.get("error_description");
    assertEquals("An Authentication object was not found in the SecurityContext", errorDescription);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebDriverHelper(org.orcid.api.common.WebDriverHelper) JSONObject(org.codehaus.jettison.json.JSONObject) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Test(org.junit.Test)

Example 100 with MultivaluedMapImpl

use of com.sun.jersey.core.util.MultivaluedMapImpl in project java-docs-samples by GoogleCloudPlatform.

the class MailgunServlet method sendSimpleMessage.

// CHECKSTYLE OFF: VariableDeclarationUsageDistance
// [START simple]
private ClientResponse sendSimpleMessage(String recipient) {
    Client client = Client.create();
    client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
    WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
    MultivaluedMapImpl formData = new MultivaluedMapImpl();
    formData.add("from", "Mailgun User <mailgun@" + MAILGUN_DOMAIN_NAME + ">");
    formData.add("to", recipient);
    formData.add("subject", "Simple Mailgun Example");
    formData.add("text", "Plaintext content");
    return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
}
Also used : WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) Client(com.sun.jersey.api.client.Client) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)

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