Change roles in Tomcat and implement Login verification box function

Source: Internet
Author: User
Tags auth ftp login

In our FTP login will appear a picture of the prompt box, this feature can be configured to implement our files, without the need to write any code.



first, modify the role (add, delete)

Conf/tomcat-users.xml the role of Tomcat, by default admin, manager and other roles, if you want to add a custom role, you can use the form

<user username= "Xiazdong" password= "Xiazdong" roles= "user"/> form, we are now configured with a name of Xiazdong, password is xiazdong, the role is user users.

If you restart Tomcat, a <role rolename= "user"/> statement is automatically generated in Tomcat-users.xml.


II. Implementation of login verification

A write-like form is required in Web-inf/web.xml

	<security-constraint>
		<web-resource-collection>
			<web-resource-name>RegisterUsers<				Location of/web-resource-name> <url-pattern>/demo/security.jsp</url-pattern> <!--validated pages-->
		</web-resource-collection>
		<auth-constraint>
			<role-name>user</role-name>			<!--validation role, do not write user name-->
		</auth-constraint>
	</security-constraint>
	< login-config>
		<auth-method>BASIC</auth-method>			<!--key-->
		<realm-name >registered users</realm-name>
	</login-config>
	<security-role>
		< Role-name>user</role-name>			<!--validation role, do not write user name-->
	</security-role>

Restart Tomcat, you can write a security.jsp verification.

Enter the user name Xiazdong, the password is Xiazdong can log on to the Web page.

If the role is user, you can see the page.

<%@ page contenttype= "text/html" language= "java" pageencoding= "GB2312"%>


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.