Skip to content

Commit

Permalink
#99 Update playframework
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Oct 29, 2020
1 parent 21ff8fc commit 8e7910f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
36 changes: 17 additions & 19 deletions app/org/elastic4play/ClientAuthSSLEngineProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ package org.elastic4play
import java.nio.file.{Files, Paths}
import java.security.KeyStore

import javax.net.ssl._
import play.api.Logger
import play.core.ApplicationProvider
import play.core.server.ServerConfig
import play.server.api.SSLEngineProvider

import javax.net.ssl._

class ClientAuthSSLEngineProvider(serverConfig: ServerConfig, appProvider: ApplicationProvider) extends SSLEngineProvider {
class ClientAuthSSLEngineProvider(serverConfig: ServerConfig) extends SSLEngineProvider {

lazy val logger = Logger(getClass)
private val config = serverConfig.configuration
lazy val logger: Logger = Logger(getClass)
private val config = serverConfig.configuration

def readKeyManagers(): Array[KeyManager] = {
val keyStorePath = Paths.get(config.get[String]("play.server.https.keyStore.path"))
Expand Down Expand Up @@ -50,21 +48,11 @@ class ClientAuthSSLEngineProvider(serverConfig: ServerConfig, appProvider: Appli
}
.getOrElse(Array.empty)

def createSSLContext(applicationProvider: ApplicationProvider): SSLContext = {
val keyManagers = readKeyManagers()
val trustManagers = readTrustManagers()

// Configure the SSL context to use TLS
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagers, trustManagers, null)
sslContext
}

override def createSSLEngine(): SSLEngine = {
val sslContext = createSSLContext(appProvider)
val sslCtx = sslContext()

// Start off with a clone of the default SSL parameters...
val sslParameters = sslContext.getDefaultSSLParameters
val sslParameters = sslCtx.getDefaultSSLParameters

// Tells the server to ignore client's cipher suite preference.
// http://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#cipher_suite_preference
Expand All @@ -76,8 +64,18 @@ class ClientAuthSSLEngineProvider(serverConfig: ServerConfig, appProvider: Appli
sslParameters.setWantClientAuth(wantClientAuth)

// Clone and modify the default SSL parameters.
val engine = sslContext.createSSLEngine
val engine = sslCtx.createSSLEngine
engine.setSSLParameters(sslParameters)
engine
}

override def sslContext(): SSLContext = {
val keyManagers = readKeyManagers()
val trustManagers = readTrustManagers()

// Configure the SSL context to use TLS
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagers, trustManagers, null)
sslContext
}
}
2 changes: 1 addition & 1 deletion app/org/elastic4play/database/DBFind.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DBFind(pageSize: Int, keepAlive: FiniteDuration, db: DBConfiguration, impl
val resp = db.execute(searchRequest.start(offset).limit(limit))
val total = resp.map(_.totalHits)
val src = Source
.fromFuture(resp)
.future(resp)
.mapConcat { resp =>
resp.hits.hits.toList
}
Expand Down
35 changes: 11 additions & 24 deletions app/org/elastic4play/services/MigrationSrv.scala
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package org.elastic4play.services

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

import play.api.libs.json.JsValue.jsValueToJsLookup
import play.api.libs.json.Json.toJsFieldJsValueWrapper
import play.api.libs.json._
import play.api.{Configuration, Logger}

import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.scaladsl.{Sink, Source}
import akka.stream.{ActorMaterializer, ActorMaterializerSettings, Materializer}
import com.sksamuel.elastic4s.http.ElasticDsl._
import com.typesafe.config.Config
import javax.inject.{Inject, Singleton}

import org.elastic4play.InternalError
import org.elastic4play.database._
import play.api.Logger
import play.api.libs.json.JsValue.jsValueToJsLookup
import play.api.libs.json.Json.toJsFieldJsValueWrapper
import play.api.libs.json._

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

case class MigrationEvent(modelName: String, current: Long, total: Long) extends EventMessage

Expand Down Expand Up @@ -45,30 +41,22 @@ abstract class DatabaseState {
}

object DatabaseState {
def unapply(s: DatabaseState) = Some(s.version)
def unapply(s: DatabaseState): Option[Int] = Some(s.version)
}

@Singleton
class MigrationSrv @Inject()(
configuration: Configuration,
migration: MigrationOperations,
db: DBConfiguration,
dbcreate: DBCreate,
dbfind: DBFind,
dbget: DBGet,
dblists: DBLists,
dbindex: DBIndex,
modelSrv: ModelSrv,
eventSrv: EventSrv,
implicit val system: ActorSystem,
implicit val ec: ExecutionContext
) {

implicit val mat: Materializer = {
val materializerSettings = configuration.getOptional[Config]("migration.stream").map(ActorMaterializerSettings.apply)
ActorMaterializer(materializerSettings, None)
}

private[MigrationSrv] lazy val logger = Logger(getClass)

/* Constructed state of the database from the previous version */
Expand Down Expand Up @@ -130,7 +118,7 @@ class MigrationSrv @Inject()(

object OriginState {

def apply(db: DBConfiguration) =
def apply(db: DBConfiguration): DatabaseState =
migration.indexType(db.version) match {
case IndexType.`indexWithoutMappingTypes` => new OriginStateES6(db)
case IndexType.indexWithMappingTypes => new OriginStateES5(db)
Expand Down Expand Up @@ -241,9 +229,8 @@ trait Operation extends ((String => Source[JsObject, NotUsed]) => (String => Sou

object Operation {

def apply(o: (String => Source[JsObject, NotUsed]) => String => Source[JsObject, NotUsed]) = new Operation {
def apply(f: String => Source[JsObject, NotUsed]): String => Source[JsObject, NotUsed] = o(f)
}
def apply(o: (String => Source[JsObject, NotUsed]) => String => Source[JsObject, NotUsed]): Operation =
(f: String => Source[JsObject, NotUsed]) => o(f)

def renameEntity(previous: String, next: String): Operation =
Operation((f: String => Source[JsObject, NotUsed]) => {
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lazy val elastic4play = (project in file("."))
// Add Http2 support to be able to ask client certificate
// cf. https://github.com/playframework/playframework/issues/8143

scalaVersion := "2.12.8"
scalaVersion := "2.12.12"

resolvers += "elasticsearch-releases" at "https://artifacts.elastic.co/maven"

Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
logLevel := Level.Info

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.25")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.3")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.0")
addSbtPlugin("org.thehive-project" % "sbt-github-changelog" % "0.3.0")

0 comments on commit 8e7910f

Please sign in to comment.