diff --git a/app/controllers/AuthController.scala b/app/controllers/AuthController.scala index e798f070cea6b257fbfa16521355160632394fed..e7699c49660727aa36c3d1a251357ef9e7315bd6 100644 --- a/app/controllers/AuthController.scala +++ b/app/controllers/AuthController.scala @@ -60,7 +60,7 @@ class AuthController @Inject()(system: ActorSystem, } def logout = Action { _ => - val prefix = configuration.getString("play.http.context").getOrElse("/") + val prefix = configuration.getOptional[String]("play.http.context").getOrElse("/") Redirect(s"${prefix}login").withNewSession } diff --git a/app/controllers/auth/AuthConfig.scala b/app/controllers/auth/AuthConfig.scala index 7f125f274fe52c4252833aebf2777867dc644bb3..e70271274f58b969023472a17f6d7ec7c2e9a865 100644 --- a/app/controllers/auth/AuthConfig.scala +++ b/app/controllers/auth/AuthConfig.scala @@ -5,7 +5,7 @@ import play.api.Configuration trait AuthConfig { def getSetting(setting: String)(implicit config: Configuration) = { - config.getString(setting).getOrElse(throw MissingSettingException(setting)) + config.getOptional[String](setting).getOrElse(throw MissingSettingException(setting)) } } diff --git a/app/controllers/auth/AuthenticationModule.scala b/app/controllers/auth/AuthenticationModule.scala index f17ddffd0949c28ab87805d1c157dd627879f47a..9d6efa39e35d4c97dc47f4b89d747212346b56f0 100644 --- a/app/controllers/auth/AuthenticationModule.scala +++ b/app/controllers/auth/AuthenticationModule.scala @@ -17,7 +17,7 @@ trait AuthenticationModule { @Singleton class AuthenticationModuleImpl @Inject()(config: Configuration) extends AuthenticationModule { - val service = config.getString("auth.type") match { + val service = config.getOptional[String]("auth.type") match { case Some("ldap") => Some(new LDAPAuthService(config)) case Some("basic") => Some(new BasicAuthService(config)) case _ => None diff --git a/app/controllers/auth/basic/BasicAuthService.scala b/app/controllers/auth/basic/BasicAuthService.scala index bd073c61f2386e419565b3551a090096d32b2d96..9d23e631366b2191ff5438e5a0b11bd1994d481d 100644 --- a/app/controllers/auth/basic/BasicAuthService.scala +++ b/app/controllers/auth/basic/BasicAuthService.scala @@ -6,7 +6,7 @@ import play.api.Configuration class BasicAuthService @Inject()(globalConfig: Configuration) extends AuthService { - private implicit final val config = new BasicAuthConfig(globalConfig.getConfig("auth.settings").get) + private implicit final val config = new BasicAuthConfig(globalConfig.get[Configuration]("auth.settings")) def auth(username: String, password: String): Option[String] = { (username, password) match { diff --git a/app/controllers/auth/ldap/LDAPAuthService.scala b/app/controllers/auth/ldap/LDAPAuthService.scala index f23d624e2b9197961a0ba9ce7284b4af95da6767..a26dbe84523996aa71aad2aa145799a443c26f09 100644 --- a/app/controllers/auth/ldap/LDAPAuthService.scala +++ b/app/controllers/auth/ldap/LDAPAuthService.scala @@ -14,7 +14,7 @@ class LDAPAuthService @Inject()(globalConfig: Configuration) extends AuthService private val log = org.slf4j.LoggerFactory.getLogger(classOf[LDAPAuthService]) - private final val config = new LDAPAuthConfig(globalConfig.getConfig("auth.settings").get) + private final val config = new LDAPAuthConfig(globalConfig.get[Configuration]("auth.settings")) def auth(username: String, password: String): Option[String] = { val env = new Hashtable[String, String](11) diff --git a/app/dao/RestHistoryDAO.scala b/app/dao/RestHistoryDAO.scala index 8a3ab88e00b9d23febd9fcea6b0b0c0268e250ca..f5d61c2197f0874e033f04676bb39eccf9a706f5 100644 --- a/app/dao/RestHistoryDAO.scala +++ b/app/dao/RestHistoryDAO.scala @@ -5,8 +5,8 @@ import java.util.Date import com.google.inject.{ImplementedBy, Inject} import play.api.Configuration import play.api.db.slick.DatabaseConfigProvider -import slick.driver.JdbcProfile -import slick.driver.SQLiteDriver.api._ +import slick.jdbc.JdbcProfile +import slick.jdbc.SQLiteProfile.api._ import slick.lifted.TableQuery import scala.concurrent.ExecutionContext.Implicits.global @@ -28,7 +28,7 @@ trait RestHistoryDAO { class RestHistoryDAOImpl @Inject()(dbConfigProvider: DatabaseConfigProvider, config: Configuration) extends RestHistoryDAO { - private val max = config.getInt("rest.history.size").getOrElse(50) + private val max = config.getOptional[Int]("rest.history.size").getOrElse(50) private val dbConfig = dbConfigProvider.get[JdbcProfile] diff --git a/app/dao/RestRequest.scala b/app/dao/RestRequest.scala index 9b02a9088f60d2eec5f7868b9ecf69a771ca3b57..9178e44d0f9f7fa2c0297202a396879fbcb6a667 100644 --- a/app/dao/RestRequest.scala +++ b/app/dao/RestRequest.scala @@ -3,7 +3,7 @@ package dao import java.security.MessageDigest import java.util.Date -import slick.driver.SQLiteDriver.api._ +import slick.jdbc.SQLiteProfile.api._ import slick.lifted.Tag case class HashedRestRequest(path: String, method: String, body: String, username: String, createdAt: Long, md5: String) diff --git a/app/elastic/HTTPElasticClient.scala b/app/elastic/HTTPElasticClient.scala index 3498b5fb53058453d2f400a59632e5056a22f90a..80a05c2117640b195910b15af8bcc7443fd95454 100644 --- a/app/elastic/HTTPElasticClient.scala +++ b/app/elastic/HTTPElasticClient.scala @@ -322,7 +322,7 @@ class HTTPElasticClient @Inject()(client: WSClient) extends ElasticClient { val authentication = target.authentication val url = s"${target.host.replaceAll("/+$", "")}$uri" val request = - authentication.foldLeft(client.url(url).withMethod(method).withHeaders(headers: _*)) { + authentication.foldLeft(client.url(url).withMethod(method).withHttpHeaders(headers: _*)) { case (request, auth) => request.withAuth(auth.username, auth.password, WSAuthScheme.BASIC) } diff --git a/app/models/Hosts.scala b/app/models/Hosts.scala index 17d96a6d72bf6004e3aa8b1d67a66cb00ee487c8..0516078340eccb1fc6180247cd7b0c5cd8316995 100644 --- a/app/models/Hosts.scala +++ b/app/models/Hosts.scala @@ -5,6 +5,10 @@ import javax.inject.Singleton import com.google.inject.{ImplementedBy, Inject} import play.api.Configuration +import scala.collection.JavaConverters._ +import scala.util.{Failure, Success, Try} + + @ImplementedBy(classOf[HostsImpl]) trait Hosts { @@ -17,18 +21,18 @@ trait Hosts { @Singleton class HostsImpl @Inject()(config: Configuration) extends Hosts { - val hosts: Map[String, ElasticServer] = config.getConfigSeq("hosts") match { - case Some(hostsConf) => hostsConf.map { hostConf => - val host = hostConf.getString("host").get - val name = hostConf.getString("name").getOrElse(host) - val username = hostConf.getString("auth.username") - val password = hostConf.getString("auth.password") + val hosts: Map[String, ElasticServer] = Try(config.underlying.getConfigList("hosts").asScala.map(Configuration(_))) match { + case Success(hostsConf) => hostsConf.map { hostConf => + val host = hostConf.getOptional[String]("host").get + val name = hostConf.getOptional[String]("name").getOrElse(host) + val username = hostConf.getOptional[String]("auth.username") + val password = hostConf.getOptional[String]("auth.password") (username, password) match { case (Some(username), Some(password)) => (name -> ElasticServer(host, Some(ESAuth(username, password)))) case _ => (name -> ElasticServer(host, None)) } }.toMap - case _ => Map() + case Failure(_) => Map() } def getHostNames() = hosts.keys.toSeq diff --git a/conf/reference.conf b/conf/reference.conf index da6cf2edc154ac7ba1d9fbcce181b25164013aad..6ebc38a278c45f2aaa8a529aab982747c0592994 100644 --- a/conf/reference.conf +++ b/conf/reference.conf @@ -1,6 +1,6 @@ # Secret key secret = "changeme" -play.crypto.secret = ${secret} +play.http.secret.key = ${secret} es { gzip = false