Reputation: 652
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
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