简体   繁体   English

如何修复tomcat HTTP状态403:访问被拒绝

[英]How to fix tomcat HTTP status 403 : access denied

I made a simple form athentification tomcat using eclipse in which a name and a password is required to access. 我使用eclipse创建了一个简单的形式化tomcat,其中需要输入名称和密码。 However when i put the username and password in the file tomcat-users.xml i get an the error HTTP status 403 which mean the access is denied. 但是,当我将用户名和密码放在文件tomcat-users.xml中时,我收到错误HTTP状态403,这意味着访问被拒绝。

I guess that the problem is in either web.xml or in server.xml. 我猜问题出在web.xml或server.xml中。 I know that the error is not in tomcat-users.xml because i tried everything but i always get the same error. 我知道该错误不在tomcat-users.xml中,因为我尝试了所有操作,但始终遇到相同的错误。

the script in the file web.xml relative to my TestServlet is : 相对于我的TestServlet的文件web.xml中的脚本是:

<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 : when i put wrong credentials i get the page login-failed.html, so everything works well when i put wrong credentials. PS:当我输入错误的凭据时,我得到的页面login-failed.html,因此当我输入错误的凭据时一切正常。 PS : the code in the file tomcat-users.xml is : PS:tomcat-users.xml文件中的代码是:

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

Could someone help me locate the problem please ? 有人可以帮我解决问题吗?

U extract it and try to access it by calling localhost:8080 and give login credentials but can't login right. U解压缩它并尝试通过调用localhost:8080来访问它,并提供登录凭据,但无法正确登录。 Means u have no access to that gui .so u must manually edit XML file and modify the scripts like this for access gui. 意味着您无权访问该gui。因此,您必须手动编辑XML文件并修改此类脚本才能访问gui。 After that I hope it will definitely works 在那之后,我希望它一定会起作用

Add following scripts 添加以下脚本

    <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.

In the auth-constraint, you have configured "tomcat" role. 在auth-constraint中,您已配置“ tomcat”角色。 This role is missing in your tomcat-users.xml file. 您的tomcat-users.xml文件中缺少此角色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM