From bea9af6c408142c080da0f614df198b4c74d5b61 Mon Sep 17 00:00:00 2001 From: Aron Engineer Date: Wed, 10 Mar 2021 19:06:18 +0000 Subject: [PATCH] feat: ValidateAuthToken revoked when user is logged out, reason added to response message --- .../core/apps/users/RegisterUserReqMsgHdlr.scala | 2 +- .../core/apps/users/UserLeaveReqMsgHdlr.scala | 11 ++++++++++- .../core/apps/users/ValidateAuthTokenReqMsgHdlr.scala | 9 ++++----- .../bigbluebutton/core/models/RegisteredUsers.scala | 7 +++++++ .../core2/message/senders/MsgBuilder.scala | 4 ++-- .../senders/ValidateAuthTokenRespMsgSender.scala | 4 ++-- .../org/bigbluebutton/common2/msgs/UsersMgs.scala | 3 ++- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/RegisterUserReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/RegisterUserReqMsgHdlr.scala index 66462cf2eb..c319e6fa8d 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/RegisterUserReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/RegisterUserReqMsgHdlr.scala @@ -26,7 +26,7 @@ trait RegisterUserReqMsgHdlr { val regUser = RegisteredUsers.create(msg.body.intUserId, msg.body.extUserId, msg.body.name, msg.body.role, msg.body.authToken, - msg.body.avatarURL, msg.body.guest, msg.body.authed, guestStatus, msg.body.loggedOut) + msg.body.avatarURL, msg.body.guest, msg.body.authed, guestStatus, false) RegisteredUsers.add(liveMeeting.registeredUsers, regUser) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala index d0c0b47379..6be39e1d9d 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/UserLeaveReqMsgHdlr.scala @@ -2,7 +2,7 @@ package org.bigbluebutton.core.apps.users import org.bigbluebutton.common2.msgs.UserLeaveReqMsg import org.bigbluebutton.core.domain.MeetingState2x -import org.bigbluebutton.core.models.Users2x +import org.bigbluebutton.core.models.{ RegisteredUsers, Users2x } import org.bigbluebutton.core.running.{ MeetingActor, OutMsgRouter } trait UserLeaveReqMsgHdlr { @@ -21,6 +21,15 @@ trait UserLeaveReqMsgHdlr { // ralam oct 23, 2018 Users2x.setUserLeftFlag(liveMeeting.users2x, msg.body.userId) } + if (msg.body.loggedOut) { + log.info("Setting user logged out flag. user {} meetingId={}", msg.body.userId, msg.header.meetingId) + + for { + ru <- RegisteredUsers.findWithUserId(msg.body.userId, liveMeeting.registeredUsers) + } yield { + RegisteredUsers.setUserLoggedOutFlag(liveMeeting.registeredUsers, ru) + } + } state case None => state diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ValidateAuthTokenReqMsgHdlr.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ValidateAuthTokenReqMsgHdlr.scala index 5b0373ea5b..904c5ebaa3 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ValidateAuthTokenReqMsgHdlr.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/apps/users/ValidateAuthTokenReqMsgHdlr.scala @@ -22,13 +22,12 @@ trait ValidateAuthTokenReqMsgHdlr extends HandlerHelpers { val regUser = RegisteredUsers.getRegisteredUserWithToken(msg.body.authToken, msg.body.userId, liveMeeting.registeredUsers) - regUser match { case Some(u) => // Check if banned user is rejoining. // Fail validation if ejected user is rejoining. // ralam april 21, 2020 - if (u.guestStatus == GuestStatus.ALLOW && !u.banned) { + if (u.guestStatus == GuestStatus.ALLOW && !u.banned && !u.loggedOut) { userValidated(u, state) } else { if (u.banned) { @@ -78,7 +77,7 @@ trait ValidateAuthTokenReqMsgHdlr extends HandlerHelpers { reasonCode: String, state: MeetingState2x ): MeetingState2x = { - val event = MsgBuilder.buildValidateAuthTokenRespMsg(meetingId, userId, authToken, valid, waitForApproval, 0, 0) + val event = MsgBuilder.buildValidateAuthTokenRespMsg(meetingId, userId, authToken, valid, waitForApproval, 0, 0, Option.apply(reason)) outGW.send(event) // send a system message to force disconnection @@ -89,8 +88,8 @@ trait ValidateAuthTokenReqMsgHdlr extends HandlerHelpers { } def sendValidateAuthTokenRespMsg(meetingId: String, userId: String, authToken: String, - valid: Boolean, waitForApproval: Boolean, registeredOn: Long, authTokenValidatedOn: Long): Unit = { - val event = MsgBuilder.buildValidateAuthTokenRespMsg(meetingId, userId, authToken, valid, waitForApproval, registeredOn, authTokenValidatedOn) + valid: Boolean, waitForApproval: Boolean, registeredOn: Long, authTokenValidatedOn: Long, reason: Option[String] = None): Unit = { + val event = MsgBuilder.buildValidateAuthTokenRespMsg(meetingId, userId, authToken, valid, waitForApproval, registeredOn, authTokenValidatedOn, reason) outGW.send(event) } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/RegisteredUsers.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/RegisteredUsers.scala index bd91ac6568..b2db60e631 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/RegisteredUsers.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/models/RegisteredUsers.scala @@ -139,6 +139,13 @@ object RegisteredUsers { users.save(u) u } + + def setUserLoggedOutFlag(users: RegisteredUsers, user: RegisteredUser): RegisteredUser = { + val u = user.copy(loggedOut = true) + users.save(u) + u + } + } class RegisteredUsers { diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/MsgBuilder.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/MsgBuilder.scala index 82f228180c..e0afa731d2 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/MsgBuilder.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/MsgBuilder.scala @@ -74,11 +74,11 @@ object MsgBuilder { } def buildValidateAuthTokenRespMsg(meetingId: String, userId: String, authToken: String, - valid: Boolean, waitForApproval: Boolean, registeredOn: Long, authTokenValidatedOn: Long): BbbCommonEnvCoreMsg = { + valid: Boolean, waitForApproval: Boolean, registeredOn: Long, authTokenValidatedOn: Long, reason: Option[String]): BbbCommonEnvCoreMsg = { val routing = Routing.addMsgToClientRouting(MessageTypes.DIRECT, meetingId, userId) val envelope = BbbCoreEnvelope(ValidateAuthTokenRespMsg.NAME, routing) val header = BbbClientMsgHeader(ValidateAuthTokenRespMsg.NAME, meetingId, userId) - val body = ValidateAuthTokenRespMsgBody(userId, authToken, valid, waitForApproval, registeredOn, authTokenValidatedOn) + val body = ValidateAuthTokenRespMsgBody(userId, authToken, valid, waitForApproval, registeredOn, authTokenValidatedOn, reason) val event = ValidateAuthTokenRespMsg(header, body) BbbCommonEnvCoreMsg(envelope, event) } diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/ValidateAuthTokenRespMsgSender.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/ValidateAuthTokenRespMsgSender.scala index 5b37686972..2e2fb20761 100755 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/ValidateAuthTokenRespMsgSender.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core2/message/senders/ValidateAuthTokenRespMsgSender.scala @@ -6,11 +6,11 @@ import org.bigbluebutton.core.running.OutMsgRouter object ValidateAuthTokenRespMsgSender { def send(outGW: OutMsgRouter, meetingId: String, userId: String, authToken: String, - valid: Boolean, waitForApproval: Boolean, registeredOn: Long, authTokenValidatedOn: Long): Unit = { + valid: Boolean, waitForApproval: Boolean, registeredOn: Long, authTokenValidatedOn: Long, reason: Option[String]): Unit = { val routing = Routing.addMsgToClientRouting(MessageTypes.DIRECT, meetingId, userId) val envelope = BbbCoreEnvelope(ValidateAuthTokenRespMsg.NAME, routing) val header = BbbClientMsgHeader(ValidateAuthTokenRespMsg.NAME, meetingId, userId) - val body = ValidateAuthTokenRespMsgBody(userId, authToken, valid, waitForApproval, registeredOn, authTokenValidatedOn) + val body = ValidateAuthTokenRespMsgBody(userId, authToken, valid, waitForApproval, registeredOn, authTokenValidatedOn, reason) val event = ValidateAuthTokenRespMsg(header, body) val msgEvent = BbbCommonEnvCoreMsg(envelope, event) outGW.send(msgEvent) diff --git a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMgs.scala b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMgs.scala index db727c4b2d..60d896f81e 100755 --- a/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMgs.scala +++ b/bbb-common-message/src/main/scala/org/bigbluebutton/common2/msgs/UsersMgs.scala @@ -59,7 +59,8 @@ case class ValidateAuthTokenRespMsg( header: BbbClientMsgHeader, body: ValidateAuthTokenRespMsgBody ) extends BbbCoreMsg -case class ValidateAuthTokenRespMsgBody(userId: String, authToken: String, valid: Boolean, waitForApproval: Boolean, registeredOn: Long, authTokenValidatedOn: Long) +case class ValidateAuthTokenRespMsgBody(userId: String, authToken: String, valid: Boolean, waitForApproval: Boolean, + registeredOn: Long, authTokenValidatedOn: Long, reason: Option[String]) object UserLeftMeetingEvtMsg { val NAME = "UserLeftMeetingEvtMsg"