Platon Efimov
Platon Efimov

Reputation: 652

How to configure basic authentication in tomcat 8.5? HTTP Error 401

I'm trying to secure my web application in tomcat with web.xml and tomcat-users.xml but it's not working. I've getting 401 error with the correct login and password.

My web.xml security part:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Web Application</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>myuser</role-name>
    </auth-constraint>
</security-constraint>

<security-role>
    <role-name>myuser</role-name>
</security-role>

<login-config>
    <auth-method>BASIC</auth-method>
</login-config>

My 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="myuser"/>
    <role username="myuser" password="myuser" role="myuser"/>

</tomcat-users>

Upvotes: 1

Views: 4088

Answers (1)

JUAN CALVOPINA M
JUAN CALVOPINA M

Reputation: 3955

I think it missing the http-methods, so you can try adding this:

<http-method>GET</http-method>
<http-method>POST</http-method>

after of <url-pattern>/*</url-pattern> tag

UPDATE

Update your tomcat-users.xml file, change this:

<role username="myuser" password="myuser" role="myuser"/>

for this:

<user username="myuser" password="myuser" role="myuser"/>

Upvotes: 1

Related Questions