Skip to content

Commit

Permalink
- store single use auth keys in redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ritzalam committed Jun 6, 2019
1 parent b3de5ae commit 7659e7f
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

package org.bigbluebutton.common2.redis;

import java.util.HashMap;
import java.util.Map;

import com.sun.org.apache.xpath.internal.operations.Bool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,6 +31,7 @@
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import org.apache.commons.codec.digest.DigestUtils;

public class RedisStorageService extends RedisAwareCommunicator {

Expand Down Expand Up @@ -56,6 +59,37 @@ public void stop() {
log.info("RedisStorageService Stopped");
}

public String generateSingleUseCaptionToken(String recordId, String caption, Long expirySeconds) {
Map<String, String> data = new HashMap<String, String>();
data.put("recordId", recordId);
data.put("caption", caption);

String token = DigestUtils.sha1Hex(recordId + caption + System.currentTimeMillis());
String key = "captions:" + token + ":singleusetoken";
RedisCommands<String, String> commands = connection.sync();
commands.multi();
commands.hmset(key, data);
commands.expire(key, expirySeconds);
commands.exec();

return token;
}

public Boolean validateSingleUseCaptionToken(String token, String recordId, String caption) {
String key = "captions:" + token + ":singleusetoken";
RedisCommands<String, String> commands = connection.sync();
Boolean keyExist = commands.exists(key) == 1;
if (keyExist) {
Map <String, String> data = commands.hgetall(key);
if (data.get("recordId").equals(recordId) && data.get("caption").equals(caption)) {
commands.del(key);
return true;
}
}

return false;
}

public void recordMeetingInfo(String meetingId, Map<String, String> info) {
recordMeeting(Keys.MEETING_INFO + meetingId, info);
}
Expand Down

0 comments on commit 7659e7f

Please sign in to comment.