Tomcat JSP身份验证失败



我有一个Tomcat 7.0.52服务器正在运行。在它里面有一个文件浏览器(http://www.vonloesch.de/filebrowser.html它有点旧,但它做我需要它做的)

但是,我想要密码保护浏览器,而不是将密码存储为纯文本,所以我更新了Realm部分如下:

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
           digest="SHA-1" digestEncoding="UTF-8"
           resourceName="UserDatabase"/>

文件浏览器安装在${CATALINA_HOME}/webapps/Browser/index.jsp

然后我创建了${CATALINA_HOME}/webapps/Browser/WEB-INF/web.xml文件,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
       version="3.0">
  <display-name>Browser</display-name>
  <description>A JSP file manager for Tomcat</description>
  <!-- Security roles referenced by this web application -->
  <security-role>
    <role-name>browser</role-name>
  </security-role>
  <!-- Define a Security Constraint on this Application -->
  <!-- NOTE:  None of these roles are present in the default users file -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Browser</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>browser</role-name>
    </auth-constraint>
  </security-constraint>
  <!-- Define the Login Configuration for this Application -->
  <login-config>
    <auth-method>BASIC</auth-method>
  </login-config>
</web-app>

最后,我在${CATALINA_HOME}/conf/tomcat-users.xml文件的部分中添加了以下行:

<role rolename="browser"/>
<user username="fadmin" password="...pw hash removed..." roles="browser"/>

Tomcat -users.xml文件还包含访问Tomcat管理器页面的信息。此外,我还检查了我针对Tomcat管理器的web.xml创建的web.xml,并且这些部分看起来非常相似

现在,当我访问Tomcat管理器页面时,我得到一个用户名/密码框,当我输入正确的凭据时,我可以访问管理器页面。但是,当我尝试访问浏览器页面时,我没有得到用户名/密码框,但我立即得到一个403页面,其中包含以下内容:

HTTP Status 403 - Access to the requested resource has been denied
--------------------------------------------------------------------------------
type Status report
message Access to the requested resource has been denied
description Access to the specified resource has been forbidden.

我做错了什么?

根据请求,以下是tomcat-users.xml文件的内容(我省略了注释并删除了密码哈希)

<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="admin-gui"/>
  <role rolename="manager-gui"/>
  <role rolename="manager-status"/>
  <user username="tcadmin" password="...pw hash removed..." roles="tomcat,admin-gui,manager-gui,manager-status"/>
  <role rolename="browser"/>
  <user username="fadmin" password="...pw hash removed..." roles="browser"/>
</tomcat-users>

解决方法很简单......

修改Tomcat -users.xml后重新启动Tomcat

最新更新