2014-08-28 75 views
3

了Java Servlet 3.0和3.1規範允許開發人員能夠執行許多在Java代碼中常見的配置基礎任務,而不是通過提供一個web.xml文件的傳統機制。的Servlet 3.1 - 安全約束 - 如果沒有web.xml中

我這一切對我的應用程序的工作,但在尋找解決應用安全,我找不到它可能還配置應用程序安全性約束通過代碼如何,或者如果任何引用。

基本上,我正在尋找一個綱領性的方式來做到以下幾點:

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>my-secure-webapp</web-resource-name> 
     <url-pattern>/*</url-pattern> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>SSORole</role-name> 
    </auth-constraint> 
</security-constraint> 
<login-config> 
    <auth-method>CLIENT-CERT</auth-method> 
</login-config> 
<security-role> 
    <role-name>SSORole</role-name> 
</security-role> 

是任何人都知道的手段來做到這一點?

謝謝

回答

5

你會發現在馬克提供的部分細節,但對於短手,你可以把你的servlet是這樣的:

@ServletSecurity((httpMethodConstraints = { 
    @HttpMethodConstraint(value = "GET", rolesAllowed = "SSORole"), 
    @HttpMethodConstraint(value = "POST", rolesAllowed = "SSORole", 
    transportGuarantee = TransportGuarantee.CONFIDENTIAL) 
}) 

但是仍然有Web模塊的安全使用註釋的一些缺點:

  • url-pattern會直接匹配到你的servlet映射 - 不能爲整個應用程序定義/*喜歡通過web.xml
  • unfor tuningly仍然沒有註釋login-config

所以我建議堅持web.xml安全定義一點點。

+2

沒有註釋的登錄,配置!!!!!!誰投了這個規範?! – jplandrain 2016-03-18 13:26:02

0

您需要閱讀Servlet 3規範的第13.4節。