Search code examples
authenticationtomcat8

Tomcat 8.5 Basic authentication not working with correct username password


Here is my code and the credentials are not working on the pop-up shown on application load.please have a look

tomcat-users.xml

  <?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
        <role rolename="admin"/>
        <user username="admin" password="admin" role="admin"/>
</tomcat-users>

web.xml

 <security-constraint>
    <web-resource-collection>
        <web-resource-name>Web Application</web-resource-name>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
</login-config>
<security-role>
    <role-name>admin</role-name>
</security-role>

Plus this Application is deployed on Heroku, so I might need help with this too


Solution

  • Make sure codes are not commented.

    Also add below line instead of < role rolename="admin"/>

    < role rolename="admin-gui"/>

    < role rolename="manager-gui"/>

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

    restart tomcat and then check