Commit 7c82b4bf authored by Julien Perret's avatar Julien Perret

auth schemes

parent 9c460a4a
package org.openmole.gate.server
import org.openmole.gate.server.Data.User
import org.scalatra._
import org.scalatra.auth.{ScentryConfig, ScentrySupport}
import org.scalatra.auth.strategy.BasicAuthSupport
import org.scalatra.auth.strategy.{BasicAuthStrategy, BasicAuthSupport}
import server.DBStrategy
import scala.concurrent.duration._
......@@ -20,8 +21,9 @@ object AutowireServer extends autowire.Server[String, upickle.default.Reader, up
class Servlet extends ScalatraServlet with AuthenticationSupport {
val basePath = "shared"
get("/") {
val user: User = auth("DB").get
contentType = "text/html"
tags.html(
tags.head(
......@@ -30,7 +32,7 @@ class Servlet extends ScalatraServlet with AuthenticationSupport {
tags.script(tags.`type` := "text/javascript", tags.src := "js/gate.js")
),
tags.body(
div("authenticated: " + basicAuth),
div("authenticated: " + user.login),
script("client.Gate.run();")
)
)
......@@ -77,4 +79,16 @@ trait AuthenticationSupport extends ScentrySupport[Data.User] with BasicAuthSupp
scentry.register("DB", app new DBStrategy(app, realm))
}
def auth(sch:String) = {
val baReq = new BasicAuthStrategy.BasicAuthRequest(request)
if (!baReq.providesAuth) {
response.setHeader("WWW-Authenticate", "Basic realm=\"%s\"" format realm)
halt(401, "Unauthenticated")
}
if (!baReq.isBasicAuth) {
halt(400, "Bad Request")
}
scentry.authenticate(sch)
}
}
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