2015-05-21 62 views
-1

我有一個可供用戶登錄的區域的網頁。這個區域Wicket 6.x https與其他主機

www.host.com/mypage/myarea

應該是下HTTPS。

的問題是,我的HTTPS是另一臺主機上運行:

www.something-foo.host.com/mypage/myarea

。 (負載均衡的東西... ???我不知道爲什麼)???我不知道爲什麼)

我的嘗試是用@RequireHttps註釋頁面,比重寫頁面的URL。

但是如何以及在哪裏?有人請舉個例子嗎?

感謝您的幫助。

回答

1

那麼如果你真的想要與Wicket這樣做,你最好的選擇是編寫一個IRequestMapperDelegate的實現並在你的WicketApplication的onInit()進程中設置它們。

爲了給你一個想法如何做到這一點,我已經寫了強姦檢票的HttpsMapper的例子:

setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new HttpsConfig(8080, 8443)) { 
     private final static String SUBDOMAIN = "www.something-foo."; 

     @Override 
     protected Scheme getSchemeOf(Request request) { 
      HttpServletRequest req = (HttpServletRequest) ((WebRequest) request).getContainerRequest(); 
      // well that's basically cheating and not so nice... but we're not allowed to overwrite mapRequest() 
      // but that means that every request that doesn't start with the subdomain will be treated as HTTP aka 
      // insecure. 
      if (req.getServerName().startsWith(SUBDOMAIN) == false) { 
       return Scheme.HTTP; 
      } 

      return super.getSchemeOf(request); 
     } 

     @Override 
     protected String createRedirectUrl(IRequestHandler handler, Request request, Scheme scheme) { 
      // stolen from super implementation 
      HttpServletRequest req = (HttpServletRequest) ((WebRequest) request).getContainerRequest(); 
      String url = scheme.urlName() + "://"; 
      // except the part where we insert the subdomain 
      url += SUBDOMAIN; 
      url += req.getServerName(); 
      if (!scheme.usesStandardPort(getConfig())) { 
       url += ":" + scheme.getPort(getConfig()); 
      } 
      url += req.getRequestURI(); 
      if (req.getQueryString() != null) { 
       url += "?" + req.getQueryString(); 
      } 
      return url; 

     } 
    }); 

根據您的問題,我真的不能確定這是否是一個很好的解決方案。 ..這實際上取決於在Wicket之上有多少框架正在工作。既然你沒有提到別的什麼,我就不會假設。

相關問題