Skip to content

Commit

Permalink
#2309 Add missing changes for lockout extraData
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jan 22, 2022
1 parent bc7364d commit 44dea68
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 17 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,26 @@ object Conversion {
.withFieldComputed(_._id, _._id.toString)
.withFieldConst(_.organisations, Nil)
.withFieldComputed(_.avatar, user => user.avatar.map(avatar => s"/api/v1/user/${user._id}/avatar/$avatar"))
.withFieldConst(_.extraData, JsObject.empty)
.enableMethodAccessors
.transform
)

implicit val userWithStatsOutput: Renderer.Aux[(RichUser, JsObject), OutputUser] =
Renderer.toJson[(RichUser, JsObject), OutputUser] { userWithExtraData =>
userWithExtraData
._1
.into[OutputUser]
.withFieldComputed(_.permissions, _.permissions.asInstanceOf[Set[String]])
.withFieldComputed(_.hasKey, _.apikey.isDefined)
.withFieldComputed(_._id, _._id.toString)
.withFieldConst(_.organisations, Nil)
.withFieldComputed(_.avatar, user => user.avatar.map(avatar => s"/api/v1/user/${user._id}/avatar/$avatar"))
.withFieldConst(_.extraData, userWithExtraData._2)
.enableMethodAccessors
.transform
}

implicit val userWithOrganisationOutput: Renderer.Aux[(RichUser, Seq[(Organisation with Entity, String)]), OutputUser] =
Renderer.toJson[(RichUser, Seq[(Organisation with Entity, String)]), OutputUser] { userWithOrganisations =>
val (user, organisations) = userWithOrganisations
Expand All @@ -370,6 +386,7 @@ object Conversion {
.withFieldComputed(_.hasKey, _.apikey.isDefined)
.withFieldConst(_.organisations, organisations.map { case (org, role) => OutputOrganisationProfile(org._id.toString, org.name, role) })
.withFieldComputed(_.avatar, user => user.avatar.map(avatar => s"/api/v1/user/${user._id}/avatar/$avatar"))
.withFieldConst(_.extraData, JsObject.empty)
.enableMethodAccessors
.transform
}
Expand Down
11 changes: 9 additions & 2 deletions thehive/app/org/thp/thehive/services/LocalPasswordAuthSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ class LocalPasswordAuthSrv(db: Database, userSrv: UserSrv, localUserSrv: LocalUs
false
}

private def timeElapsed(user: User with Entity): Boolean =
def timeElapsed(user: User with Entity): Boolean =
user.lastFailed.fold(true)(lf => resetAfter.fold(false)(ra => (System.currentTimeMillis - lf.getTime) > ra.toMillis))

private def maxAttemptsReached(user: User with Entity) =
def lockedUntil(user: User with Entity): Option[Date] =
if (maxAttemptsReached(user))
user.lastFailed.map { lf =>
resetAfter.fold(new Date(Long.MaxValue))(ra => new Date(ra.toMillis + lf.getTime))
}
else None

def maxAttemptsReached(user: User with Entity) =
(for {
ma <- maxAttempts
fa <- user.failedAttempts
Expand Down

0 comments on commit 44dea68

Please sign in to comment.