2010-12-29 2 views
0

어떻게 LiftFilter.doFilter 메서드에서 쿠키를 설정합니까? LiftFilter에서 쿠키 설정

나는 (제거 몇 가지 코드) 다음과 같은 쿠키를 설정하려고 그러나

class AuthenticationFilter extends LiftFilter { 

    override def doFilter(request: ServletRequest, response: ServletResponse , chain: FilterChain) { 

     val cookie = new HTTPCookie("SomeCookie", Full("" + System.nanoTime), Empty, 
     Full("/authentication"), Full(60 * 60 * 24 * 14), Empty, Empty) 
     cookie.setPath("/somePath") 
     S.addCookie(cookie) 

     val httpResp = response.asInstanceOf[HttpServletResponse] 
     httpResp.sendRedirect("/some/page.html") 

    } 
} 

, 내가 브라우저 쿠키를 확인할 때, 어떤 쿠키 (떨어져 JSESSIONID에서) 설정되지 않으며, 내가 doFilter 방법을 알고 로깅 메시지와 브라우저가 /some/page.html로 리디렉션 되었기 때문에 실행되고 있습니다.

저는 Scala 2.8, Lift 2.1-SNAPSHOT을 사용하고 있으며 응용 프로그램은 GAE (1.3.6, 지금까지 dev_appserver에서만 테스트 됨)입니다.

아이디어가 있으십니까? 감사합니다,

게로

+0

:-) 나를 위해 마법처럼

LiftRules.statelessDispatchTable.prepend { case req if !checkReqForCookies(req) =>() => Full(RedirectResponse(whereTo, cookie1, cookie2)) } def checkReqForCookies(in: Req): Boolean { ... do your checks ... } 

작품을 필터에 쿠키를 설정해야합니다. S.cookieValue 메서드를 사용하여 필터의 쿠키를 읽는 데 문제가 있었습니까? 그래서 대신 request.asInstanceOf [HttpServletRequest] .getCookies를 사용한 다음 올바른 쿠키를 선택합니다. 그건 효과가 있을지도 모른다. – Gero

+0

David Pollak과의 대화에서 흥미로운 통찰력을 얻을 수 있다고 생각합니다. http://groups.google.com/group/liftweb/browse_thread/thread/bce3211dc6a39349/af463c988448e592?show_docid=af463c988448e592&pli=1 – thoredge

답변

1

은 내가 same question to the Lift discussion list을 게시 데이비드 폴락은 올바른 방향으로 절 지적했다.

내가 실제로 달성하기를 원하는 것은 쿠키 값 (있는 경우)을 사용하여 사용자의 일부 정보를 검색 할 수 있어야한다는 것입니다. 필터에 쿠키를 설정할 필요는 없지만 데이빗 (David)이 지적한 것처럼 LiftFilter의 사용 자체는 적절했습니다. 당신은 LiftFilter 서브 클래스, 대신 당신의 Boot.scala에서 다음을 수행해서는 안 : 이미 그렇게하지하는 다른 접근 방식을 취함으로써 그것을 해결