http认证(二) - DIGEST 认证

和讲Basic篇的内容差不多,不同的是过程采用的是DIGEST认证:

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

2 在authen目录下建立WEB-INF目录,下放web.xml文件,内容如下

<security-constraint>
<web-resource-collection>
<web-resource-name>
My App
</web-resource-name>
<url-pattern>/subdir/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>test</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>DIGEST</auth-method> <!-- DIGEST here -->
<realm-name>My Realm</realm-name>
</login-config>

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


[b]客户端访问:[/b]
访问http://localhost:port/authen/subdir/index.jsp
会弹出对话框提示认证,输入test test可以登录。
[img]http://dl.iteye.com/upload/attachment/185241/62c76571-fdd2-3d32-a24d-014ab98ae923.jpg[/img]

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

2 服务器发一个401返回,并含有下面的头
[img]http://dl.iteye.com/upload/attachment/185243/1299fe63-d366-3052-9b0f-d1392e6e9f2b.jpg[/img]

3 客户端认证,含有下面的头
[img]http://dl.iteye.com/upload/attachment/185245/cbe8b59c-997c-3f76-9fcd-3c0cdb88a628.jpg[/img]
response="..."就是客户端用来签名的部分。

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

[b]httpclient中的实现[/b]
查看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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值