0

我正在尝试使用 tomcats 安全约束来保护我的 web 应用程序。因此我添加了一个文件夹“prot”,我想通过 web.xml 中的 url-pattern 来保护。当我将标签更改为<url-pattern>/prot</url-pattern>我的登录页面时没有出现,因此我想要保护的文件。Wehn 我更改了<url-pattern>/*</url-pattern>页面登录页面的路径,但没有在单独的文件中定义任何 javascript(被 tomcat 阻止?)。在上下文中,我添加了路径 /mywebapp/prot。我如何保护文件夹保护?提前致谢!

4

1 回答 1

2

您应该在默认情况下保护您想要的内容并对其不安全。

必须在 web.xml 中从最具体到最通用声明约束,以便您首先匹配最具体的。

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Unsecure resources</web-resource-name>
        <url-pattern>/unsecure</url-pattern>
    </web-resource-collection>
</security-constraint>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Secure resources</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>authenticated</role-name>
    </auth-constraint>
</security-constraint>
于 2012-03-20T17:03:59.857 回答