启动Tomcat时,我会得到这个错误:
对于具有/*模式的安全约束,HTTP是不公开的。
这是什么原因?
我认为这是一个与this不同的问题。
我的web.xml看起来像:
<security-constraint>
<display-name>Restrict resources</display-name>
<web-resource-collection>
<web-resource-name>/resources dir</web-resource-name>
<url-pattern>/resources/*</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Whitelist</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method-omission>GET</http-method-omission>
<http-method-omission>POST</http-method-omission>
</web-resource-collection>
<auth-constraint />
</security-constraint>因此,我试图禁止除GET和POST以外的所有方法(请参阅)。然而,一些方法(PUT,DELETE,OPTIONS.)似乎返回了一个"302 Found“而不是一个自动403,不知道为什么(缺少请求参数?)
发布于 2020-01-30 09:06:07
在我看来,您实际上也禁止GET和POST。在第二个<auth-constraint />部分中,不要使用空的<security-constraint>,而是尝试以下操作:
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>此外,您可能需要为<url-pattern>/*</url-pattern>的未发现方法添加另一个“拒绝”部分。但是,如果您使用的是Servlet 3.1+ (例如Tomcat8.5.x),您可以简单地使用这个标记,而不是使用另一个<security-constraint>部分:
<deny-uncovered-http-methods />然后,确保您的web.xml确实定义了Servlet3.1,例如:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">https://stackoverflow.com/questions/56257890
复制相似问题