Reduce Dashboard cookie timelife

This commit is contained in:
Gustavo Trott 2021-12-10 17:15:47 -03:00
parent a7e7a87157
commit 63f60f5009
8 changed files with 30 additions and 23 deletions

View File

@ -550,10 +550,10 @@ object MsgBuilder {
BbbCommonEnvCoreMsg(envelope, event)
}
def buildLearningDashboardEvtMsg(meetingId: String, activityJson: String): BbbCommonEnvCoreMsg = {
def buildLearningDashboardEvtMsg(meetingId: String, learningDashboardAccessToken: String, activityJson: String): BbbCommonEnvCoreMsg = {
val routing = collection.immutable.HashMap("sender" -> "bbb-apps-akka")
val envelope = BbbCoreEnvelope(LearningDashboardEvtMsg.NAME, routing)
val body = LearningDashboardEvtMsgBody(activityJson)
val body = LearningDashboardEvtMsgBody(learningDashboardAccessToken, activityJson)
val header = BbbCoreHeaderWithMeetingId(LearningDashboardEvtMsg.NAME, meetingId)
val event = LearningDashboardEvtMsg(header, body)

View File

@ -19,7 +19,6 @@ case class Meeting(
intId: String,
extId: String,
name: String,
learningDashboardAccessToken: String,
users: Map[String, User] = Map(),
polls: Map[String, Poll] = Map(),
screenshares: Vector[Screenshare] = Vector(),
@ -91,8 +90,9 @@ class LearningDashboardActor(
) extends Actor with ActorLogging {
private var meetings: Map[String, Meeting] = Map()
private var meetingsLastJsonHash : Map[String,String] = Map()
private var meetingExcludedUserIds : Map[String,Vector[String]] = Map()
private var meetingAccessTokens: Map[String,String] = Map()
private var meetingsLastJsonHash: Map[String,String] = Map()
private var meetingExcludedUserIds: Map[String,Vector[String]] = Map()
system.scheduler.schedule(10.seconds, 10.seconds, self, SendPeriodicReport)
@ -373,10 +373,10 @@ class LearningDashboardActor(
msg.body.props.meetingProp.intId,
msg.body.props.meetingProp.extId,
msg.body.props.meetingProp.name,
msg.body.props.password.learningDashboardAccessToken,
)
meetings += (newMeeting.intId -> newMeeting)
meetingAccessTokens += (newMeeting.intId -> msg.body.props.password.learningDashboardAccessToken)
log.info(" created for meeting {}.",msg.body.props.meetingProp.intId)
} else {
@ -418,7 +418,9 @@ class LearningDashboardActor(
sendReport(updatedMeeting)
meetings = meetings.-(updatedMeeting.intId)
meetingAccessTokens = meetingAccessTokens.-(updatedMeeting.intId)
meetingExcludedUserIds = meetingExcludedUserIds.-(updatedMeeting.intId)
meetingsLastJsonHash = meetingsLastJsonHash.-(updatedMeeting.intId)
log.info(" removed for meeting {}.",updatedMeeting.intId)
}
}
@ -446,12 +448,16 @@ class LearningDashboardActor(
val activityJsonHash : String = MessageDigest.getInstance("MD5").digest(activityJson.getBytes).mkString
if(!meetingsLastJsonHash.contains(meeting.intId) || meetingsLastJsonHash.get(meeting.intId).getOrElse("") != activityJsonHash) {
val event = MsgBuilder.buildLearningDashboardEvtMsg(meeting.intId, activityJson)
outGW.send(event)
for {
learningDashboardAccessToken <- meetingAccessTokens.get(meeting.intId)
} yield {
val event = MsgBuilder.buildLearningDashboardEvtMsg(meeting.intId, learningDashboardAccessToken, activityJson)
outGW.send(event)
meetingsLastJsonHash += (meeting.intId -> activityJsonHash)
meetingsLastJsonHash += (meeting.intId -> activityJsonHash)
log.info("Activity Report sent for meeting {}",meeting.intId)
log.info("Activity Report sent for meeting {}",meeting.intId)
}
}
}

View File

@ -232,4 +232,4 @@ case class LearningDashboardEvtMsg(
header: BbbCoreHeaderWithMeetingId,
body: LearningDashboardEvtMsgBody
) extends BbbCoreMsg
case class LearningDashboardEvtMsgBody(activityJson: String)
case class LearningDashboardEvtMsgBody(learningDashboardAccessToken: String, activityJson: String)

View File

@ -963,10 +963,9 @@ public class MeetingService implements MessageListener {
}
public void processLearningDashboard(LearningDashboard message) {
//Get all data from Json instead of getMeeting(message.meetingId), to process messages received even after meeting ended
JsonObject activityJsonObject = new Gson().fromJson(message.activityJson, JsonObject.class).getAsJsonObject();
String learningDashboardAccessToken = activityJsonObject.get("learningDashboardAccessToken").getAsString();
Map<String, Object> logData = new HashMap<String, Object>();
logData.put("meetingId", activityJsonObject.get("intId").getAsString());
logData.put("externalMeetingId", activityJsonObject.get("extId").getAsString());
@ -979,7 +978,7 @@ public class MeetingService implements MessageListener {
log.info(" --analytics-- data={}", logStr);
learningDashboardService.writeJsonDataFile(message.meetingId, learningDashboardAccessToken, message.activityJson);
learningDashboardService.writeJsonDataFile(message.meetingId, message.learningDashboardAccessToken, message.activityJson);
}
@Override

View File

@ -3,9 +3,11 @@ package org.bigbluebutton.api.messaging.messages;
public class LearningDashboard implements IMessage {
public final String meetingId;
public final String activityJson;
public final String learningDashboardAccessToken;
public LearningDashboard(String meetingId, String activityJson) {
public LearningDashboard(String meetingId, String learningDashboardAccessToken, String activityJson) {
this.meetingId = meetingId;
this.activityJson = activityJson;
this.learningDashboardAccessToken = learningDashboardAccessToken;
}
}

View File

@ -182,7 +182,7 @@ class OldMeetingMsgHdlrActor(val olgMsgGW: OldMessageReceivedGW)
}
def handleLearningDashboardEvtMsg(msg: LearningDashboardEvtMsg): Unit = {
olgMsgGW.handle(new LearningDashboard(msg.header.meetingId, msg.body.activityJson))
olgMsgGW.handle(new LearningDashboard(msg.header.meetingId, msg.body.learningDashboardAccessToken, msg.body.activityJson))
}
}

View File

@ -48,18 +48,18 @@ class App extends React.Component {
if (typeof params.report !== 'undefined') {
learningDashboardAccessToken = params.report;
} else {
const cookieName = `learningDashboardAccessToken-${params.meeting}`;
const cookieName = `ld-${params.meeting}`;
const cDecoded = decodeURIComponent(document.cookie);
const cArr = cDecoded.split('; ');
cArr.forEach((val) => {
if (val.indexOf(`${cookieName}=`) === 0) learningDashboardAccessToken = val.substring((`${cookieName}=`).length);
});
// Extend AccessToken lifetime by 30d (in each access)
// Extend AccessToken lifetime by 7d (in each access)
if (learningDashboardAccessToken !== '') {
const cookieExpiresDate = new Date();
cookieExpiresDate.setTime(cookieExpiresDate.getTime() + (3600000 * 24 * 30));
document.cookie = `learningDashboardAccessToken-${meetingId}=${learningDashboardAccessToken}; expires=${cookieExpiresDate.toGMTString()}; path=/;SameSite=None;Secure`;
cookieExpiresDate.setTime(cookieExpiresDate.getTime() + (3600000 * 24 * 7));
document.cookie = `ld-${meetingId}=${learningDashboardAccessToken}; expires=${cookieExpiresDate.toGMTString()}; path=/;SameSite=None;Secure`;
}
}

View File

@ -39,9 +39,9 @@ const getLearningDashboardAccessToken = () => ((
const setLearningDashboardCookie = () => {
const learningDashboardAccessToken = getLearningDashboardAccessToken();
if (learningDashboardAccessToken !== null) {
const cookieExpiresDate = new Date();
cookieExpiresDate.setTime(cookieExpiresDate.getTime() + (3600000 * 24 * 30)); // keep cookie 30d
document.cookie = `learningDashboardAccessToken-${Auth.meetingID}=${getLearningDashboardAccessToken()}; expires=${cookieExpiresDate.toGMTString()}; path=/`;
const lifetime = new Date();
lifetime.setTime(lifetime.getTime() + (3600000)); // 1h (extends 7d when open Dashboard)
document.cookie = `ld-${Auth.meetingID}=${getLearningDashboardAccessToken()}; expires=${lifetime.toGMTString()}; path=/`;
return true;
}
return false;