我正在为我的Struts2应用程序使用Tomcat。web.xml
包含某些条目,如下所示:
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>no_access</web-resource-name>
<url-pattern>/jsp/*</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>no_access</web-resource-name>
<url-pattern>/myrrunner/*</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
如何将上述黑名单部分改为只使用白名单部分…例如,我需要将其他方法列入白名单,而不是将PUT
、DELTE
http方法列入黑名单,但我不确定将它们列入白名单的语法&应该将哪些方法列入白名单。
对于我上面的web.xml
片段,如果有人能为我提供上面xml
的白化对应部分,我将不胜感激。
编辑:另外,我如何真正验证解决方案是否有效?
谢谢
发布于 2011-11-10 04:53:37
我会尝试以下几点:
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<!-- no auth-constraint tag here -->
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
第一个security-constraint
没有任何auth-constraint
,因此任何没有登录的人都可以使用GET和POST方法。第二个限制了所有人都可以使用的其他http方法。(我还没试过。)
发布于 2013-10-22 08:05:30
Java EE 6的新特性简化了应用程序的安全配置。您现在可以在您的web.xml中设置允许的HTTP方法的白名单和黑名单:
<security-constraint>
<web-resource-collection>
<web-resource-name>Disable unneeded HTTP methods by 403 Forbidden them</web-resource-name>
<url-pattern>*</url-pattern>
<http-method-omission>GET</http-method-omission>
<http-method-omission>HEAD</http-method-omission>
<http-method-omission>POST</http-method-omission>
</web-resource-collection>
<auth-constraint />
</security-constraint>
参考:https://docs.oracle.com/cd/E19798-01/821-1841/bncbk/index.html#6nmq2cpkb
发布于 2016-04-20 04:28:11
对接受的答案稍作调整(将第二个security-constraint
中的url-pattern
设置为映射到默认的servlet "/"
)对JBoss和Weblogic有效,但对Websphere无效:
<security-constraint>
<web-resource-collection>
<web-resource-name>Allowed methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<!-- no auth-constraint tag here -->
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Restricted methods</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
有了上面的安全约束配置,我不确定为什么Websphere允许所有的HTTP方法,而JBoss和Weblogic只允许GET
和POST
。
https://stackoverflow.com/questions/8069640
复制相似问题