无法查看Tomcat的服务器状态和管理应用页面:为什么它不接受用户名和密码?

5

我无法查看Tomcat中的服务器状态和管理应用程序页面。

enter image description here

尽管我已经在tomcat-users.xml中配置了用户名和密码,但它并不接受这个组合,并显示以下消息:

401 Unauthorized

You are not authorized to view this page. If you have not changed any configuration  files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.

For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.

<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>

Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.

manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only

The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:

Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.
If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.

我编辑了tomcat-users.xml文件并做出如下修改:

  <tomcat-users>
  <role rolename="admin"/>
  <role rolename="admin-gui"/>
  <role rolename="manager"/>
  <role rolename="manager-gui"/>
  <user username="suhail" password="suhail" roles="admin,admin-gui,manager,manager-gui"/>
  </tomcat-users>

我将用户名和密码设置为suhail,为什么它不接受这个组合?

尝试这个:https://dev59.com/HGXWa4cB1Zd3GeqPJhg5#11080899 - alain.janinm
@alain.janinm 我也遇到了同样的问题。我的 tomcat-users.xml 文件看起来像 [这样] 这是我的 tomcat-users.xml 文件的样子)。 - Suhail Gupta
@alain.janinm,你能不能告诉我如何在Windows上做同样的事情? - Suhail Gupta
@SuhailGupta 你确定你编辑的 tomcat-users.xml 文件在 $CATALINA_HOME 引用的文件夹中吗? - alain.janinm
@alain.janinm 是的!我发现问题了。请看我的回答 :) - Suhail Gupta
显示剩余6条评论
6个回答

6
我也曾经遇到过类似的问题。 以下内容适用于我的情况。 将以下内容复制并粘贴到tomcat-users.xml文件中。
<?xml version='1.0' encoding='utf-8'?>

<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
 -->
<role rolename="manager-gui" />
<user username="jeril" password="1" roles="manager-gui"/>
</tomcat-users>

2
将以下代码添加到你的tomcat-users.xml文件中,以检查服务器状态和管理器应用程序。
<user username="username" password="password" roles="admin-gui,manager-gui"/>

更新了tomcat-users.xml文件后,您是否重新启动了Tomcat? - Koti
当然我重启了Tomcat。这是我的tomcat-users.xml文件的样子 - Suhail Gupta

0

提供信息:我在Tomcat 7中遇到了相同的401错误,但它基于一个完全不同的问题,源于从Web复制和粘贴tomcat-users.xml定义:有两种几乎相同的双引号(不同的Unicode字符),因此我忽略了这个问题几个小时!

一种双引号(有效的那种)是直的类型 "(Unicode字符U+0022),另一种(无效的那种)是弯曲或卷曲或斜体或“右侧”类型 ”(Unicode字符U+201D)。

使用正确的双引号取代不正确的双引号后,我的登录工作非常流畅。

提示让我找到这个问题的方法是查看了catalina.out报告的以下错误(注意:在我的tomcat-users.xml文件中,我删除了所有评论,以确保在隔离问题时处理纯XML语句):

SEVERE: Parse Fatal Error at line 4 column 18: Open quote is expected for attribute "{1}" associated with an  element type  "rolename".

在更换错误的引号后,我的登录完美无缺地工作了。


0

这对我起作用了...你只需注意设置用户角色时要小心。某些用户角色不能使用相同的用户名。

例如:

具有manager-gui角色的用户不应该被授予manager-script或manager-jmx角色。 如果通过浏览器访问文本或jmx界面(例如测试,因为这些界面是为工具而不是人类设计的),则必须在之后关闭浏览器以终止会话。

具有admin-gui角色的用户不应该被授予admin-script角色。 如果通过浏览器访问文本界面(例如测试,因为此界面是为工具而不是人类设计的),则必须在之后关闭浏览器以终止会话。

所以这就是我做的,我能够查看所有三个服务器状态、管理应用程序和主机管理器。

希望这可以帮到你。

<tomcat-users>
    <role rolename="admin-gui"/>
    <role rolename="manager-gui" />
    <user username="Your User Name" password="Your Password" roles="manager-gui, admin-gui"/>
</tomcat-users>

请确保关闭Tomcat并重新启动它!!!


0

将以下行复制粘贴到您的tomcat-user.xml文件中,并更改用户名和密码

 <?xml version='1.0'?>
 <tomcat-users>
       <user name="username" password="password" roles="admin-gui,manager-gui" />
 </tomcat-users>

重启Tomcat


0

我从我的IDE (Netbeans) 启动了服务器Tomcat。因此,我必须从Netbeans设置更改配置:

enter image description here

现在它按预期工作了!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接