小编典典

web.xml中的白名单安全性约束

tomcat

我在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>

我怎样才能改变上述列入黑名单的部分只使用白名单的一部分…例如,而不是列入黑名单PUTDELTEHTTP方法,我需要白名单等方法,但我不知道他们列入白名单,和什么样的方法来白名单它们的语法。

对于我上面的web.xml摘录,如果有人可以为我提供上述内容,我将不胜感激xml

编辑:另外,我将如何真正验证该解决方案是否有效?

谢谢


阅读 1054

收藏
2020-06-16

共1个答案

小编典典

我会尝试以下方法:

<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方法。(我还没有尝试过。)

2020-06-16