To perform basic authentication is a username/password mechanism, when a browser accesses a protected resource, the server requires a user name and password, and only a valid user name and password are entered. Server to send resources. The user name and password can be stored in the security domain. A security domain is a "database" that identifies a legitimate user name and password for a Web application, and it also contains user-related roles.
Example: Login with basic and Memoryrealm
1./conf/tomcat-users.xml under Tomcat defines roles and users, and some roles
<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" >
<user username= "li" password= "123456" roles= "Admin-gui,manager-gui"/>
<role rolename= "Manager"/>
<user username= "admin" password= "123456" roles= "manager"/>
</tomcat-user>
2. The following is defined in Web. xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>adminResource</web-resource-name>
<url-pattern>/AccountServlet</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>allManager</description>
<role-name>manager</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>test</realm-name>
</login-config>
<security-role>
<role-name>manager</role-name>
</security-role>
Where <security-constraint> tags are set to protected resources and accessible user roles;
<login-config> is the authentication mechanism that accesses the protected resource, the popup dialog box differs, and its <realm-name>test</realm-name>; is the name of the security domain displayed in the popup dialog box
<security-role> is used to define, use the role
This protects the resource and, when accessing the resource, enters the previously defined user in the dialog box that pops up, and the password can be accessed
Security constraint--basic validation for Java web