无法在Tomcat中查看服务器状态,管理器应用程序页面:不接受用户名和密码,为什么会这样?

时间:2012-07-23 11:21:06

标签: java windows tomcat tomcat7 role

我无法在Tomcat中查看服务器状态和Manager App页面。

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。为什么不接受这种组合?

6 个答案:

答案 0 :(得分:5)

我也经常挣扎。 这个对我有用。 将以下内容复制粘贴到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>

答案 1 :(得分:2)

在tomcat-users.xml中添加以下行以检查服务器状态和经理应用程序。

<user username="username" password="password" roles="admin-gui,manager-gui"/>

答案 2 :(得分:0)

复制tomcat-user.xml中的行下面的粘贴并更改用户名和密码

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

重启tomcat

答案 3 :(得分:0)

我从IDE (Netbeans)启动服务器Tomcat。所以,我不得不从Netbeans设置更改配置:

enter image description here

现在它按预期工作了!

答案 4 :(得分:0)

这对我有用......你只需要注意设置用户角色的时间。某些用户角色不能使用相同的用户名。

例如:

  

具有manager-gui角色的用户不应被授予manager-script或manager-jmx角色。   如果通过浏览器访问text或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并重新启动它!!!

答案 5 :(得分:0)

仅供参考:我遇到了同样的401错误(在Tomcat 7中),但它基于一个完全不同的问题,该问题源于从网上复制和粘贴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".

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