Hi,I was hoping to use unfiltered to define a servlet filter that adds a value to the request as a cookie or header which could then be used in front of a servlet to gain access to this value. I'd prefer not to use a session to pass the value. I was thinking something like HttpServletRequestWrapper but I don't see how I could do this with a unfiltered.filter.Plan. I searched on variants of 'unfiltered wrap http request' but didn't find a similar scenario. Does anyone know if something like this is possible?
--Thanks -Scott
You received this message because you are subscribed to the Google Groups "Unfiltered" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unfiltered-sca...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for the reply but req is a unfiltered.request.HttpRequest and can't be wrapped by HttpServletRequestWrapper, right? I'm sure there's some way..
p.intent.lift(new RequestBinding(newReq)).getOrElse(Pass), but I'm still trying to wrap my head around how this would work
case class MyPrincipal(user: String) extends Principal { def getName = user; }def getUser(cookie: String): Option[String] = Some("dummyUser")val userAuthPlan = new PlanWithRequestSwap {def intent = {case req @ Cookies(cookies) => cookies(authCookieName) match {case Some(Cookie(_,authToken,_,_,_,_,_,_)) => getUser(authToken) match {case Some(user) =>println("got user: "+ user)RequestSwap(new RequestBinding(new HttpServletRequestWrapper(req.underlying) {override def getUserPrincipal = new MyPrincipal(user)}))case _ => Unauthorized}case _ => Unauthorized}}}
val userProtectedPlan = Planify {case req => req.underlying.getUserPrincipal match {case MyPrincipal(user) => req match {case Path("/userProtected") => HtmlBody(s"get protected as $user")}case x => Unauthorized ~> HtmlBody(s"Unrecognized principal: $x")}}
case class RequestSwap(req: RequestBinding) extends ResponseFunction[Any] { def apply[T](res: HttpResponse[T]) = res; }trait PlanWithRequestSwap extends Plan {override def doFilter(request: ServletRequest,response: ServletResponse,chain: FilterChain) {(request, response) match {case (hreq: HttpServletRequest, hres: HttpServletResponse) =>val request = new RequestBinding(hreq)val response = new ResponseBinding(hres)intent.lift(request) match {case Some(rf:RequestSwap) => chain.doFilter(rf.req.underlying, response.underlying)case Some(Pass) | None => chain.doFilter(request.underlying, response.underlying)case Some(rf) => rf(response).outputStream.close()}}}}I can run a server like the following but it will ultimately be exported as a servlet filter in front of more traditional java web apps:val publicPlan = Planify {case Path(Seg("setc"::name::value::Nil)) => SetCookies(Cookie(name, value, path=Some("/"))) ~> HtmlBody(s"set $name=$value")}unfiltered.jetty.Server.local(9080).plan(publicPlan).plan(userAuthPlan).plan(userProtectedPlan).run()The full file is https://gist.github.com/scottstewartt/5a0d47d11c8d21dd062b and thanks again for your help and please don't hesitate to point out problems-Scott