diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala index 1e2f2e2f32caeb027b801a2d58fca022ff7b19eb..465c98ea24e4868c9ced3c495a59b2bffb26d487 100644 --- a/app/controllers/Application.scala +++ b/app/controllers/Application.scala @@ -2,11 +2,11 @@ package controllers import com.google.inject.Inject import controllers.auth.AuthenticationModule -import play.api.mvc.Controller +import play.api.mvc.InjectedController -class Application @Inject()(val authentication: AuthenticationModule) extends Controller with AuthSupport { +class Application @Inject()(val authentication: AuthenticationModule) extends InjectedController with AuthSupport { - def index = AuthAction(authentication, true) { request => + def index = AuthAction(authentication, true)(defaultExecutionContext) { request => Ok(views.html.Index()) } diff --git a/app/controllers/AuthController.scala b/app/controllers/AuthController.scala index 468881e4b0d50c60f58b576fb3bb31894f952ecb..e798f070cea6b257fbfa16521355160632394fed 100644 --- a/app/controllers/AuthController.scala +++ b/app/controllers/AuthController.scala @@ -6,14 +6,14 @@ import akka.actor.ActorSystem import controllers.auth.{AuthAction, AuthenticationModule} import forms.LoginForm import play.api.Configuration -import play.api.mvc.{Action, Controller} +import play.api.mvc.InjectedController @Singleton class AuthController @Inject()(system: ActorSystem, authentication: AuthenticationModule, configuration: Configuration) - extends Controller { + extends InjectedController { import AuthController._ diff --git a/app/controllers/AuthSupport.scala b/app/controllers/AuthSupport.scala index f6cca62c3b225ca72099f687b23287e5f7f59eec..feae1b12f34c5178946d6392787bcc55c336ab5d 100644 --- a/app/controllers/AuthSupport.scala +++ b/app/controllers/AuthSupport.scala @@ -1,11 +1,13 @@ package controllers import controllers.auth.{AuthAction, AuthenticationModule} -import play.api.mvc.Controller +import play.api.mvc.InjectedController -trait AuthSupport { self: Controller => +import scala.concurrent.ExecutionContext - def AuthAction(authentication: AuthenticationModule, redirect: Boolean = false): AuthAction = - new AuthAction(authentication, redirect) +trait AuthSupport { self: InjectedController => + + def AuthAction(authentication: AuthenticationModule, redirect: Boolean = false)(implicit ec: ExecutionContext): AuthAction = + new AuthAction(authentication, redirect, parse.anyContent) } \ No newline at end of file diff --git a/app/controllers/BaseController.scala b/app/controllers/BaseController.scala index a9a808b6eb2e9994e2c5a3e1a3013e6ab96c01a7..51d8d3cf448b2c842c941a218ec0208a0d4455e1 100644 --- a/app/controllers/BaseController.scala +++ b/app/controllers/BaseController.scala @@ -5,14 +5,14 @@ import exceptions.MissingRequiredParamException import models.{CerebroRequest, CerebroResponse, Hosts} import play.api.Logger import play.api.libs.json.{JsValue, Json} -import play.api.mvc.{Controller, Result} +import play.api.mvc.{Controller, InjectedController, Result} import services.exception.RequestFailedException import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.util.control.NonFatal -trait BaseController extends Controller with AuthSupport { +trait BaseController extends InjectedController with AuthSupport { val authentication: AuthenticationModule diff --git a/app/controllers/ConnectController.scala b/app/controllers/ConnectController.scala index 9c7550e6e2212fc6311f94ee3f997b34adf6298d..10f84521944762060c0b2cbefd9e96614ce3c433 100644 --- a/app/controllers/ConnectController.scala +++ b/app/controllers/ConnectController.scala @@ -6,19 +6,19 @@ import controllers.auth.AuthenticationModule import elastic.ElasticClient import models.{CerebroRequest, CerebroResponse, Hosts} import play.api.libs.json.{JsArray, JsString} -import play.api.mvc.Controller +import play.api.mvc.InjectedController import scala.concurrent.ExecutionContext.Implicits.global class ConnectController @Inject()(val authentication: AuthenticationModule, elastic: ElasticClient, - hosts: Hosts) extends Controller with AuthSupport { + hosts: Hosts) extends InjectedController with AuthSupport { - def index = AuthAction(authentication) { _ => + def index = AuthAction(authentication)(defaultExecutionContext) { _ => CerebroResponse(200, JsArray(hosts.getHostNames().map(JsString(_)))) } - def connect = AuthAction(authentication).async(parse.json) { request => + def connect = AuthAction(authentication)(defaultExecutionContext).async(parse.json) { request => val req = CerebroRequest(request, hosts) elastic.executeRequest("GET", "_cluster/health", None, req.target).map { response => CerebroResponse(response.status, response.body) diff --git a/app/controllers/auth/AuthAction.scala b/app/controllers/auth/AuthAction.scala index b54a7a6d51a588a3c7861a218817007624bdc4e3..5f3ec73eca8c5045f8b41bc90d903ef90af56c08 100644 --- a/app/controllers/auth/AuthAction.scala +++ b/app/controllers/auth/AuthAction.scala @@ -5,11 +5,12 @@ import models.{CerebroResponse, User} import play.api.libs.json.JsNull import play.api.mvc._ -import scala.concurrent.Future +import scala.concurrent.{ExecutionContext, Future} class AuthRequest[A](val user: Option[User], request: Request[A]) extends WrappedRequest[A](request) -final class AuthAction(auth: AuthenticationModule, redirect: Boolean) extends ActionBuilder[AuthRequest] { +final class AuthAction(auth: AuthenticationModule, redirect: Boolean, override val parser: BodyParser[AnyContent])(implicit ec: ExecutionContext) + extends ActionBuilder[AuthRequest, AnyContent] { def invokeBlock[A](request: Request[A], block: (AuthRequest[A]) => Future[Result]) = { if (auth.isEnabled) { @@ -29,6 +30,7 @@ final class AuthAction(auth: AuthenticationModule, redirect: Boolean) extends Ac } } + override protected def executionContext: ExecutionContext = ec } object AuthAction { diff --git a/build.sbt b/build.sbt index 5ff676e98a4935b08c4ae904dfa4562b759f10f4..e41b199b86554cb19a5e9ed2de5839e746314566 100644 --- a/build.sbt +++ b/build.sbt @@ -7,10 +7,10 @@ version := "0.7.2" scalaVersion := "2.11.11" libraryDependencies ++= Seq( - "com.typesafe.play" %% "play" % "2.5.10", - "com.typesafe.play" %% "play-ws" % "2.5.10", - "com.typesafe.play" %% "play-slick" % "2.0.2", - "com.typesafe.play" %% "play-slick-evolutions" % "2.0.2", + "com.typesafe.play" %% "play" % "2.6.7", + "com.typesafe.play" %% "play-json" % "2.6.7", + "com.typesafe.play" %% "play-slick" % "3.0.1", + "com.typesafe.play" %% "play-slick-evolutions" % "3.0.1", "org.xerial" % "sqlite-jdbc" % "3.20.0", "org.specs2" %% "specs2-junit" % "3.8.4" % "test", "org.specs2" %% "specs2-core" % "3.8.4" % "test", @@ -18,6 +18,8 @@ libraryDependencies ++= Seq( ) libraryDependencies += filters +libraryDependencies += ws +libraryDependencies += guice lazy val root = (project in file(".")). enablePlugins(PlayScala, BuildInfoPlugin, LauncherJarPlugin). diff --git a/project/plugins.sbt b/project/plugins.sbt index 3e7948687bc0cf4fdf1228a74905cf6787718d4b..74c9618f0b6ab2d28b782fd285030c4a84b4c09e 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -5,7 +5,7 @@ logLevel := Level.Warn resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/" // Use the Play sbt plugin for Play projects -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10") +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.7") addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.9")