From 21d874b9723d6a36ef57398d9f3406afc755485f Mon Sep 17 00:00:00 2001
From: Jacob Laboissonniere <jacob.laboissonniere@carleton.ca>
Date: Tue, 19 Feb 2019 11:02:23 -0500
Subject: [PATCH] In the bbb-lti applicaation, add a way to configure the
 parameters used for generating the meetingID (#6714)

* Can now configure parameters used to generate meeting_id

* Add back deleted config stuff

* Fix documentation typo

* Fix bad indentation

* Change function name
---
 bbb-lti/grails-app/conf/lti-config.properties |  7 ++++-
 .../bigbluebutton/BigbluebuttonService.groovy | 31 ++++++++++++++++---
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/bbb-lti/grails-app/conf/lti-config.properties b/bbb-lti/grails-app/conf/lti-config.properties
index 7653c5d16a..d4f937b815 100644
--- a/bbb-lti/grails-app/conf/lti-config.properties
+++ b/bbb-lti/grails-app/conf/lti-config.properties
@@ -49,11 +49,16 @@ ltiAllRecordedByDefault=false
 ltiCanvasPlacements=
 ltiCanvasPlacementName=BigBlueButton
 
+# Parameters to generate a unique meeting ID from
+# By default, resource_link_id and oauth_consumer_key are used, but certain LMS don't provide unique resource_link_ids
+# Specify parameters separated by commas. Can leave blank to use default.
+meetingIdParams=resource_link_id,oauth_consumer_key
+
 #----------------------------------------------------
 # Inject configuration values into BigbluebuttonSrvice beans
 beans.bigbluebuttonService.url=${bigbluebuttonURL}
 beans.bigbluebuttonService.salt=${bigbluebuttonSalt}
-
+beans.bigbluebuttonService.idParams=${meetingIdParams}
 #----------------------------------------------------
 # Inject configuration values into LtiSrvice beans
 beans.ltiService.endPoint=${ltiEndPoint}
diff --git a/bbb-lti/grails-app/services/org/bigbluebutton/BigbluebuttonService.groovy b/bbb-lti/grails-app/services/org/bigbluebutton/BigbluebuttonService.groovy
index 17714737b5..ffa8649cb4 100644
--- a/bbb-lti/grails-app/services/org/bigbluebutton/BigbluebuttonService.groovy
+++ b/bbb-lti/grails-app/services/org/bigbluebutton/BigbluebuttonService.groovy
@@ -56,7 +56,8 @@ class BigbluebuttonService {
 
     def url = "http://test-install.blindsidenetworks.com/bigbluebutton"
     def salt = "8cd8ef52e8e101574e400365b55e11a6"
-
+    def idParams = "resource_link_id,oauth_consumer_key"
+	
     Proxy bbbProxy
     DocumentBuilderFactory docBuilderFactory
     DocumentBuilder docBuilder
@@ -81,8 +82,9 @@ class BigbluebuttonService {
         if (!salt.equals(bbbProxy.salt) && !salt.equals("")) {
             bbbProxy.setSalt(salt)
         }
+		
         String meetingName = getValidatedMeetingName(params.get(Parameter.RESOURCE_LINK_TITLE))
-        String meetingID = getValidatedMeetingId(params.get(Parameter.RESOURCE_LINK_ID), params.get(Parameter.CONSUMER_ID))
+        String meetingID = getValidatedMeetingId(getParamsForMeetingId(params))
         String attendeePW = DigestUtils.shaHex("ap" + params.get(Parameter.RESOURCE_LINK_ID) + params.get(Parameter.CONSUMER_ID))
         String moderatorPW = DigestUtils.shaHex("mp" + params.get(Parameter.RESOURCE_LINK_ID) + params.get(Parameter.CONSUMER_ID))
         String logoutURL = getValidatedLogoutURL(params.get(Parameter.LAUNCH_RETURN_URL))
@@ -133,7 +135,7 @@ class BigbluebuttonService {
         if (!salt.equals(bbbProxy.salt) && !salt.equals("")) {
             bbbProxy.setSalt(salt)
         }
-        String meetingID = getValidatedMeetingId(params.get(Parameter.RESOURCE_LINK_ID), params.get(Parameter.CONSUMER_ID))
+        String meetingID = getValidatedMeetingId(getParamsForMeetingId(params))
         String recordingsURL = bbbProxy.getGetRecordingsURL(meetingID)
         Map<String, Object> responseAPICall = doAPICall(recordingsURL)
         if (responseAPICall == null) {
@@ -204,8 +206,8 @@ class BigbluebuttonService {
         return (meetingName == null || meetingName == "")? "Meeting": meetingName
     }
 
-    private String getValidatedMeetingId(String resourceId, String consumerId){
-        return DigestUtils.shaHex(resourceId + consumerId)
+    private String getValidatedMeetingId(String params){	
+        return DigestUtils.shaHex(params)
     }
 
     private String getValidatedLogoutURL(String logoutURL){
@@ -370,4 +372,23 @@ class BigbluebuttonService {
         }
         return list;
     }
+	
+    /**
+     * Get the value of all params from idParams (specified in lti-config)
+     * If none are specified, fallback to using resource_link_id and oauth_consumer_key
+     */
+    private String getParamsForMeetingId(params) {
+	String[] paramArray = idParams.split(",");
+	String result = "";
+	for(String s : paramArray) {
+	    if(params.get(s) != null) {
+    	    	result += params.get(s);
+	    }
+	}
+	// If we can't get anything from config, fallback to old way
+	if(result.equals("")) {
+	    result = params.get(Parameter.RESOURCE_LINK_ID) + params.get(Parameter.CONSUMER_ID);
+	}
+	return result;
+    }
 }
-- 
GitLab