2010-06-28 49 views
5

在一个struts应用程序中,我有一个过滤器强制某些页面只能通过https重定向访问。我正在考虑移植它来解决问题,因此我的问题是:在这种环境中,是否有一种“提升”的方式来实现这样的过滤器,还是与struts中的类似/相同?谢谢电梯过滤器强制ssl

回答

11

在Lift中,SiteMap定义了页面访问的规则。您可以创建一个SiteMap条目,在某些页面上重定向到https网站:

// 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 

希望这有助于。