use of com.sun.jersey.core.util.MultivaluedMapImpl in project ORCID-Source by ORCID.
the class MailGunManager method sendEmail.
public boolean sendEmail(String from, String to, String subject, String text, String html, boolean custom) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", getApiKey()));
// determine correct api based off domain.
WebResource webResource = null;
String toAddress = to.trim();
String fromEmail = getFromEmail(from);
if (shouldBeSentThroughDedicatedIP(toAddress)) {
if (custom)
webResource = client.resource(getAltNotifyApiUrl());
else if (fromEmail.endsWith("@verify.orcid.org"))
webResource = client.resource(getAltVerifyApiUrl());
else if (fromEmail.endsWith("@notify.orcid.org"))
webResource = client.resource(getAltNotifyApiUrl());
else
webResource = client.resource(getAltApiUrl());
} else {
if (custom)
webResource = client.resource(getNotifyApiUrl());
else if (fromEmail.endsWith("@verify.orcid.org"))
webResource = client.resource(getVerifyApiUrl());
else if (fromEmail.endsWith("@notify.orcid.org"))
webResource = client.resource(getNotifyApiUrl());
else
webResource = client.resource(getApiUrl());
}
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("from", from);
formData.add("to", to);
formData.add("subject", subject);
formData.add("text", text);
if (html != null) {
formData.add("html", html);
}
formData.add("o:testmode", testmode);
if (testmode.equals("yes"))
LOGGER.error("Email form data: \n" + formData.toString());
// sandbox
if (to.matches(filter)) {
ClientResponse cr = webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, formData);
if (cr.getStatus() != 200) {
LOGGER.error("Post MailGunManager.sendEmail not accepted: " + formData.toString());
return false;
}
}
return true;
}
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"));
}
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"));
}
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("redirect_uri", redirectUri);
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 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));
}
Aggregations