Skip to content

Commit

Permalink
#89 Let an user display and change their API key
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 13, 2018
1 parent 714b131 commit 7823ecb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/org/thp/cortex/controllers/AnalyzerCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import javax.inject.{ Inject, Singleton }

import scala.concurrent.{ ExecutionContext, Future }

import play.api.libs.json.{ JsNull, JsObject, Json }
import play.api.libs.json.{ JsObject, Json }
import play.api.mvc.{ AbstractController, Action, AnyContent, ControllerComponents }

import akka.stream.Materializer
Expand Down
3 changes: 1 addition & 2 deletions app/org/thp/cortex/controllers/MispCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package org.thp.cortex.controllers

import javax.inject.Inject
import org.elastic4play.controllers.{ Authenticated, Fields, FieldsBodyParser, Renderer }
import org.elastic4play.services.QueryDSL
import org.thp.cortex.models.Roles
import org.thp.cortex.services.{ AnalyzerSrv, MispSrv }
import play.api.Logger
import play.api.libs.json.{ JsObject, JsValue, Json }
import play.api.libs.json.{ JsObject, JsValue }
import play.api.mvc._

import scala.concurrent.{ ExecutionContext, Future }
Expand Down
8 changes: 6 additions & 2 deletions app/org/thp/cortex/controllers/UserCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,11 @@ class UserCtrl @Inject() (
}

@Timed
def getKey(userId: String): Action[AnyContent] = authenticated(Roles.orgAdmin, Roles.superAdmin).async { implicit request
def getKey(userId: String): Action[AnyContent] = authenticated().async { implicit request
for {
_ checkUserOrganization(userId)
_ if (userId == request.userId || request.roles.contains(Roles.orgAdmin) || request.roles.contains(Roles.superAdmin)) Future.successful(())
else Future.failed(AuthorizationError("You are not authorized to perform this operation"))
key authSrv.getKey(userId)
} yield Ok(key)
}
Expand All @@ -226,9 +228,11 @@ class UserCtrl @Inject() (
}

@Timed
def renewKey(userId: String): Action[AnyContent] = authenticated(Roles.orgAdmin, Roles.superAdmin).async { implicit request
def renewKey(userId: String): Action[AnyContent] = authenticated().async { implicit request
for {
_ checkUserOrganization(userId)
_ if (userId == request.userId || request.roles.contains(Roles.orgAdmin) || request.roles.contains(Roles.superAdmin)) Future.successful(())
else Future.failed(AuthorizationError("You are not authorized to perform this operation"))
key authSrv.renewKey(userId)
} yield Ok(key)
}
Expand Down

0 comments on commit 7823ecb

Please sign in to comment.