tomcat配置http digest认证

来源:互联网 发布:淘宝上开网店要钱吗 编辑:程序博客网 时间:2024/05/16 11:17
具体步骤如下:

1、在tomcat服务器下的webapps下新建一个digesttest的文件夹,在该文件夹下新建一个test的文件夹,进入test文件夹,在该文件夹下新建一个index.jsp。(jsp的内容可以随便选择,比如说是一个随意的网页的代码)

2、在digesttest新建一个WEB-INF的文件夹,在该文件夹下新建一个web.xml文件。内容如下所示:

<?xml version="1.0" encoding="UTF-8"?>
< web-app version="2.5"
 xmlns="
http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   <security-constraint> 
    <web-resource-collection> 
        <web-resource-name> 
            My App  
        </web-resource-name> 
        <url-pattern>/test/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
        <role-name>tomcat</role-name> <!-- tomcat中配置的用户角色-->
     </auth-constraint> 
   </security-constraint> 
   <login-config> 
    <auth-method>DIGEST</auth-method>  <!-- DIGEST here --> 
    <realm-name>My Realm</realm-name> 
   </login-config>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
< /web-app>
3、在tomcat\conf下搜索tomcat-users.xml文件,打开编辑,添加一个用户,密码和角色。用户名为:test;密码:test;角色可以是默认的tomcat或者自己定义的。

4、重启tomcat服务器,在地址栏如入http://localhost:8080/digesttest/test/index.jsp。就会弹出来一个对话框,在其中输入你在tomcat-users.xml下新设置的用户名和密码(test,test)。就会跳转到该页面。

0 0
原创粉丝点击