Security constraint--basic validation for Java web

Source: Internet
Author: User

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

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.