Commit 2b0e270c authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[REST] enh: remove authentication

parent 6bd7f184
Pipeline #441 passed with stage
in 14 minutes and 30 seconds
......@@ -60,14 +60,14 @@ lazy val circe = OsgiProject(dir, "io.circe",
lazy val logback = OsgiProject(dir, "ch.qos.logback", exports = Seq("ch.qos.logback.*", "org.slf4j.impl"), dynamicImports = Seq("*")) settings
(libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3", version := "1.2.3") settings(settings: _*)
lazy val h2Version = "1.4.199"
lazy val h2Version = "1.4.200"
lazy val h2 = OsgiProject(dir, "org.h2", dynamicImports = Seq("*"), privatePackages = Seq("META-INF.*")) settings
(libraryDependencies += "com.h2database" % "h2" % h2Version, version := h2Version) settings(settings: _*)
lazy val bonecp = OsgiProject(dir, "com.jolbox.bonecp", dynamicImports = Seq("*")) settings
(libraryDependencies += "com.jolbox" % "bonecp" % "0.8.0.RELEASE", version := "0.8.0.RELEASE") settings(settings: _*)
lazy val slickVersion = "3.3.0"
lazy val slickVersion = "3.3.2"
lazy val slick = OsgiProject(dir,"com.typesafe.slick", exports = Seq("slick.*"), privatePackages = Seq("org.reactivestreams.*")) settings
(libraryDependencies += "com.typesafe.slick" %% "slick" % slickVersion, version := slickVersion) settings(settings: _*)
......@@ -119,7 +119,7 @@ lazy val scalaLang = OsgiProject(
)
}, version := scalaVersion.value) settings(settings: _*)
lazy val jasyptVersion = "1.9.2"
lazy val jasyptVersion = "1.9.3"
lazy val jasypt = OsgiProject(dir, "org.jasypt.encryption", exports = Seq("org.jasypt.*")) settings(
libraryDependencies += "org.jasypt" % "jasypt" % jasyptVersion,
version := jasyptVersion
......@@ -165,7 +165,7 @@ lazy val netlogo6 = OsgiProject(
lazy val scalaTagsVersion = "0.8.3"
lazy val scalaRxVersion = "0.4.0"
lazy val scalaDomVersion = "0.9.3"
lazy val scalaUpickleVersion = "0.4.4"
//lazy val scalaUpickleVersion = "0.9.6"
lazy val scalaBoopickleVersion = "1.3.1"
lazy val scalaAutowireVersion = "0.2.6"
lazy val scalajsVersion = "0.6.31"
......@@ -191,9 +191,9 @@ lazy val scalatexSite =
libraryDependencies += "com.lihaoyi" %% "scalatex-site" % "0.3.12",
version := "0.3.12") settings(settings: _*)
lazy val upickle = OsgiProject(dir, "upickle", exports = Seq("upickle.*", "jawn.*", "derive.*"), imports = Seq("*")) settings(
/*lazy val upickle = OsgiProject(dir, "upickle", exports = Seq("upickle.*", "jawn.*", "derive.*"), imports = Seq("*")) settings(
libraryDependencies ++= Seq("com.lihaoyi" %% "upickle" % scalaUpickleVersion),
version := scalaUpickleVersion) settings(settings: _*) dependsOn(sourceCode)
version := scalaUpickleVersion) settings(settings: _*) dependsOn(sourceCode)*/
lazy val boopickle = OsgiProject(dir, "boopickle", exports = Seq("boopickle.*"), imports = Seq("*")) settings(
libraryDependencies ++= Seq("io.suzaku" %% "boopickle" % scalaBoopickleVersion),
......@@ -265,8 +265,8 @@ lazy val arm = OsgiProject(dir, "com.jsuereth.scala-arm") settings(
exportPackage := Seq("resource.*")) settings(settings: _*)
lazy val scalajHttp = OsgiProject(dir, "org.scalaj.scalaj-http") settings(
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.3.0",
version := "2.3.0",
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.4.2",
version := "2.4.2",
exportPackage := Seq("scalaj.http.*")
) settings(settings: _*)
......@@ -294,13 +294,13 @@ lazy val logging = OsgiProject(dir, "org.apache.commons.logging") settings
(libraryDependencies += "commons-logging" % "commons-logging" % "1.2", version := "1.2") settings(settings: _*)
lazy val lang3 = OsgiProject(dir, "org.apache.commons.lang3") settings (
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.4", version := "3.4") settings(settings: _*)
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.9", version := "3.9") settings(settings: _*)
lazy val ant = OsgiProject(dir, "org.apache.ant") settings
(libraryDependencies += "org.apache.ant" % "ant" % "1.8.0", version := "1.8.0") settings(settings: _*)
(libraryDependencies += "org.apache.ant" % "ant" % "1.10.7", version := "1.10.7") settings(settings: _*)
lazy val codec = OsgiProject(dir, "org.apache.commons.codec") settings
(libraryDependencies += "commons-codec" % "commons-codec" % "1.13", version := "1.13") settings(settings: _*)
(libraryDependencies += "commons-codec" % "commons-codec" % "1.14", version := "1.14") settings(settings: _*)
lazy val collections = OsgiProject(dir, "org.apache.commons.collections", exports = Seq("org.apache.commons.collections4.*")) settings
(libraryDependencies += "org.apache.commons" % "commons-collections4" % "4.4", version := "4.4") settings(settings: _*)
......@@ -339,9 +339,9 @@ lazy val asm = OsgiProject(dir, "org.objectweb.asm") settings (
lazy val config = OsgiProject(dir, "org.apache.commons.configuration2",
privatePackages = Seq("!scala.*", "!org.apache.commons.logging.*","*"),
imports = Seq("org.apache.commons.logging.*")) settings (
libraryDependencies += "org.apache.commons" % "commons-configuration2" % "2.2",
libraryDependencies += "commons-beanutils" % "commons-beanutils" % "1.9.2",
version := "2.2") settings(settings: _*) dependsOn (logging)
libraryDependencies += "org.apache.commons" % "commons-configuration2" % "2.6",
libraryDependencies += "commons-beanutils" % "commons-beanutils" % "1.9.4",
version := "2.6") settings(settings: _*) dependsOn (logging)
def sourceCodeVersion = "0.1.9"
lazy val sourceCode = OsgiProject(dir, "sourcecode") settings (
......@@ -414,8 +414,8 @@ lazy val gridscaleEGI = OsgiProject(dir, "gridscale.egi", imports = Seq("*")) se
lazy val gridscaleDIRAC = OsgiProject(dir, "gridscale.dirac", imports = Seq("*"), privatePackages = Seq("gridscale.dirac.*", "org.apache.commons.compress.*", "org.brotli.*", "org.tukaani.*", "com.github.luben.*")) settings (
libraryDependencies += "org.openmole.gridscale" %% "dirac" % gridscaleVersion,
libraryDependencies += "org.brotli" % "dec" % "0.1.2",
libraryDependencies += "org.tukaani" % "xz" % "1.6",
libraryDependencies += "com.github.luben" % "zstd-jni" % "1.4.3-1",
libraryDependencies += "org.tukaani" % "xz" % "1.8",
libraryDependencies += "com.github.luben" % "zstd-jni" % "1.4.4-3",
version := gridscaleVersion
) settings(settings: _*) dependsOn(gridscale, gridscaleHTTP)
......
......@@ -63,15 +63,15 @@ object Libraries {
lazy val scalatra = "org.openmole.library" %% "org-scalatra" % scalatraVersion
lazy val logback = "org.openmole.library" %% "ch-qos-logback" % "1.2.3"
lazy val h2 = "org.openmole.library" %% "org-h2" % "1.4.199"
lazy val h2 = "org.openmole.library" %% "org-h2" % "1.4.200"
lazy val bonecp = "org.openmole.library" %% "com-jolbox-bonecp" % "0.8.0.RELEASE"
lazy val slick = "org.openmole.library" %% "com-typesafe-slick" % "3.3.0"
lazy val slick = "org.openmole.library" %% "com-typesafe-slick" % "3.3.2"
lazy val slf4j = "org.openmole.library" %% "org-slf4j" % "1.7.30"
lazy val xstream = "org.openmole.library" %% "com-thoughtworks-xstream" % xstreamVersion
lazy val jasypt = "org.openmole.library" %% "org-jasypt-encryption" % "1.9.2"
lazy val jasypt = "org.openmole.library" %% "org-jasypt-encryption" % "1.9.3"
lazy val opencsv = "org.openmole.library" %% "au-com-bytecode-opencsv" % "2.3"
lazy val arm = "org.openmole.library" %% "com-jsuereth-scala-arm" % "2.0"
lazy val scalajHttp = "org.openmole.library" %% "org-scalaj-scalaj-http" % "2.3.0"
lazy val scalajHttp = "org.openmole.library" %% "org-scalaj-scalaj-http" % "2.4.2"
lazy val scopt = "org.openmole.library" %% "com-github-scopt" % scoptVersion
lazy val scalabc = "org.openmole.library" %% "fr-iscpif-scalabc" % "0.4"
lazy val scalatexSite = "org.openmole.library" %% "com-lihaoyi-scalatex-site" % "0.3.12"
......@@ -80,16 +80,16 @@ object Libraries {
lazy val exec = "org.openmole.library" %% "org-apache-commons-exec" % "1.3"
lazy val log4j = "org.openmole.library" %% "org-apache-log4j" % "1.2.17"
lazy val logging = "org.openmole.library" %% "org-apache-commons-logging" % "1.2"
lazy val lang3 = "org.openmole.library" %% "org-apache-commons-lang3" % "3.4"
lazy val ant = "org.openmole.library" %% "org-apache-ant" % "1.8.0"
lazy val codec = "org.openmole.library" %% "org-apache-commons-codec" % "1.13"
lazy val lang3 = "org.openmole.library" %% "org-apache-commons-lang3" % "3.9"
lazy val ant = "org.openmole.library" %% "org-apache-ant" % "1.10.7"
lazy val codec = "org.openmole.library" %% "org-apache-commons-codec" % "1.14"
lazy val async = "org.openmole.library" %% "scala-async" % "0.10.0"
lazy val jgit = "org.openmole.library" %% "org-eclipse-jgit" % "5.6.0"
lazy val cats = "org.openmole.library" %% "cats" % catsVersion
lazy val squants = "org.openmole.library" %% "squants" % squantsVersion
lazy val clapper = "org.openmole.library" %% "org-clapper" % "1.5.1"
lazy val asm = "org.openmole.library" %% "org-objectweb-asm" % "7.2"
lazy val configuration = "org.openmole.library" %% "org-apache-commons-configuration2" % "2.2"
lazy val configuration = "org.openmole.library" %% "org-apache-commons-configuration2" % "2.6"
lazy val json4s = "org.openmole.library" %% "org-json4s" % json4sVersion
lazy val circe = "org.openmole.library" %% "io-circe" % circeVersion
lazy val scalajsTools = "org.openmole.library" %% "scalajs-tools" % scalajsVersion
......
......@@ -79,7 +79,6 @@ trait RESTAPI extends ScalatraServlet with ContentEncodingSupport
}
post("/start") {
authenticate()
(params get "script") match {
case None ExpectationFailed(Error("Missing mandatory script parameter.").toJson)
case Some(script)
......@@ -134,7 +133,6 @@ trait RESTAPI extends ScalatraServlet with ContentEncodingSupport
}
post("/download") {
authenticate()
getExecution { ex
val path = (params get "path").getOrElse("")
val file = ex.workDirectory.workDirectory / path
......@@ -155,12 +153,10 @@ trait RESTAPI extends ScalatraServlet with ContentEncodingSupport
}
post("/output") {
authenticate()
getExecution { ex Ok(Output(ex.workDirectory.readOutput).toJson) }
}
post("/state") {
authenticate()
getExecution { ex
val moleExecution = ex.moleExecution
val state: State = (moleExecution.exception, moleExecution.finished) match {
......@@ -191,7 +187,6 @@ trait RESTAPI extends ScalatraServlet with ContentEncodingSupport
}
post("/remove") {
authenticate()
getId {
moles.remove(_) match {
case None ExpectationFailed(Error("Execution not found").toJson)
......@@ -205,7 +200,6 @@ trait RESTAPI extends ScalatraServlet with ContentEncodingSupport
}
post("/list") {
authenticate()
Ok(moles.getKeys.toSeq.toJson)
}
......@@ -223,13 +217,4 @@ trait RESTAPI extends ScalatraServlet with ContentEncodingSupport
case Success(id) success(ExecutionId(id))
}
def authenticate()(implicit r: HttpServletRequest) = {
def fail = halt(401, Error("This service requires a valid token").toJson)
Try(params("token")(r)) match {
case Failure(_) fail
case Success(k) if (!checkToken(k)) fail
}
}
}
......@@ -47,26 +47,16 @@ class RESTLifeCycle extends LifeCycle {
}
class RESTServer(sslPort: Option[Int], hostName: Option[String], services: Services, subDir: Option[String]) {
class RESTServer(port: Option[Int], hostName: Option[String], services: Services, subDir: Option[String]) {
private lazy val server = {
val sslP = sslPort getOrElse 8443
val portValue = port getOrElse 8080
val server = new Server()
logger.info(s"binding HTTP REST API to port $portValue")
val contextFactory = new org.eclipse.jetty.util.ssl.SslContextFactory()
def keyStorePassword = "openmole"
val ks = KeyStore(services.workspace.persistentDir / "keystorerest", keyStorePassword)
contextFactory.setKeyStore(ks.keyStore)
contextFactory.setKeyStorePassword(keyStorePassword)
contextFactory.setKeyManagerPassword(keyStorePassword)
contextFactory.setTrustStore(ks.keyStore)
contextFactory.setTrustStorePassword(keyStorePassword)
logger.info(s"binding https to port $sslP")
val connector = new org.eclipse.jetty.server.ServerConnector(server, contextFactory)
connector.setPort(sslP)
val connector = new org.eclipse.jetty.server.ServerConnector(server)
connector.setPort(portValue)
server.addConnector(connector)
val context = new WebAppContext()
......@@ -75,22 +65,22 @@ class RESTServer(sslPort: Option[Int], hostName: Option[String], services: Servi
context.setBaseResource(Res.newResource(classOf[RESTServer].getClassLoader.getResource("/")))
context.setClassLoader(classOf[RESTServer].getClassLoader)
hostName foreach (context.setInitParameter(ScalatraBase.HostNameKey, _))
context.setInitParameter("org.scalatra.Port", sslP.toString)
context.setInitParameter("org.scalatra.Port", portValue.toString)
context.setInitParameter(ScalatraBase.ForceHttpsKey, true.toString)
context.setAttribute(RESTLifeCycle.arguments, RESTLifeCycle.Arguments(services))
context.setInitParameter(ScalatraListener.LifeCycleKey, classOf[RESTLifeCycle].getCanonicalName)
context.addEventListener(new ScalatraListener)
val constraintHandler = new ConstraintSecurityHandler
val constraintMapping = new ConstraintMapping
constraintMapping.setPathSpec("/*")
constraintMapping.setConstraint({
val r = new org.eclipse.jetty.util.security.Constraint(); r.setDataConstraint(1); r
})
constraintHandler.addConstraintMapping(constraintMapping)
context.setSecurityHandler(constraintHandler)
// val constraintHandler = new ConstraintSecurityHandler
// val constraintMapping = new ConstraintMapping
// constraintMapping.setPathSpec("/*")
// constraintMapping.setConstraint({
// val r = new org.eclipse.jetty.util.security.Constraint(); r.setDataConstraint(1); r
// })
// constraintHandler.addConstraintMapping(constraintMapping)
//
// context.setSecurityHandler(constraintHandler)
server.setHandler(context)
server
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment