【发布时间】:2014-03-19 13:46:56
【问题描述】:
我有一个 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 管理器页面的信息。我还检查了我创建的 web.xml 与 Tomcat 管理器的 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 文件的内容(我确实省略了 cmets 并删除了密码哈希)
<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文件的完整内容(仍然可以隐藏哈希)。
-
@MarkThomas,我已在原帖底部添加了 tomcat-users.xml 文件的内容。
-
要求提供完整文件的意义在于,默认情况下所有用户都被注释掉,人们经常会错过这一点。现在您已经删除了我们无法检查是否是问题的 cmets。
-
@MarkThomas,我现在明白你的理由了。幸运的是,正如您在我自己的答案中所读到的,tomcat-users.xml 文件中没有错误。但是感谢您的反馈!
标签: jsp tomcat authentication