403 Tomcat 8 Manager App 拒绝访问,没有提示 user/password

403 Access Denied on Tomcat 8 Manager App without prompting for user/password

我根据this设置了tomcat8,我有如下tomcat-users.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0"> 
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>

  <user username="notadmin" password="not_real_pass" roles="manager-gui"/>
  <user username="cargo" password="not_real_pass" roles="manager-script"/>
<tomcat-users/>

当我尝试访问 Manager App 时,我被 403 拒绝了,没有任何输入用户名和密码的提示。

我在配置中遗漏了什么?

Edit1:添加了完整的 xml 文件。

将以下内容复制到文件tomcat-users.xml

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
<role rolename="manager-gui"/>
<role rolename="manager-script"/>

<user username="notadmin" password="not_real_pass" roles="manager-gui"/>
<user username="cargo" password="not_real_pass" roles="manager-script"/>


</tomcat-users>

我已经测试过了,它很好用!


可以找到正确答案


看起来这个问题可以在 unix 机器上按照提到的教程重现。还注意到作者使用 TC 8.0.33
Win(和 OSX)没有这样的问题,至少在我的环境中:

Server version:        Apache Tomcat/8.5.4
Server built:          Jul 6 2016 08:43:30 UTC
Server number:         8.5.4.0
OS Name:               Windows 8.1
OS Version:            6.3
Architecture:          amd64
Java Home:             C:\TOOLS\jdk1.8.0_101\jre
JVM Version:           1.8.0_101-b13
JVM Vendor:            Oracle Corporation
CATALINA_BASE:         C:\TOOLS\tomcat\apache-tomcat-8.5.4
CATALINA_HOME:         C:\TOOLS\tomcat\apache-tomcat-8.5.4

添加角色修改tomcat-users.xml后,可在Tomcat/8.5.4上访问用户Tomcat Web Application Manager

这可能是工作。

找到 CATALINA_HOME/webapps/manager/META-INF/context.xml 文件并在 Valve 周围添加注释标记。

<Context antiResourceLocking="false" privileged="true" >

<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->

</Context>

You can find more details at this page.

如果以上都不适合您,请确保 tomcat 可以访问 webapps (chown ...) 下的管理器文件夹。该消息是完全相同的消息,我花了 2 个小时才弄清楚问题所在。 :-)

仅供与我遇到同样问题的其他人。

fade 的回答对我有用。我从 8.0.30 移动到 8.5.5,不同之处在于 <8.0.30>/manager/META-INF/context.xml 中的阀门已经被 from 注释掉 tar 文件,但在 8.5.5 tar.

未注释

我未能阅读 403 响应中的这条重要消息:

By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.

也没有读到这个:

Since r1734267 a RemoteAddrValve.is configured by default in Manager and HostManager web applications. This feature is present in 9.0.0.M4 and 8.5.0 onwards.

https://bz.apache.org/bugzilla/show_bug.cgi?id=59672

我愚蠢地取消了默认配置的注释,它有像“”这样的密码。 Tomcat 无法解析此文件(因为“<”),然后您添加的任何其他配置都将不起作用-

对我有用的解决方案是编辑 $CATALINA_HOME/webapps/manager/META-INF$CATALINA_HOME/webapps/host-manager/META-INF 中的 context.xml 文件,其中我的 IP 是 123.123.123.123.

<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|123.123.123.123" />
</Context>

我在 Ubuntu 上安装了 Tomcat 8.5 并编辑了 $CATALINA_HOME/conf/tomcat-users.xml:

<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="myuser" password="mypass" roles="admin-gui,manager-gui"/>

但是,在我编辑 context.xml 文件。

我遵循了相同的教程,但几个月后我在尝试使用 Manager App 时奇怪地收到错误“403 Access Denied”。在这种情况下,我在地址栏中使用 ipaddress:8080,而 Tomcat Manager App 没有提示输入 user/password。在 localhost:8080 的情况下,错误为“401”,显示了要求输入用户名和密码的对话框,但无法识别用户。

我尝试了所有以前的建议/解决方案,但运气不佳。 我找到的唯一方法是再次重复整个教程并覆盖文件。完成后,我再次在 webapps 目录中找到了旧的已部署项目。现在 Apache Tomcat/8.5.16 Manager App 再次运行。我不知道发生了什么,我也不明白,因为我是 Tomcat user

的新手

这里有用link:

从 Tomcat 版本 8 开始,manager/html url 除了 localhost 之外的任何人都无法访问。

为了访问 /manager/html url,您需要在管理器应用程序的 context.xml 中进行以下更改。 1、进入/apache-tomcat-8.5.23/webapps/manager/META-INF位置,然后编辑context.xml

<Context antiResourceLocking="false" privileged="true" >
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="^.*$" />
 ......
</Context>
  1. 重新启动服务器。

我必须同时添加 manager-guimanager-script 角色才能在版本 9 中工作。

获得 MangerApp 的访问权限后,在尝试上传 .war 文件时,出现异常

org.apache.tomcat.util.http.fileupload.FileUploadBase$IOFileUploadException

我能够使用这个 post

的答案解决

要获得 Host Manager 的访问权限,请选中此 post

我在 docker 中安装 tomcat 时遇到了同样的问题。 我通过添加“^.*$”而不是“127.\d+.\d+.\d+|::1|0:0:0:0:0:0:0:1|123.123.123.123”解决了这个问题。 =10=]

重新启动 tomcat。

我要修改以下文件

$CATALINA_BASE/conf/Catalina/localhost/manager.xml 并添加以下行

  <Context privileged="true" antiResourceLocking="false" 
     docBase="${catalina.home}/webapps/manager">
        <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
  </Context>

这将允许从任何机器访问 tomcat,如果您想授予对特定 IP 的访问权限,请使用以下值而不是 allow="^.*$"

    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="192\.168\.11\.234" />

正确答案如@JaKu 指出的那样。 Tomcat 正在限制对 localhost 的访问以确保其安全。这是应该的。将端口转发到 tomcat 是正确的做法,最好是在像 SSH 这样安全的东西下。

在我的例子中,它是 web.xml 中定义的安全约束。确保他们的角色与您在 tomcat-users.xml 文件中使用的角色相同。

例如,这是开箱即用的标签之一,可以与标准 tomcat-users.xml.

一起使用
 <security-constraint>
    <web-resource-collection>
      <web-resource-name>HTML Manager interface (for humans)</web-resource-name>
      <url-pattern>/html/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>manager-gui</role-name>
    </auth-constraint>
  </security-constraint>

在我的例子中,管理员使用了不同的角色名称,这使我无法访问管理器。

  1. 去检查是否创建了用户 如果没有,请通过在 /apache-tomcat-9.0.20/tomcat-users.xml 中打开文件来创建用户 在其中添加一行

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

  2. 转到/apache-tomcat-9.0.20/webapps/manager/META-INF/ 打开 context.xml 注释上下文标记中的所有内容 示例:

<Context antiResourceLocking="false" privileged="true" >
     <!--Valve className="org.apache.catalina.valves.RemoteAddrValve"
            allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /-->
   </Context>
<role rolename="tomcat"/>
  <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-jmx"/>
  <user username="admin" password="admin" roles="tomcat,manager-gui,admin-gui,manager-script,manager-jmx"/>


Close all the session, once closed, ensure open the URL in incognito mode login again and it should start working