【问题标题】:How to fix tomcat HTTP status 403 : access denied如何修复 tomcat HTTP 状态 403:访问被拒绝
【发布时间】:2018-07-19 02:43:50
【问题描述】:

我使用eclipse制作了一个简单的表单认证tomcat,其中需要名称和密码才能访问。但是,当我将用户名和密码放入文件 tomcat-users.xml 时,我收到错误 HTTP 状态 403,这意味着访问被拒绝。

我猜问题出在 web.xml 或 server.xml 中。我知道错误不在 tomcat-users.xml 中,因为我尝试了所有方法,但总是遇到相同的错误。

文件 web.xml 中相对于我的 TestServlet 的脚本是:

<servlet>
        <servlet-name>TestServlet</servlet-name>
        <servlet-class>test.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Wildcard means whole app requires authentication</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>

        <auth-constraint>
            <role-name>tomcat</role-name>
        </auth-constraint>


    </security-constraint>

    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.html</form-login-page>
            <form-error-page>/login-failed.html</form-error-page>
        </form-login-config>
    </login-config>

PS:当我输入错误的凭据时,我得到页面 login-failed.html,所以当我输入错误的凭据时一切正常。 PS:文件tomcat-users.xml中的代码是:

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

有人可以帮我找出问题吗?

【问题讨论】:

    标签: java xml eclipse tomcat http-status-code-403


    【解决方案1】:

    U 解压它并尝试通过调用 localhost:8080 来访问它并提供登录凭据,但无法正确登录。意味着您无权访问该 gui。因此您必须手动编辑 XML 文件并修改这样的脚本才能访问 gui。在那之后,我希望它一定会起作用

    添加以下脚本

        <tomcat-users>
          <role rolename="manager-gui"/>
       <role rolename="manager-jmx"/>
       <role rolename="manager-status"/>
       <user username="admin" password="admin" 
         roles="manager-gui,manager-status"/>
        </tomcat-users>
    
        manager-gui — Access to the HTML interface.
    

    【讨论】:

      【解决方案2】:

      在 auth-constraint 中,您已经配置了“tomcat”角色。您的 tomcat-users.xml 文件中缺少此角色。

      【讨论】:

        猜你喜欢
        • 2011-08-14
        • 2017-03-23
        • 2015-12-05
        • 2020-01-25
        • 2015-12-03
        • 2013-10-19
        • 2019-11-06
        • 1970-01-01
        • 2015-09-07
        相关资源
        最近更新 更多