SEVERE-对于具有URL模式[/ *]的安全性约束,未发现HTTP方法[POST GET]

问题描述 投票:0回答:1

启动Tomcat时出现此错误:

SEVERE-对于具有URL模式[/ *]的安全性限制,HTTP方法[POST GET]被发现。

这是什么原因?


我认为这是与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>

因此,我尝试禁止GETPOST以外的所有方法(请参阅参考资料)。但是,某些方法(PUTDELETEOPTIONS ...)似乎返回“ 302 Found”而不是自动403,不确定为什么(缺少请求参数?)。

servlets web.xml
1个回答
0
投票

对我来说,您似乎实际上也禁止GETPOST。代替第二个<auth-constraint />部分中的空<security-constraint>,请尝试以下操作:

<auth-constraint>
  <role-name>*</role-name>
</auth-constraint>

此外,对于<url-pattern>/*</url-pattern>的未发现方法,您可能需要添加另一个“拒绝”部分。但是,如果您使用的是Servlet 3.1+(例如Tomcat 8.5.x),则可以简单地使用此标记代替另一个<security-constraint>部分:

<deny-uncovered-http-methods />

然后确保您的web.xml实际上确实定义了Servlet 3.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">
© www.soinside.com 2019 - 2024. All rights reserved.