Java Servlet 3.0 和 3.1 规范允许开发人员在 Java 代码中执行许多常见的基于配置的任务,而不是通过提供 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>
有人知道有办法做到这一点吗?
thanks
您可以在 Mark 提供的部分中找到详细信息,但为了方便起见,您可以在 servlet 中添加如下内容:
@ServletSecurity((httpMethodConstraints = {
@HttpMethodConstraint(value = "GET", rolesAllowed = "SSORole"),
@HttpMethodConstraint(value = "POST", rolesAllowed = "SSORole",
transportGuarantee = TransportGuarantee.CONFIDENTIAL)
})
然而,在 Web 模块安全中使用注释仍然存在一些缺点:
- your
url-pattern
将直接匹配您的 servlet 映射 - 无法定义/*
对于整个应用程序,例如viaweb.xml
- 不幸的是仍然没有注释
login-config
所以我建议坚持web.xml
对于安全定义,需要更长的时间。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)