Skip to content

Commit 47bfae9

Browse files
committed
#275 Add Support for Play 2.6.x and Elasticsearch 5.x
1 parent de56e8d commit 47bfae9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+725
-582
lines changed

project/BuildSettings.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object BasicSettings extends AutoPlugin {
1313
"-deprecation", // Emit warning and location for usages of deprecated APIs.
1414
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
1515
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
16-
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
16+
//"-Xfatal-warnings", // Fail the compilation if there are any warnings.
1717
"-Xlint", // Enable recommended additional warnings.
1818
"-Ywarn-adapted-args", // Warn if an argument list is modified to match the receiver.
1919
"-Ywarn-dead-code", // Warn when dead code is identified.

project/Dependencies.scala

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import sbt._
22

33
object Dependencies {
4-
val scalaVersion = "2.11.8"
4+
val scalaVersion = "2.12.3"
55

66
object Library {
77

88
object Play {
99
val version = play.core.PlayVersion.current
1010
val ws = "com.typesafe.play" %% "play-ws" % version
11-
val cache = "com.typesafe.play" %% "play-cache" % version
11+
val ahc = "com.typesafe.play" %% "play-ahc-ws" % version
12+
val cache = "com.typesafe.play" %% "play-ehcache" % version
1213
val test = "com.typesafe.play" %% "play-test" % version
1314
val specs2 = "com.typesafe.play" %% "play-specs2" % version
1415
val filters = "com.typesafe.play" %% "filters-helpers" % version
16+
val guice = "com.typesafe.play" %% "play-guice" % version
1517
object Specs2 {
1618
private val version = "3.6.6"
1719
val matcherExtra = "org.specs2" %% "specs2-matcher-extra" % version
@@ -20,16 +22,16 @@ object Dependencies {
2022
}
2123

2224
object Specs2 {
23-
private val version = "3.6.6"
25+
private val version = "3.9.4"
2426
val core = "org.specs2" %% "specs2-core" % version
2527
val matcherExtra = "org.specs2" %% "specs2-matcher-extra" % version
2628
val mock = "org.specs2" %% "specs2-mock" % version
2729
}
28-
val scalaGuice = "net.codingwell" %% "scala-guice" % "4.0.1"
29-
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % "2.4.7"
30-
val reflections = "org.reflections" % "reflections" % "0.9.10"
30+
val scalaGuice = "net.codingwell" %% "scala-guice" % "4.1.0"
31+
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % "2.5.4"
32+
val reflections = "org.reflections" % "reflections" % "0.9.11"
3133
val zip4j = "net.lingala.zip4j" % "zip4j" % "1.3.2"
32-
val akkaTest = "com.typesafe.akka" %% "akka-stream-testkit" % "2.4.4"
33-
val elastic4play = "org.cert-bdf" %% "elastic4play" % "1.2.1"
34+
val akkaTest = "com.typesafe.akka" %% "akka-stream-testkit" % "2.5.4"
35+
val elastic4play = "org.cert-bdf" %% "elastic4play" % "1.3-SNAPSHOT"
3436
}
3537
}

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.13
1+
sbt.version=0.13.16

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Comment to get more information during initialization
22
logLevel := Level.Info
33

4-
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.14")
4+
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.3")
55

66
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
77

thehive-backend/app/connectors/Connectors.scala

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
package connectors
22

3-
import javax.inject.Inject
3+
import javax.inject.{ Inject, Singleton }
4+
5+
import scala.collection.immutable
46

5-
import com.google.inject.AbstractModule
6-
import net.codingwell.scalaguice.{ ScalaModule, ScalaMultibinder }
77
import play.api.libs.json.{ JsObject, Json }
8-
import play.api.mvc.{ Action, Handler, RequestHeader, Results }
8+
import play.api.mvc._
99
import play.api.routing.sird.UrlContext
1010
import play.api.routing.{ Router, SimpleRouter }
1111

12-
import scala.collection.immutable
12+
import com.google.inject.AbstractModule
13+
import net.codingwell.scalaguice.{ ScalaModule, ScalaMultibinder }
1314

1415
trait Connector {
1516
val name: String
1617
val router: Router
1718
val status: JsObject = Json.obj("enabled" true)
1819
}
1920

20-
class ConnectorRouter @Inject() (connectors: immutable.Set[Connector]) extends SimpleRouter {
21+
@Singleton
22+
class ConnectorRouter @Inject() (
23+
connectors: immutable.Set[Connector],
24+
actionBuilder: DefaultActionBuilder) extends SimpleRouter {
2125
def get(connectorName: String): Option[Connector] = connectors.find(_.name == connectorName)
2226

2327
def routes: PartialFunction[RequestHeader, Handler] = {
2428
case request @ p"/$connector/$path<.*>"
2529
get(connector)
2630
.flatMap(_.router.withPrefix(s"/$connector/").handlerFor(request))
27-
.getOrElse(Action { _ Results.NotFound(s"connector $connector not found") })
31+
.getOrElse(actionBuilder { _ Results.NotFound(s"connector $connector not found") })
2832
}
2933
}
3034

thehive-backend/app/controllers/AlertCtrl.scala

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ package controllers
22

33
import javax.inject.{ Inject, Singleton }
44

5+
import scala.concurrent.{ ExecutionContext, Future }
6+
import scala.util.Try
7+
8+
import play.api.Logger
9+
import play.api.http.Status
10+
import play.api.libs.json.{ JsArray, JsObject, Json }
11+
import play.api.mvc._
12+
513
import akka.stream.Materializer
14+
import services.JsonFormat.caseSimilarityWrites
15+
import services.{ AlertSrv, CaseSrv }
16+
617
import org.elastic4play.controllers.{ Authenticated, Fields, FieldsBodyParser, Renderer }
718
import org.elastic4play.models.JsonFormat.baseModelEntityWrites
819
import org.elastic4play.services.JsonFormat.{ aggReads, queryReads }
920
import org.elastic4play.services._
1021
import org.elastic4play.{ BadRequestError, Timed }
11-
import play.api.Logger
12-
import play.api.http.Status
13-
import play.api.libs.json.{ JsArray, JsObject, Json }
14-
import play.api.mvc.{ Action, AnyContent, Controller }
15-
import services.{ AlertSrv, CaseSrv }
16-
import services.JsonFormat.caseSimilarityWrites
17-
18-
import scala.concurrent.{ ExecutionContext, Future }
19-
import scala.util.Try
2022

2123
@Singleton
2224
class AlertCtrl @Inject() (
@@ -25,11 +27,12 @@ class AlertCtrl @Inject() (
2527
auxSrv: AuxSrv,
2628
authenticated: Authenticated,
2729
renderer: Renderer,
30+
components: ControllerComponents,
2831
fieldsBodyParser: FieldsBodyParser,
2932
implicit val ec: ExecutionContext,
30-
implicit val mat: Materializer) extends Controller with Status {
33+
implicit val mat: Materializer) extends AbstractController(components) with Status {
3134

32-
val log = Logger(getClass)
35+
private[AlertCtrl] lazy val logger = Logger(getClass)
3336

3437
@Timed
3538
def create(): Action[Fields] = authenticated(Role.write).async(fieldsBodyParser) { implicit request

thehive-backend/app/controllers/ArtifactCtrl.scala

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@ package controllers
33
import javax.inject.{ Inject, Singleton }
44

55
import scala.concurrent.{ ExecutionContext, Future }
6+
67
import play.api.http.Status
78
import play.api.libs.json.JsArray
8-
import play.api.mvc.{ Action, AnyContent, Controller }
9-
import org.elastic4play.{ BadRequestError, Timed }
9+
import play.api.mvc._
10+
11+
import services.ArtifactSrv
12+
1013
import org.elastic4play.controllers.{ Authenticated, Fields, FieldsBodyParser, Renderer }
1114
import org.elastic4play.models.JsonFormat.baseModelEntityWrites
12-
import org.elastic4play.services.{ Agg, AuxSrv }
13-
import org.elastic4play.services.{ QueryDSL, QueryDef, Role }
1415
import org.elastic4play.services.JsonFormat.{ aggReads, queryReads }
15-
import services.ArtifactSrv
16+
import org.elastic4play.services._
17+
import org.elastic4play.{ BadRequestError, Timed }
1618

1719
@Singleton
1820
class ArtifactCtrl @Inject() (
1921
artifactSrv: ArtifactSrv,
2022
auxSrv: AuxSrv,
2123
authenticated: Authenticated,
2224
renderer: Renderer,
25+
components: ControllerComponents,
2326
fieldsBodyParser: FieldsBodyParser,
24-
implicit val ec: ExecutionContext) extends Controller with Status {
27+
implicit val ec: ExecutionContext) extends AbstractController(components) with Status {
2528

2629
@Timed
2730
def create(caseId: String): Action[Fields] = authenticated(Role.write).async(fieldsBodyParser) { implicit request

thehive-backend/app/controllers/Asset.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ package controllers
22

33
import javax.inject.{ Inject, Singleton }
44

5+
import scala.concurrent.ExecutionContext
6+
57
import play.api.Environment
6-
import play.api.http.HttpErrorHandler
7-
import play.api.mvc.{ Action, AnyContent, Controller }
8+
import play.api.http.{ FileMimeTypes, HttpErrorHandler }
9+
import play.api.mvc.{ Action, AnyContent }
810

911
trait AssetCtrl {
1012
def get(file: String): Action[AnyContent]
1113
}
1214

1315
@Singleton
14-
class AssetCtrlProd @Inject() (errorHandler: HttpErrorHandler) extends Assets(errorHandler) with AssetCtrl {
16+
class AssetCtrlProd @Inject() (errorHandler: HttpErrorHandler, meta: AssetsMetadata) extends Assets(errorHandler, meta) with AssetCtrl {
1517
def get(file: String): Action[AnyContent] = at("/ui", file)
1618
}
1719

1820
@Singleton
19-
class AssetCtrlDev @Inject() (environment: Environment) extends ExternalAssets(environment) with AssetCtrl {
21+
class AssetCtrlDev @Inject() (environment: Environment)(implicit ec: ExecutionContext, fileMimeTypes: FileMimeTypes) extends ExternalAssets(environment) with AssetCtrl {
2022
def get(file: String): Action[AnyContent] = {
2123
if (file.startsWith("bower_components/")) {
2224
at("ui", file)

thehive-backend/app/controllers/AttachmentCtrl.scala

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
package controllers
22

3+
import java.nio.file.Files
34
import javax.inject.{ Inject, Singleton }
45

5-
import akka.stream.scaladsl.FileIO
6-
import play.api.Configuration
76
import play.api.http.HttpEntity
8-
import play.api.libs.Files.TemporaryFile
7+
import play.api.libs.Files.DefaultTemporaryFileCreator
98
import play.api.mvc._
9+
import play.api.{ Configuration, mvc }
10+
11+
import akka.stream.scaladsl.FileIO
1012
import net.lingala.zip4j.core.ZipFile
1113
import net.lingala.zip4j.model.ZipParameters
1214
import net.lingala.zip4j.util.Zip4jConstants
15+
1316
import org.elastic4play.Timed
14-
import org.elastic4play.services.{ AttachmentSrv, Role }
15-
import org.elastic4play.models.AttachmentAttributeFormat
17+
import org.elastic4play.controllers.{ Authenticated, Renderer }
1618
import org.elastic4play.models.AttachmentAttributeFormat
17-
import org.elastic4play.controllers.Authenticated
18-
import org.elastic4play.controllers.Renderer
19+
import org.elastic4play.services.{ AttachmentSrv, Role }
1920

2021
/**
2122
* Controller used to access stored attachments (plain or zipped)
2223
*/
2324
@Singleton
2425
class AttachmentCtrl(
2526
password: String,
27+
tempFileCreator: DefaultTemporaryFileCreator,
2628
attachmentSrv: AttachmentSrv,
2729
authenticated: Authenticated,
28-
renderer: Renderer) extends Controller {
30+
components: ControllerComponents,
31+
renderer: Renderer) extends AbstractController(components) {
2932

3033
@Inject() def this(
3134
configuration: Configuration,
35+
tempFileCreator: DefaultTemporaryFileCreator,
3236
attachmentSrv: AttachmentSrv,
3337
authenticated: Authenticated,
38+
components: ControllerComponents,
3439
renderer: Renderer) =
3540
this(
36-
configuration.getString("datastore.attachment.password").get,
41+
configuration.get[String]("datastore.attachment.password"),
42+
tempFileCreator,
3743
attachmentSrv,
3844
authenticated,
45+
components,
3946
renderer)
4047

4148
/**
@@ -47,8 +54,8 @@ class AttachmentCtrl(
4754
def download(hash: String, name: Option[String]): Action[AnyContent] = authenticated(Role.read) { implicit request
4855
if (hash.startsWith("{{")) // angularjs hack
4956
NoContent
50-
else if (!name.getOrElse("").intersect(AttachmentAttributeFormat.forbiddenChar).isEmpty())
51-
BadRequest("File name is invalid")
57+
else if (!name.getOrElse("").intersect(AttachmentAttributeFormat.forbiddenChar).isEmpty)
58+
mvc.Results.BadRequest("File name is invalid")
5259
else
5360
Result(
5461
header = ResponseHeader(
@@ -66,12 +73,12 @@ class AttachmentCtrl(
6673
*/
6774
@Timed("controllers.AttachmentCtrl.downloadZip")
6875
def downloadZip(hash: String, name: Option[String]): Action[AnyContent] = authenticated(Role.read) { implicit request
69-
if (!name.getOrElse("").intersect(AttachmentAttributeFormat.forbiddenChar).isEmpty())
76+
if (!name.getOrElse("").intersect(AttachmentAttributeFormat.forbiddenChar).isEmpty)
7077
BadRequest("File name is invalid")
7178
else {
72-
val f = TemporaryFile("zip", hash).file
73-
f.delete()
74-
val zipFile = new ZipFile(f)
79+
val f = tempFileCreator.create("zip", hash).path
80+
Files.delete(f)
81+
val zipFile = new ZipFile(f.toFile)
7582
val zipParams = new ZipParameters
7683
zipParams.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST)
7784
zipParams.setEncryptFiles(true)
@@ -88,8 +95,8 @@ class AttachmentCtrl(
8895
"Content-Disposition" s"""attachment; filename="${name.getOrElse(hash)}.zip"""",
8996
"Content-Type" "application/zip",
9097
"Content-Transfer-Encoding" "binary",
91-
"Content-Length" f.length.toString)),
92-
body = HttpEntity.Streamed(FileIO.fromPath(f.toPath), Some(f.length), Some("application/zip")))
98+
"Content-Length" Files.size(f).toString)),
99+
body = HttpEntity.Streamed(FileIO.fromPath(f), Some(Files.size(f)), Some("application/zip")))
93100
}
94101
}
95102
}

thehive-backend/app/controllers/AuthenticationCtrl.scala

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ package controllers
22

33
import javax.inject.{ Inject, Singleton }
44

5+
import scala.concurrent.{ ExecutionContext, Future }
6+
7+
import play.api.mvc._
8+
59
import models.UserStatus
6-
import org.elastic4play.{ AuthorizationError, Timed }
10+
import services.UserSrv
11+
712
import org.elastic4play.controllers.{ Authenticated, Fields, FieldsBodyParser, Renderer }
813
import org.elastic4play.database.DBIndex
914
import org.elastic4play.services.AuthSrv
10-
import play.api.mvc.{ Action, Controller, Results }
11-
import services.UserSrv
12-
13-
import scala.concurrent.{ ExecutionContext, Future }
15+
import org.elastic4play.{ AuthorizationError, Timed }
1416

1517
@Singleton
1618
class AuthenticationCtrl @Inject() (
@@ -19,8 +21,9 @@ class AuthenticationCtrl @Inject() (
1921
authenticated: Authenticated,
2022
dbIndex: DBIndex,
2123
renderer: Renderer,
24+
components: ControllerComponents,
2225
fieldsBodyParser: FieldsBodyParser,
23-
implicit val ec: ExecutionContext) extends Controller {
26+
implicit val ec: ExecutionContext) extends AbstractController(components) {
2427

2528
@Timed
2629
def login: Action[Fields] = Action.async(fieldsBodyParser) { implicit request

0 commit comments

Comments
 (0)