开发者

Lift filter to force ssl

开发者 https://www.devze.com 2023-01-04 20:03 出处:网络
in a struts application, I have a filter that forces certain pages to be accessed only over https via redirection. I\'m thin开发者_如何学Goking in porting it to lift so my question is: In the this env

in a struts application, I have a filter that forces certain pages to be accessed only over https via redirection. I'm thin开发者_如何学Goking in porting it to lift so my question is: In the this environment, is there a "lift" way to implement such filter or is it similar/the same as in struts ? Thanks


In Lift, the SiteMap defines the rules for page access. You can create a SiteMap entry that does a Redirect to the https site on certain pages:

// create an object that does a redirect to the https server if the
// request is on http
object RequireSSL extends Loc.EarlyResponse(
  () => {
    for {
      r <- S.request
      lowLevelReq <- Box !! r if lowLevelReq.scheme == "http"
    } {
      S.redirectTo("https://"+lowLevelReq.serverName+lowLevelReq.contextPath)
    }
    Empty
  })

// Build SiteMap
def entries = (Menu("Home") / "index") ::
(Menu("Secure") / "secure" >> RequireSSL) ::
Nil

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消