diff --git a/bbb-lti/grails-app/conf/lti.properties b/bbb-lti/grails-app/conf/lti.properties index 3fcce5f571..23454c1f9f 100644 --- a/bbb-lti/grails-app/conf/lti.properties +++ b/bbb-lti/grails-app/conf/lti.properties @@ -17,4 +17,5 @@ beans.bigbluebuttonService.url=${bigbluebuttonURL} beans.bigbluebuttonService.salt=${bigbluebuttonSalt} beans.ltiService.ltiEndPoint=${bigbluebuttonLtiEndPoint} +beans.ltiService.consumers=demo:welcome,user1:secret1 diff --git a/bbb-lti/grails-app/controllers/ToolController.groovy b/bbb-lti/grails-app/controllers/ToolController.groovy index 61a2cf42e1..b4e5f0599b 100644 --- a/bbb-lti/grails-app/controllers/ToolController.groovy +++ b/bbb-lti/grails-app/controllers/ToolController.groovy @@ -63,7 +63,8 @@ class ToolController { BigbluebuttonService bigbluebuttonService def index = { - log.debug CONTROLLER_NAME + "#index" + if( ltiService.consumerMap == null) ltiService.initConsumerMap() + log.debug CONTROLLER_NAME + "#index" + ltiService.consumerMap def resultMessageKey = "init" def resultMessage = "init" @@ -74,7 +75,7 @@ class ToolController { if (hasAllRequiredParams(params, missingParams)) { def sanitizedParams = sanitizePrametersForBaseString(params) - consumer = getConsumer(params) + consumer = ltiService.getConsumer(params.get(CONSUMER_ID)) if (consumer != null) { log.debug "Found consumer with key " + consumer.get("key") if (checkValidSignature(request.getMethod().toUpperCase(), retrieveLtiEndpoint(), consumer.get("secret"), sanitizedParams, params.get(OAUTH_SIGNATURE))) { @@ -152,6 +153,12 @@ class ToolController { } + def retrieveLtiEndpoint() { + String ltiEndPoint = ltiService.ltiEndPoint + log.debug "basicLtiEndPoint [" + ltiEndPoint + "]" + return ltiEndPoint + } + def test = { log.debug CONTROLLER_NAME + "#index" @@ -266,19 +273,4 @@ class ToolController { return calculatedSignature.equals(signature) } - private Map getConsumer(params) { - Map consumer = new HashMap() - - consumer.put("key", "demo"); - consumer.put("secret", "welcome") - - return consumer - } - - def retrieveLtiEndpoint() { - String ltiEndPoint = ltiService.ltiEndPoint - log.debug "basicLtiEndPoint [" + ltiEndPoint + "]" - return ltiEndPoint - } - } diff --git a/bbb-lti/grails-app/services/LtiService.groovy b/bbb-lti/grails-app/services/LtiService.groovy index dd51410054..9936d05082 100644 --- a/bbb-lti/grails-app/services/LtiService.groovy +++ b/bbb-lti/grails-app/services/LtiService.groovy @@ -1,4 +1,6 @@ +import java.util.Map; + import javax.crypto.spec.SecretKeySpec import javax.crypto.Mac import org.apache.commons.codec.binary.Base64 @@ -8,7 +10,35 @@ class LtiService { boolean transactional = false def ltiEndPoint = "http://192.168.0.153/lti/tool.xml" + def consumers = "demo:welcome" + Map consumerMap + + + private Map getConsumer(consumerId) { + Map consumer = null + + if( this.consumerMap.containsKey(consumerId) ){ + consumer = new HashMap() + consumer.put("key", consumerId); + consumer.put("secret", this.consumerMap.get(consumerId)) + } + + return consumer + } + private void initConsumerMap(){ + this.consumerMap = new HashMap() + String[] consumers = this.consumers.split(",") + for( int i=0; i < consumers.length; i++){ + String[] consumer = consumers[i].split(":") + if( consumer.length == 2 ){ + this.consumerMap.put(consumer[0], consumer[1]) + } + } + + } + + public String sign(String sharedSecret, String data) throws Exception { Mac mac = setKey(sharedSecret)