2014-08-28 60 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节。