Tomcat JSP身份验证失败

时间:2014-03-19 13:46:57

标签: jsp tomcat authentication

我正在运行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>

1 个答案:

答案 0 :(得分:1)

解决方案很简单......

更改tomcat-users.xml后重启Tomcat

现在它按预期工作。