2012-10-16 02:36:54 +08:00
|
|
|
/*
|
2012-10-25 04:04:40 +08:00
|
|
|
BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
2012-10-16 02:36:54 +08:00
|
|
|
|
2012-10-25 04:04:40 +08:00
|
|
|
Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
|
2012-10-16 02:36:54 +08:00
|
|
|
|
2012-10-25 04:04:40 +08:00
|
|
|
This program is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU Lesser General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3.0 of the License, or (at your option) any later
|
|
|
|
version.
|
2012-10-16 02:36:54 +08:00
|
|
|
|
2012-10-25 04:04:40 +08:00
|
|
|
BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
2012-10-16 02:36:54 +08:00
|
|
|
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
|
|
|
2012-10-25 04:04:40 +08:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-10-16 23:22:45 +08:00
|
|
|
|
2012-10-11 23:52:41 +08:00
|
|
|
import java.util.ArrayList
|
|
|
|
import java.util.HashMap
|
|
|
|
import java.util.List
|
|
|
|
import java.util.Map
|
|
|
|
import java.util.Properties
|
|
|
|
|
2012-10-13 04:01:27 +08:00
|
|
|
import org.apache.commons.codec.digest.DigestUtils
|
|
|
|
|
2012-10-11 23:52:41 +08:00
|
|
|
import net.oauth.OAuthMessage
|
2012-10-17 06:09:56 +08:00
|
|
|
import net.oauth.signature.OAuthSignatureMethod
|
|
|
|
import net.oauth.signature.HMAC_SHA1
|
|
|
|
import org.bigbluebutton.lti.Parameter
|
2012-10-11 23:52:41 +08:00
|
|
|
|
2012-10-16 23:22:45 +08:00
|
|
|
import BigbluebuttonService
|
|
|
|
import LtiService
|
2012-10-11 23:52:41 +08:00
|
|
|
|
|
|
|
class ToolController {
|
|
|
|
private static final String CONTROLLER_NAME = 'ToolController'
|
|
|
|
private static final String RESP_CODE_SUCCESS = 'SUCCESS'
|
|
|
|
private static final String RESP_CODE_FAILED = 'FAILED'
|
2013-01-26 04:10:27 +08:00
|
|
|
private static final String REQUEST_METHOD = "request_method";
|
|
|
|
|
2012-10-11 23:52:41 +08:00
|
|
|
LtiService ltiService
|
2012-10-13 04:01:27 +08:00
|
|
|
BigbluebuttonService bigbluebuttonService
|
|
|
|
|
2012-10-11 23:52:41 +08:00
|
|
|
def index = {
|
2012-10-17 00:14:16 +08:00
|
|
|
if( ltiService.consumerMap == null) ltiService.initConsumerMap()
|
2013-01-29 04:53:27 +08:00
|
|
|
log.debug CONTROLLER_NAME + "#index"
|
2013-04-20 05:52:46 +08:00
|
|
|
|
|
|
|
setLocalization(params)
|
2013-01-26 04:10:27 +08:00
|
|
|
|
|
|
|
params.put(REQUEST_METHOD, request.getMethod().toUpperCase())
|
2013-01-29 04:53:27 +08:00
|
|
|
log.debug "params: " + params
|
|
|
|
|
|
|
|
Map<String, String> result = new HashMap<String, String>()
|
|
|
|
ArrayList<String> missingParams = new ArrayList<String>()
|
|
|
|
log.debug "Checking for required parameters"
|
|
|
|
if (hasAllRequiredParams(params, missingParams)) {
|
|
|
|
def sanitizedParams = sanitizePrametersForBaseString(params)
|
|
|
|
def consumer = ltiService.getConsumer(params.get(Parameter.CONSUMER_ID))
|
|
|
|
if (consumer != null) {
|
|
|
|
log.debug "Found consumer with key " + consumer.get("key") //+ " and sharedSecret " + consumer.get("secret")
|
|
|
|
if (checkValidSignature(params.get(REQUEST_METHOD), ltiService.endPoint, consumer.get("secret"), sanitizedParams, params.get(Parameter.OAUTH_SIGNATURE))) {
|
|
|
|
log.debug "The message has a valid signature."
|
|
|
|
|
|
|
|
if( !"extended".equals(ltiService.mode) ) {
|
|
|
|
log.debug "LTI service running in simple mode."
|
|
|
|
result = doJoinMeeting(params)
|
|
|
|
} else {
|
|
|
|
log.debug "LTI service running in extended mode."
|
2013-06-08 05:45:47 +08:00
|
|
|
if ( !Boolean.parseBoolean(params.get(Parameter.CUSTOM_RECORD)) ) {
|
2013-04-20 05:52:46 +08:00
|
|
|
log.debug "No bbb_record parameter was sent; immediately redirecting to BBB session!"
|
|
|
|
result = doJoinMeeting(params)
|
|
|
|
}
|
2013-01-29 04:53:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
result.put("resultMessageKey", "InvalidSignature")
|
|
|
|
result.put("resultMessage", "Invalid signature (" + params.get(Parameter.OAUTH_SIGNATURE) + ").")
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
result.put("resultMessageKey", "ConsumerNotFound")
|
|
|
|
result.put("resultMessage", "Consumer with id = " + params.get(Parameter.CONSUMER_ID) + " was not found.")
|
|
|
|
}
|
|
|
|
|
2013-01-26 04:10:27 +08:00
|
|
|
} else {
|
2013-01-29 04:53:27 +08:00
|
|
|
String missingStr = ""
|
|
|
|
for(String str:missingParams) {
|
|
|
|
missingStr += str + ", ";
|
|
|
|
}
|
|
|
|
result.put("resultMessageKey", "MissingRequiredParameter")
|
|
|
|
result.put("resultMessage", "Missing parameters [$missingStr]")
|
|
|
|
}
|
2012-10-17 06:09:56 +08:00
|
|
|
|
2013-01-29 04:53:27 +08:00
|
|
|
|
|
|
|
if( result != null && result.containsKey("resultMessageKey") ) {
|
2013-01-26 04:10:27 +08:00
|
|
|
log.debug "Error [resultMessageKey:'" + result.get("resultMessageKey") + "', resultMessage:'" + result.get("resultMessage") + "']"
|
|
|
|
render(view: "error", model: ['resultMessageKey': result.get("resultMessageKey"), 'resultMessage': result.get("resultMessage")])
|
|
|
|
|
|
|
|
} else {
|
|
|
|
session["params"] = params
|
2013-01-26 06:59:11 +08:00
|
|
|
List<Object> recordings = bigbluebuttonService.getRecordings(params)
|
2013-04-20 05:52:46 +08:00
|
|
|
for(Map<String, Object> recording: recordings){
|
|
|
|
/// Calculate duration
|
|
|
|
long endTime = Long.parseLong((String)recording.get("endTime"))
|
|
|
|
endTime -= (endTime % 1000)
|
|
|
|
long startTime = Long.parseLong((String)recording.get("startTime"))
|
|
|
|
startTime -= (startTime % 1000)
|
|
|
|
int duration = (endTime - startTime) / 60000
|
|
|
|
/// Add duration
|
|
|
|
recording.put("duration", duration )
|
|
|
|
}
|
2013-01-29 04:53:27 +08:00
|
|
|
|
2013-04-20 05:52:46 +08:00
|
|
|
render(view: "index", model: ['params': params, 'recordingList': recordings, 'ismoderator': bigbluebuttonService.isModerator(params)])
|
2013-01-29 04:53:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 04:10:27 +08:00
|
|
|
def join = {
|
2013-01-29 04:53:27 +08:00
|
|
|
if( ltiService.consumerMap == null) ltiService.initConsumerMap()
|
2013-01-26 04:10:27 +08:00
|
|
|
log.debug CONTROLLER_NAME + "#join"
|
2013-01-29 04:53:27 +08:00
|
|
|
Map<String, String> result
|
|
|
|
|
2013-01-26 04:10:27 +08:00
|
|
|
def sessionParams = session["params"]
|
|
|
|
|
2013-01-29 04:53:27 +08:00
|
|
|
if( sessionParams != null ) {
|
|
|
|
log.debug "params: " + params
|
|
|
|
log.debug "sessionParams: " + sessionParams
|
|
|
|
result = doJoinMeeting(sessionParams)
|
|
|
|
} else {
|
|
|
|
result = new HashMap<String, String>()
|
|
|
|
result.put("resultMessageKey", "InvalidSession")
|
|
|
|
result.put("resultMessage", "Invalid session. User can not execute this action.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result.containsKey("resultMessageKey")) {
|
|
|
|
log.debug "Error [resultMessageKey:'" + result.get("resultMessageKey") + "', resultMessage:'" + result.get("resultMessage") + "']"
|
|
|
|
render(view: "error", model: ['resultMessageKey': result.get("resultMessageKey"), 'resultMessage': result.get("resultMessage")])
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
def publish = {
|
|
|
|
log.debug CONTROLLER_NAME + "#publish"
|
|
|
|
Map<String, String> result
|
|
|
|
|
|
|
|
def sessionParams = session["params"]
|
|
|
|
|
2013-01-29 05:58:55 +08:00
|
|
|
if( sessionParams == null ) {
|
|
|
|
result = new HashMap<String, String>()
|
|
|
|
result.put("resultMessageKey", "InvalidSession")
|
|
|
|
result.put("resultMessage", "Invalid session. User can not execute this action.")
|
|
|
|
} else if ( !bigbluebuttonService.isModerator(sessionParams) ) {
|
|
|
|
result = new HashMap<String, String>()
|
|
|
|
result.put("resultMessageKey", "NotAllowed")
|
|
|
|
result.put("resultMessage", "User not allowed to execute this action.")
|
|
|
|
} else {
|
2013-01-29 04:53:27 +08:00
|
|
|
log.debug "params: " + params
|
|
|
|
log.debug "sessionParams: " + sessionParams
|
|
|
|
|
|
|
|
//Execute the publish command
|
|
|
|
result = bigbluebuttonService.doPublishRecordings(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result.containsKey("resultMessageKey")) {
|
|
|
|
log.debug "Error [resultMessageKey:'" + result.get("resultMessageKey") + "', resultMessage:'" + result.get("resultMessage") + "']"
|
|
|
|
render(view: "error", model: ['resultMessageKey': result.get("resultMessageKey"), 'resultMessage': result.get("resultMessage")])
|
|
|
|
} else {
|
2013-06-09 05:28:06 +08:00
|
|
|
List<Object> recordings = bigbluebuttonService.getRecordings(sessionParams)
|
|
|
|
for(Map<String, Object> recording: recordings){
|
|
|
|
/// Calculate duration
|
|
|
|
long endTime = Long.parseLong((String)recording.get("endTime"))
|
|
|
|
endTime -= (endTime % 1000)
|
|
|
|
long startTime = Long.parseLong((String)recording.get("startTime"))
|
|
|
|
startTime -= (startTime % 1000)
|
|
|
|
int duration = (endTime - startTime) / 60000
|
|
|
|
/// Add duration
|
|
|
|
recording.put("duration", duration )
|
|
|
|
}
|
|
|
|
|
|
|
|
render(view: "index", model: ['params': sessionParams, 'recordingList': recordings, 'ismoderator': bigbluebuttonService.isModerator(sessionParams)])
|
|
|
|
|
2013-01-29 04:53:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-01-26 04:10:27 +08:00
|
|
|
|
2013-01-29 04:53:27 +08:00
|
|
|
def delete = {
|
|
|
|
log.debug CONTROLLER_NAME + "#delete"
|
|
|
|
Map<String, String> result
|
|
|
|
|
|
|
|
def sessionParams = session["params"]
|
|
|
|
|
2013-01-29 05:58:55 +08:00
|
|
|
if( sessionParams == null ) {
|
|
|
|
result = new HashMap<String, String>()
|
|
|
|
result.put("resultMessageKey", "InvalidSession")
|
|
|
|
result.put("resultMessage", "Invalid session. User can not execute this action.")
|
|
|
|
} else if ( !bigbluebuttonService.isModerator(sessionParams) ) {
|
|
|
|
result = new HashMap<String, String>()
|
|
|
|
result.put("resultMessageKey", "NotAllowed")
|
|
|
|
result.put("resultMessage", "User not allowed to execute this action.")
|
|
|
|
} else {
|
2013-01-29 04:53:27 +08:00
|
|
|
log.debug "params: " + params
|
|
|
|
log.debug "sessionParams: " + sessionParams
|
|
|
|
|
|
|
|
//Execute the delete command
|
|
|
|
result = bigbluebuttonService.doDeleteRecordings(params)
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result.containsKey("resultMessageKey")) {
|
|
|
|
log.debug "Error [resultMessageKey:'" + result.get("resultMessageKey") + "', resultMessage:'" + result.get("resultMessage") + "']"
|
|
|
|
render(view: "error", model: ['resultMessageKey': result.get("resultMessageKey"), 'resultMessage': result.get("resultMessage")])
|
|
|
|
} else {
|
2013-06-09 05:28:06 +08:00
|
|
|
List<Object> recordings = bigbluebuttonService.getRecordings(sessionParams)
|
|
|
|
for(Map<String, Object> recording: recordings){
|
|
|
|
/// Calculate duration
|
|
|
|
long endTime = Long.parseLong((String)recording.get("endTime"))
|
|
|
|
endTime -= (endTime % 1000)
|
|
|
|
long startTime = Long.parseLong((String)recording.get("startTime"))
|
|
|
|
startTime -= (startTime % 1000)
|
|
|
|
int duration = (endTime - startTime) / 60000
|
|
|
|
/// Add duration
|
|
|
|
recording.put("duration", duration )
|
|
|
|
}
|
|
|
|
|
|
|
|
render(view: "index", model: ['params': sessionParams, 'recordingList': recordings, 'ismoderator': bigbluebuttonService.isModerator(sessionParams)])
|
2013-01-29 04:53:27 +08:00
|
|
|
}
|
2013-01-26 04:10:27 +08:00
|
|
|
|
|
|
|
}
|
2013-04-20 05:52:46 +08:00
|
|
|
|
|
|
|
private void setLocalization(params){
|
|
|
|
|
2013-01-29 04:53:27 +08:00
|
|
|
String locale = params.get(Parameter.LAUNCH_LOCALE)
|
|
|
|
locale = (locale == null || locale.equals("")?"en":locale)
|
|
|
|
log.debug "Locale code =" + locale
|
|
|
|
String[] localeCodes = locale.split("_")
|
|
|
|
//Localize the default welcome message
|
|
|
|
if( localeCodes.length > 1 )
|
|
|
|
session['org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'] = new Locale(localeCodes[0], localeCodes[1])
|
|
|
|
else
|
|
|
|
session['org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'] = new Locale(localeCodes[0])
|
2013-01-26 04:10:27 +08:00
|
|
|
|
2013-01-29 04:53:27 +08:00
|
|
|
log.debug "Locale has been set to " + locale
|
2013-04-20 05:52:46 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private Object doJoinMeeting(params) {
|
|
|
|
Map<String, String> result = new HashMap<String, String>()
|
|
|
|
|
|
|
|
setLocalization(params)
|
2013-01-29 04:53:27 +08:00
|
|
|
String welcome = message(code: "bigbluebutton.welcome", args: ["\"{0}\"", "\"{1}\""])
|
|
|
|
log.debug "Localized default welcome message: [" + welcome + "]"
|
2013-03-15 00:42:53 +08:00
|
|
|
|
|
|
|
// Check for [custom_]welcome parameter being passed from the LTI
|
2013-06-08 05:45:47 +08:00
|
|
|
if (params.get(Parameter.CUSTOM_WELCOME) != null) {
|
|
|
|
welcome = params.get(Parameter.CUSTOM_WELCOME)
|
2013-03-15 00:42:53 +08:00
|
|
|
log.debug "Overriding default welcome message with: [" + welcome + "]"
|
|
|
|
}
|
2013-01-29 04:53:27 +08:00
|
|
|
|
|
|
|
String destinationURL = bigbluebuttonService.getJoinURL(params, welcome, ltiService.mode)
|
|
|
|
log.debug "redirecting to " + destinationURL
|
2013-01-26 04:10:27 +08:00
|
|
|
|
2013-01-29 04:53:27 +08:00
|
|
|
if( destinationURL != null ) {
|
|
|
|
redirect(url:destinationURL)
|
2012-10-11 23:52:41 +08:00
|
|
|
} else {
|
2013-01-29 04:53:27 +08:00
|
|
|
result.put("resultMessageKey", "BigBlueButtonServerError")
|
|
|
|
result.put("resultMessage", "The join could not be completed")
|
2013-01-25 04:52:06 +08:00
|
|
|
}
|
2012-10-13 04:01:27 +08:00
|
|
|
|
2013-01-26 04:10:27 +08:00
|
|
|
return result
|
2012-10-11 23:52:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assemble all parameters passed that is required to sign the request.
|
|
|
|
* @param the HTTP request parameters
|
|
|
|
* @return the key:val pairs needed for Basic LTI
|
|
|
|
*/
|
2012-10-16 23:43:20 +08:00
|
|
|
private Properties sanitizePrametersForBaseString(Object params) {
|
2012-10-11 23:52:41 +08:00
|
|
|
|
|
|
|
Properties reqProp = new Properties();
|
|
|
|
for (String key : ((Map<String, String>)params).keySet()) {
|
|
|
|
if (key == "action" || key == "controller") {
|
|
|
|
// Ignore as these are the grails controller and action tied to this request.
|
|
|
|
continue
|
|
|
|
} else if (key == "oauth_signature") {
|
|
|
|
// We don't need this as part of the base string
|
|
|
|
continue
|
2013-01-26 04:10:27 +08:00
|
|
|
} else if (key == "request_method") {
|
|
|
|
// As this is was added by the controller, we don't want it as part of the base string
|
|
|
|
continue
|
2012-10-11 23:52:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
reqProp.setProperty(key, ((Map<String, String>)params).get(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
return reqProp
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if all required parameters have been passed in the request.
|
|
|
|
* @param params - the HTTP request parameters
|
|
|
|
* @param missingParams - a list of missing parameters
|
|
|
|
* @return - true if all required parameters have been passed in
|
|
|
|
*/
|
2012-10-16 23:43:20 +08:00
|
|
|
private boolean hasAllRequiredParams(Object params, Object missingParams) {
|
2012-10-11 23:52:41 +08:00
|
|
|
boolean hasAllParams = true
|
2012-10-17 06:09:56 +08:00
|
|
|
if (! ((Map<String, String>)params).containsKey(Parameter.CONSUMER_ID)) {
|
|
|
|
((ArrayList<String>)missingParams).add(Parameter.CONSUMER_ID);
|
2012-10-11 23:52:41 +08:00
|
|
|
hasAllParams = false;
|
|
|
|
}
|
|
|
|
|
2012-10-17 06:09:56 +08:00
|
|
|
if (! ((Map<String, String>)params).containsKey(Parameter.OAUTH_SIGNATURE)) {
|
|
|
|
((ArrayList<String>)missingParams).add(Parameter.OAUTH_SIGNATURE);
|
2012-10-11 23:52:41 +08:00
|
|
|
hasAllParams = false;
|
|
|
|
}
|
|
|
|
|
2013-01-24 06:46:31 +08:00
|
|
|
if (! ((Map<String, String>)params).containsKey(Parameter.RESOURCE_LINK_ID)) {
|
|
|
|
((ArrayList<String>)missingParams).add(Parameter.RESOURCE_LINK_ID);
|
|
|
|
hasAllParams = false;
|
|
|
|
}
|
|
|
|
|
2012-10-11 23:52:41 +08:00
|
|
|
return hasAllParams
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the passed signature is valid.
|
|
|
|
* @param method - POST or GET method used to make the request
|
|
|
|
* @param URL - The target URL for the Basic LTI tool
|
|
|
|
* @param conSecret - The consumer secret key
|
|
|
|
* @param postProp - the parameters passed in from the tool
|
|
|
|
* @param signature - the passed in signature calculated from the client
|
|
|
|
* @return - TRUE if the signatures matches the calculated signature
|
|
|
|
*/
|
2012-10-16 23:43:20 +08:00
|
|
|
private boolean checkValidSignature(String method, String URL, String conSecret, Object postProp, String signature) {
|
2012-10-11 23:52:41 +08:00
|
|
|
OAuthMessage oam = new OAuthMessage(method, URL, ((Properties)postProp).entrySet());
|
|
|
|
HMAC_SHA1 hmac = new HMAC_SHA1();
|
|
|
|
hmac.setConsumerSecret(conSecret);
|
|
|
|
|
2012-10-17 06:09:56 +08:00
|
|
|
log.debug("Base Message String = [ " + hmac.getBaseString(oam) + " ]\n");
|
2012-10-11 23:52:41 +08:00
|
|
|
String calculatedSignature = hmac.getSignature(hmac.getBaseString(oam))
|
2012-10-17 06:09:56 +08:00
|
|
|
log.debug("Calculated: " + calculatedSignature + " Received: " + signature);
|
2012-10-11 23:52:41 +08:00
|
|
|
return calculatedSignature.equals(signature)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|