Implementation of basic HTTP authentication in Tomcat

Source: Internet
Author: User
Tags http authentication

1 , implement basic validation

(1) Add roles and users to the Tomcat-users.xml file under C:\jakarta-tomcat-5.0.19\conf (multiple users can be added at the same time)

<role rolename= "Users"/>

<user name= "Yang" password= "12345678" roles= "Users"/>

<user name= "Zhang" password= "12345678" roles= "Users"/>

(2) Add the following items to the Web. xml file

<?xml version= "1.0" encoding= "Iso-8859-1"?>

<! DOCTYPE Web-app

Public "-//sunmicrosystems, INC.//DTD Web application 2.3//en"

"Http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>

.....

<security-constraint>

<web-resource-collection>

<web-resource-name>

Protected Resource

</web-resource-name>

<url-pattern>/BasicVerify/*</url-pattern>

</web-resource-collection>

<auth-constraint>

<role-name>users</role-name>

</auth-constraint>

</security-constraint>

<login-config>

<auth-method>BASIC</auth-method>

<realm-name>Default</realm-name>

</login-config>

<security-role>

<description>this is a user</description>

<role-name>users</role-name>

</security-role>

.....

</web-app>

(3) Restart the Tomcat server

and enter the protected directory http://127.0.0.1:8080/WebMis/BasicVerify directly in the browser, the following login page appears

Enter user name: Yang (see the settings for the previous Tomcat-users.xml file)

Password: 12345678




The following will appear:


If there is an error in the user name or password, the input is forced.

Implementation of basic HTTP authentication in Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.