bbb-lti v0.1: Made "consumers" parameter configurable

Signed-off-by: jfederico <jesus@123it.ca>
This commit is contained in:
jfederico 2012-10-16 12:14:16 -04:00
parent 32f89be690
commit 40fec9502c
3 changed files with 40 additions and 17 deletions

View File

@ -17,4 +17,5 @@ beans.bigbluebuttonService.url=${bigbluebuttonURL}
beans.bigbluebuttonService.salt=${bigbluebuttonSalt}
beans.ltiService.ltiEndPoint=${bigbluebuttonLtiEndPoint}
beans.ltiService.consumers=demo:welcome,user1:secret1

View File

@ -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<String, String> getConsumer(params) {
Map<String, String> consumer = new HashMap<String, String>()
consumer.put("key", "demo");
consumer.put("secret", "welcome")
return consumer
}
def retrieveLtiEndpoint() {
String ltiEndPoint = ltiService.ltiEndPoint
log.debug "basicLtiEndPoint [" + ltiEndPoint + "]"
return ltiEndPoint
}
}

View File

@ -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<String, String> consumerMap
private Map<String, String> getConsumer(consumerId) {
Map<String, String> consumer = null
if( this.consumerMap.containsKey(consumerId) ){
consumer = new HashMap<String, String>()
consumer.put("key", consumerId);
consumer.put("secret", this.consumerMap.get(consumerId))
}
return consumer
}
private void initConsumerMap(){
this.consumerMap = new HashMap<String, String>()
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)