gpt4 book ai didi

security - Tomcat 7 - 多个安全约束不起作用

转载 作者:行者123 更新时间:2023-11-28 22:03:46 26 4
gpt4 key购买 nike

运行 Tomcat 7,我正在尝试在 Tomcat 服务器上配置/conf/web.xml 以使用基本身份验证保护一些 URL 并提供一些其他 URL 以供公共(public)访问。

tomcat-users.xml 包含以下角色和用户:

<role rolename="test-ui"/>
<user username="paul" password="password" roles="test-ui"/>

我已将以下部分添加到 Tomcats/conf/web.xml

<security-constraint>
<web-resource-collection>
<web-resource-name>Public access</web-resource-name>
<url-pattern>/docs/*</url-pattern>
</web-resource-collection>
</security-constraint>

<security-constraint>
<web-resource-collection>
<web-resource-name>Protected access</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>test-ui</role-name>
</auth-constraint>
</security-constraint>

<security-role>
<description>Protected access</description>
<role-name>test-ui</role-name>
</security-role>

<login-config>
<auth-method>BASIC</auth-method>
</login-config>

所以有两个“security-constraint”元素,public 元素不包含“auth-constraint”,这实际上应该意味着不需要身份验证。

当我打开网址时 http://localhost:8080

Tomcat 要求进行身份验证。这很好,但是当我打开 URL 时 http://localhost:8080/docs/

Tomcat 还要求进行身份验证,据我所知,这被配置为“非安全”URL - 因此可以公开访问,但它的行为并不像这样。

我在配置中做错了什么,或者这个场景不应该像这样工作吗?

谢谢。保罗

最佳答案

您需要 中的 节点,即使它是空的,例如

关于security - Tomcat 7 - 多个安全约束不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9432710/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com