2012-10-25 04:04:40 +08:00
|
|
|
/*
|
|
|
|
BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
|
2012-10-16 23:22:45 +08:00
|
|
|
|
2012-10-25 04:04:40 +08:00
|
|
|
Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
|
2012-10-17 01:46:29 +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-17 01:46:29 +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
|
|
|
|
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
2012-10-17 01:46:29 +08:00
|
|
|
|
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-17 01:46:29 +08:00
|
|
|
*/
|
2012-10-25 04:04:40 +08:00
|
|
|
|
2012-10-17 00:14:16 +08:00
|
|
|
import java.util.Map;
|
|
|
|
|
2012-10-11 23:52:41 +08:00
|
|
|
import javax.crypto.spec.SecretKeySpec
|
|
|
|
import javax.crypto.Mac
|
|
|
|
import org.apache.commons.codec.binary.Base64
|
|
|
|
|
|
|
|
class LtiService {
|
|
|
|
|
2012-10-16 02:36:54 +08:00
|
|
|
boolean transactional = false
|
2012-10-16 23:43:20 +08:00
|
|
|
|
2013-07-19 04:48:48 +08:00
|
|
|
def endPoint = "http://localhost/lti/tool"
|
2013-07-19 03:16:21 +08:00
|
|
|
|
2012-10-17 00:14:16 +08:00
|
|
|
def consumers = "demo:welcome"
|
2013-01-24 06:46:31 +08:00
|
|
|
def mode = "simple"
|
2012-10-17 00:14:16 +08:00
|
|
|
Map<String, String> consumerMap
|
|
|
|
|
2013-07-19 04:48:48 +08:00
|
|
|
def retrieveIconEndpoint() {
|
|
|
|
return endPoint.replaceFirst("tool", "images/icon.ico")
|
2013-07-19 03:16:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
def retrieveBasicLtiEndpoint() {
|
2013-07-19 04:48:48 +08:00
|
|
|
return endPoint
|
2013-07-19 03:16:21 +08:00
|
|
|
}
|
|
|
|
|
2012-10-17 00:14:16 +08:00
|
|
|
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
|
|
|
|
}
|
2012-10-11 23:52:41 +08:00
|
|
|
|
2012-10-17 00:14:16 +08:00
|
|
|
private void initConsumerMap(){
|
|
|
|
this.consumerMap = new HashMap<String, String>()
|
|
|
|
String[] consumers = this.consumers.split(",")
|
2013-05-01 04:28:49 +08:00
|
|
|
//for( int i=0; i < consumers.length; i++){
|
|
|
|
if ( consumers.length > 0 ){
|
|
|
|
int i = 0;
|
2012-10-17 00:14:16 +08:00
|
|
|
String[] consumer = consumers[i].split(":")
|
|
|
|
if( consumer.length == 2 ){
|
|
|
|
this.consumerMap.put(consumer[0], consumer[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-11 23:52:41 +08:00
|
|
|
public String sign(String sharedSecret, String data) throws Exception
|
|
|
|
{
|
|
|
|
Mac mac = setKey(sharedSecret)
|
|
|
|
|
|
|
|
// Signed String must be BASE64 encoded.
|
|
|
|
byte[] signBytes = mac.doFinal(data.getBytes("UTF8"));
|
|
|
|
String signature = encodeBase64(signBytes);
|
|
|
|
return signature;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Mac setKey(String sharedSecret) throws Exception
|
|
|
|
{
|
|
|
|
Mac mac = Mac.getInstance("HmacSHA1");
|
|
|
|
byte[] keyBytes = sharedSecret.getBytes("UTF8");
|
|
|
|
SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
|
|
|
|
mac.init(signingKey);
|
|
|
|
return mac
|
|
|
|
}
|
|
|
|
|
|
|
|
private String encodeBase64(byte[] signBytes) {
|
|
|
|
return Base64.encodeBase64URLSafeString(signBytes)
|
|
|
|
}
|
|
|
|
}
|