Lift filter to force ssl

后端 未结 1 2085

in a struts application, I have a filter that forces certain pages to be accessed only over https via redirection. I\'m thinking in porting it to lift so my question is: In the

相关标签:
1条回答
  • 2021-02-10 12:22

    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 讨论(0)
提交回复
热议问题