打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
http认证(二)
     和讲Basic篇的内容差不多,不同的是过程采用的是DIGEST认证:

Tomcat配置:
1 在tomcat的webapps下新建一个目录authen,再建立子目录subdir,下面放一个index.jsp

2 在authen目录下建立WEB-INF目录,下放web.xml文件,内容如下
Xml代码  
  1. <security-constraint>  
  2.     <web-resource-collection>  
  3.         <web-resource-name>  
  4.             My App  
  5.         </web-resource-name>  
  6.         <url-pattern>/subdir/*</url-pattern>  
  7.     </web-resource-collection>  
  8.     <auth-constraint>  
  9.         <role-name>test</role-name>  
  10.     </auth-constraint>  
  11. </security-constraint>  
  12.   
  13. <login-config>  
  14.     <auth-method>DIGEST</auth-method>  <!-- DIGEST here -->  
  15.     <realm-name>My Realm</realm-name>  
  16. </login-config>  

3 在tomcat的tomcat-users.xml文件中添加一个用户名密码为test,test的用户,角色test。


客户端访问:
访问http://localhost:port/authen/subdir/index.jsp
会弹出对话框提示认证,输入test test可以登录。


工作流程(通过firebug可以查看请求头)
1 客户端先发请求(不知道要认证,头里不包含任何特殊信息)

2 服务器发一个401返回,并含有下面的头


3 客户端认证,含有下面的头

response="..."就是客户端用来签名的部分。

缺点:
监听到消息的攻击者可以使用这个消息提交请求。

httpclient中的实现
查看org.apache.commons.httpclient.auth包的DigestScheme类的authenticate方法。

RFC2617描述了计算方法:
A valid response contains a checksum (by default, the MD5 checksum) of the username, the password, the given nonce value, the HTTP method, and the requested URI.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Java Web基础知识之安全:人生苦短,注意安全
tomcat下禁止不安全的http方法
jaas tomcat的实例
HTTP认证及其在Web平台中的实现
HTTP认证方式
HTTP认证之摘要认证
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服