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));
}
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));
}
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));
}
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);
}
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);
}
Aggregations