Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
#283 change the social login email subject line (#284)
Browse files Browse the repository at this point in the history
* #283 change the social login subject line

* Pom version change release

* giving defaults property values and removing warning associated with invalid cookie header
  • Loading branch information
pushyamig authored Jun 15, 2020
1 parent f9aca68 commit 0f303cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>edu.umich.ctools</groupId>
<artifactId>canvasCourseManager</artifactId>
<packaging>war</packaging>
<version>4.0.6</version>
<version>4.0.7</version>
<name>canvasCourseManager</name>
<url>http://maven.apache.org</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
Expand Down Expand Up @@ -107,12 +109,15 @@ private void socialLoginRestApiCall(HttpServletRequest request,
String keySecretStr = String.format("%s:%s", key, secret);
M_log.info(String.format("Social login guest invitation API Request for user Email: %s Firstname: %s Lastname: %s ", nonUmichEmail, nonUmichEmailFirstName, nonUmichEmailLastName));
String encoding = Base64.getEncoder().encodeToString((keySecretStr).getBytes());
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpClient httpclient= HttpClients.custom()
.setDefaultRequestConfig(RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD).build())
.build();
HttpPost httpPost = new HttpPost(fullSocialLoginApiUrl);
httpPost.setHeader("Accept", Utils.APPLICATION_JSON);
httpPost.setHeader("Content-type", Utils.APPLICATION_JSON);
httpPost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encoding);
apiPostBodyStringEntity = socialLoginApiRequestBody(spURL, nonUmichEmail, nonUmichEmailFirstName, nonUmichEmailLastName);
apiPostBodyStringEntity = socialLoginApiRequestBody(spURL, nonUmichEmail);
httpPost.setEntity(apiPostBodyStringEntity);
HttpResponse res = httpclient.execute(httpPost);
if (res == null) {
Expand Down Expand Up @@ -146,16 +151,19 @@ private void socialLoginRestApiCall(HttpServletRequest request,
M_log.info(String.format("Social login account creation Api response took %sms", elapsedTime));
}

private StringEntity socialLoginApiRequestBody(String spURL, String nonUmichEmail, String friendFirstName, String friendLastName) throws UnsupportedEncodingException {
private StringEntity socialLoginApiRequestBody(String spURL, String nonUmichEmail) throws UnsupportedEncodingException {
JSONObject apiPostBody = new JSONObject();
apiPostBody.put(Utils.SOCIAL_LOGIN_SP_ENTITY_ID, spURL);
//Legacy required parameter in cirrusAPI will be deprecated in future so need to be part of the API but can be any value
apiPostBody.put(Utils.SOCIAL_LOGIN_CLIENT_REQUEST_ID, "request001");
apiPostBody.put(Utils.SOCIAL_LOGIN_SERVICE_NAME, "UMICH Invite");
apiPostBody.put(Utils.SOCIAL_LOGIN_EMAIL_ADDRESS, nonUmichEmail);
apiPostBody.put(Utils.SOCIAL_LOGIN_EMAIL_SUBJECT, String.format("UMICH Invitation for %s %s" ,friendFirstName, friendLastName));
apiPostBody.put(Utils.SOCIAL_LOGIN_SPONSOR_EPPN, appExtProperties.getProperty(Utils.SOCIAL_LOGIN_NO_REPLY_EMAIL));
apiPostBody.put(Utils.SOCIAL_LOGIN_SPONSOR_MAIL, appExtProperties.getProperty(Utils.SOCIAL_LOGIN_NO_REPLY_EMAIL));
apiPostBody.put(Utils.SOCIAL_LOGIN_EMAIL_SUBJECT,
appExtProperties.getProperty(Utils.SOCIAL_LOGIN_EMAIL_SUBJECT_PROP, Utils.SOCIAL_LOGIN_EMAIL_DEFAULT_SUBJECT));
apiPostBody.put(Utils.SOCIAL_LOGIN_SPONSOR_EPPN,
appExtProperties.getProperty(Utils.SOCIAL_LOGIN_NO_REPLY_EMAIL, Utils.SOCIAL_LOGIN_DEFAULT_NO_REPLY_EMAIL));
apiPostBody.put(Utils.SOCIAL_LOGIN_SPONSOR_MAIL,
appExtProperties.getProperty(Utils.SOCIAL_LOGIN_NO_REPLY_EMAIL, Utils.SOCIAL_LOGIN_DEFAULT_NO_REPLY_EMAIL));
apiPostBody.put(Utils.SOCIAL_LOGIN_SPONSOR_GIVENNAME, "ITS");
apiPostBody.put(Utils.SOCIAL_LOGIN_SPONSOR_SURNAME, "Service Center");
String apiPostData = apiPostBody.toString();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/edu/umich/ctools/sectionsUtilityTool/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class Utils {
public static final String SOCIAL_LOGIN_SERVICE_NAME = "serviceName";
public static final String SOCIAL_LOGIN_EMAIL_ADDRESS = "emailAddress";
public static final String SOCIAL_LOGIN_EMAIL_SUBJECT = "emailSubject";
public static final String SOCIAL_LOGIN_EMAIL_DEFAULT_SUBJECT = "University of Michigan Canvas Course Invitation";
public static final String SOCIAL_LOGIN_EMAIL_SUBJECT_PROP = "social.login.subjectline";
public static final String SOCIAL_LOGIN_SPONSOR_EPPN = "sponsorEppn";
public static final String SOCIAL_LOGIN_SPONSOR_MAIL = "sponsorMail";
public static final String SOCIAL_LOGIN_SPONSOR_GIVENNAME = "sponsorGivenname";
Expand All @@ -86,6 +88,7 @@ public class Utils {
protected static final String JSON_PARAM_IMPORTED = "imported";
protected static final String SOCIAL_LOGIN_API_SERVICE_PROVIDED_URL = "social.login.service.provider.url";
protected static final String SOCIAL_LOGIN_NO_REPLY_EMAIL = "social.login.no.reply.email";
protected static final String SOCIAL_LOGIN_DEFAULT_NO_REPLY_EMAIL = "[email protected]";
protected static final String SOCIAL_LOGIN_API_URL = "social.login.url";
protected static final String SOCIAL_LOGIN_API_KEY = "social.login.key";
protected static final String SOCIAL_LOGIN_API_SECRET = "social.login.secret";
Expand Down

0 comments on commit 0f303cb

Please sign in to comment.