Skip to content

Commit

Permalink
#263 Don't delegate user key search to ES as key is not indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Sep 5, 2017
1 parent 106842f commit 008a59a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions thehive-backend/app/controllers/UserCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class UserCtrl @Inject() (
@Timed
def update(id: String): Action[Fields] = authenticated(Roles.read).async(fieldsBodyParser) { implicit request
if (id == request.authContext.userId || request.authContext.roles.contains(Roles.admin)) {
if (request.body.contains("password"))
logger.warn("Change password attribute using update operation is deprecated. Please use dedicated API (setPassword and changePassword)")
userSrv.update(id, request.body.unset("password")).map { user
if (request.body.contains("password") || request.body.contains("key"))
logger.warn("Change password or key using update operation is deprecated. Please use dedicated API (setPassword, changePassword or renewKey)")
userSrv.update(id, request.body.unset("password").unset("key")).map { user
renderer.toOutput(OK, user)
}
}
Expand Down
3 changes: 1 addition & 2 deletions thehive-backend/app/models/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ object UserStatus extends Enumeration with HiveEnumeration {
trait UserAttributes { _: AttributeDef
val login = attribute("login", F.stringFmt, "Login of the user", O.form)
val userId = attribute("_id", F.stringFmt, "User id (login)", O.model)
val withKey = optionalAttribute("with-key", F.booleanFmt, "Generate an API key", O.form)
val key = optionalAttribute("key", F.stringFmt, "API key", O.model, O.sensitive, O.unaudited)
val key = optionalAttribute("key", F.stringFmt, "API key", O.sensitive, O.unaudited)
val userName = attribute("name", F.stringFmt, "Full name (Firstname Lastname)")
val roles = multiAttribute("roles", RoleAttributeFormat, "Comma separated role list (READ, WRITE and ADMIN)")
val status = attribute("status", F.enumFmt(UserStatus), "Status of the user", UserStatus.Ok)
Expand Down
4 changes: 3 additions & 1 deletion thehive-backend/app/services/LocalAuthSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class LocalAuthSrv @Inject() (

override def authenticate(key: String)(implicit request: RequestHeader): Future[AuthContext] = {
import org.elastic4play.services.QueryDSL._
userSrv.find(and("status" ~= "Ok", "key" ~= key), Some("0-1"), Nil)
// key attribute is sensitive so it is not possible to search on that field
userSrv.find("status" ~= "Ok", Some("all"), Nil)
._1
.filter(_.key().contains(key))
.runWith(Sink.headOption)
.flatMap {
case Some(user) userSrv.getFromUser(request, user)
Expand Down

0 comments on commit 008a59a

Please sign in to comment.