I have a problem with tomcat authentication. I want authenticate a user from a java application with nickname and password I tried to make a post to j_security_check but this does not work. Can anyone help me?
This guy's blog has a link to a file with some java form login examples, perhaps they will help you.
Easiest way to do a basic authentication like mentioned above is to do the following things:
1) Inside your TOMCAT_ROOT, there is a directory "conf" which contains a file called tomcat-users.xml. Add a user and a role to this file, eg:
<tomcat-users>
[...]
<role rolename="authuser"/>
<user username="user" password="password" roles="authuser"/>
</tomcat-users>
2) Within your application, you have to reference the defined role to restrict access to resources. To achieve this, add the following code to your WEB-INF/web.xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>Restrict everything</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>authuser</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
3) Restart tomcat, rebuild your application and redeploy it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.