-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2309 Add extraData related to user lockout
- Loading branch information
Showing
3 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
thehive/app/org/thp/thehive/controllers/v1/UserRenderer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.thp.thehive.controllers.v1 | ||
|
||
import org.thp.scalligraph.auth.AuthContext | ||
import org.thp.scalligraph.traversal.TraversalOps._ | ||
import org.thp.scalligraph.traversal.{Converter, Traversal} | ||
import org.thp.thehive.models.{Permissions, User} | ||
import org.thp.thehive.services.LocalPasswordAuthSrv | ||
import org.thp.thehive.services.OrganisationOps._ | ||
import org.thp.thehive.services.UserOps._ | ||
import play.api.libs.json._ | ||
|
||
import java.util.{Map => JMap} | ||
|
||
trait UserRenderer extends BaseRenderer[User] { | ||
|
||
def lockout( | ||
localPasswordAuthSrv: Option[LocalPasswordAuthSrv] | ||
)(implicit authContext: AuthContext): Traversal.V[User] => Traversal[JsObject, JMap[String, Any], Converter[JsObject, JMap[String, Any]]] = | ||
_.project(_.by.by(_.organisations.users(Permissions.manageUser).current.option)) | ||
.domainMap { | ||
case (user, Some(_)) => | ||
Json.obj( | ||
"lastFailed" -> user.lastFailed, | ||
"failedAttempts" -> user.failedAttempts, | ||
"lockedUntil" -> localPasswordAuthSrv.flatMap(_.lockedUntil(user)) | ||
) | ||
case _ => JsObject.empty | ||
} | ||
|
||
def userStatsRenderer(extraData: Set[String], authSrv: Option[LocalPasswordAuthSrv])(implicit | ||
authContext: AuthContext | ||
): Traversal.V[User] => JsTraversal = { implicit traversal => | ||
baseRenderer( | ||
extraData, | ||
traversal, | ||
{ | ||
case (f, "lockout") => addData("lockout", f)(lockout(authSrv)) | ||
case (f, _) => f | ||
} | ||
) | ||
} | ||
} |