标签:tomcat 安全认证 tomcat安全机制
设置 tomcat-user.xml
<?xml version=‘1.0‘ encoding=‘utf-8‘?> <tomcat-users> <role rolename="yy_role"/> <user username="yyadmin" password="yyadmin" roles="yy_role"/> </tomcat-users>
自己的工程下设置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>app</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <security-constraint> <web-resource-collection> <web-resource-name>force login</web-resource-name> <!-- Define the context-relative URL(s) to be protected --> <url-pattern>/*</url-pattern> <!-- If you list http methods, only those methods are protected --> </web-resource-collection> <auth-constraint> <!-- Anyone with one of the listed roles may access this area --> <role-name>yy_role</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>force login</realm-name> </login-config> <!-- Security roles referenced by this web application --> <security-role> <role-name>yy_role</role-name> </security-role> </web-app>
测试:要加密的项目
测试:确认不影响网站其他项目
本文出自 “好大的刀” 博客,请务必保留此出处http://53cto.blog.51cto.com/9899631/1754424
标签:tomcat 安全认证 tomcat安全机制
原文地址:http://53cto.blog.51cto.com/9899631/1754424