TOMCAT中添加DIGEST认证
1、修改web.xml文件
1 <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
4 version="2.4">
5 …略…
6 <security-constraint>
7 <web-resource-collection>
8 <web-resource-name>TOMCAT DIGEST</web-resource-name>
9 <url-pattern>/*</url-pattern>
10 </web-resource-collection>
11 <auth-constraint>
12 <role-name>digestdemo</role-name>
13 </auth-constraint>
14 </security-constraint>
15
16 <login-config>
17 <auth-method>DIGEST</auth-method>
18 <realm-name>TOMCAT DIGEST example</realm-name>
19 </login-config>
20
21 <security-role>
22 <role-name>digestdemo</role-name>
23 </security-role>
24 …略…
25 </web-app>
2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
4 version="2.4">
5 …略…
6 <security-constraint>
7 <web-resource-collection>
8 <web-resource-name>TOMCAT DIGEST</web-resource-name>
9 <url-pattern>/*</url-pattern>
10 </web-resource-collection>
11 <auth-constraint>
12 <role-name>digestdemo</role-name>
13 </auth-constraint>
14 </security-constraint>
15
16 <login-config>
17 <auth-method>DIGEST</auth-method>
18 <realm-name>TOMCAT DIGEST example</realm-name>
19 </login-config>
20
21 <security-role>
22 <role-name>digestdemo</role-name>
23 </security-role>
24 …略…
25 </web-app>
2、修改server.xml
1 <!--解开注释-->
2 <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
3 debug="0" resourceName="UserDatabase"/>
4 <!--解开注释-->
5 <Realm className="org.apache.catalina.realm.MemoryRealm" />
2 <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
3 debug="0" resourceName="UserDatabase"/>
4 <!--解开注释-->
5 <Realm className="org.apache.catalina.realm.MemoryRealm" />
3、修改tomcat-users.xml(添加角色)
1 <role rolename="digestdemo"/>
2 <user username="admin" password="admin" roles="digestdemo"/>
2 <user username="admin" password="admin" roles="digestdemo"/>
4、重新启动Tomcat,就会有验证对话框弹出来 输入指定的用户名和密码 就可以通过验证。