JSP Tomcat安全性约束始终失败

时间:2017-06-13 13:15:56

标签: java jsp tomcat security-constraint

我的web.xml中有以下内容

<security-constraint>
    <web-resource-collection>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>rolename</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
</login-config>
<security-role>
    <role-name>rolename</role-name>
</security-role>

并且在我的tomcat-users.xml文件中也有以下内容:

<role rolename="rolename"/>
<user username="username" password="password" roles="rolename"/>

当我尝试导航到我的localhost网站时,会出现“需要验证”对话框,但即使我输入了正确的凭据,对话框也会刷新,没有任何反应。

为什么这不起作用?似乎不像auth方法所暗示的那样基本。

2 个答案:

答案 0 :(得分:1)

设置看起来正确,当您在添加服务器时使用Netbeans时,您可以在manager或manager-script角色中配置现有用户和密码,例如,如果您有:

 

enter image description here

如果您使用嵌入Netbeans的Tomcat服务器,则存在Tomcat文件的缓存位置,例如:

C:\用户\用户\应用程序数据\漫游\的NetBeans \ 8.2 \ Apache的Tomcat的8.0.27.0_base \ CONF

enter image description here

如果您使用Eclipse IDE,则缓存文件tomcat将保留在文件夹中:

C:\ projects \ workspace \ Servers \ Tomcat v8.5服务器在localhost-config

enter image description here

答案 1 :(得分:0)

也许您忘记将security-role标记放在security-constraint标记的级别。

unordered_set

在这里查看示例

inline button