读书人

《Spring Security3》第八章第三一部分

发布时间: 2012-09-21 15:47:26 作者: rapoo

《Spring Security3》第八章第三部分翻译(属性交换)

?

属性交换(Attribute Exchange)


?AX属性值(如果provider提供的话)将会与其它的OpenID响应一起返回,并作为一个o.s.s.openid.OpenIDAttribute列表(list)插入到OpenIDAuthenticationToken中。

<openid-login authentication-failure-handler-ref="openIdAuthFailureHandler"> <attribute-exchange> <openid-attribute name="email" type="http://schema.openid.net/contact/email" required="true"/> </attribute-exchange></openid-login>


?请求的属性一旦被提供者返回,那在OpenIDAuthenticationToken就可用了(在成功认证的请求中),是以键值对的方式存在而名字(即键)就是在<openid-attribute>中声明的。这就取决于我们的站点来检查这些数据并对其进行处理。一般来说这些数据能够要在填充用户简介或用户注册表单上。

request.getSession(true).setAttribute("USER_OPENID_CREDENTIAL", ((UsernameNotFoundException)exception).getExtraInformation());OpenIDAuthenticationToken openIdAuth = (OpenIDAuthenticationToken)exception.getAuthentication();for(OpenIDAttribute attr : openIdAuth.getAttributes()) { System.out.printf("AX Attribute: %s, Type: %s, Count: %d\n", attr.getName(), attr.getType(), attr.getCount()); for(String value : attr.getValues()) { System.out.printf(" Value: %s\n", value); }}redirectStrategy.sendRedirect(request, response, "/registrationOpenid.do");

AX Attribute: email, Type: http://schema.openid.net/contact/email, Count: 1 Value: peter@mularien.comAX Attribute: birthDate, Type: http://schema.openid.net/birthDate, Count: 1 Value: 1968-04-13AX Attribute: namePerson, Type: http://schema.openid.net/namePerson, Count: 1 Value: Peter MularienAX Attribute: nickname, Type: http://schema.openid.net/namePerson/friendly, Count: 1 Value: pmularienAX Attribute: country, Type: http://schema.openid.net/contact/country/home, Count: 1 Value: US

?我们可以看到AX数据能够很容易从OpenID提供者那里得到,并且支持通过简单API调用访问。在典型的应用场景下,如前面所讨论,AX信息会用在注册时填入用户基本信息或偏好信息,节省了用户重复键入OpenID简介中已包含的信息。

<form action="j_spring_openid_security_check" method="post"> <input name="openid_identifier" size="50" maxlength="100" type="hidden" value="https://www.google.com/accounts/o8/id"/> <input type="submit" value="Sign in with Google"/></form>


?在Google登录过程完成后,用户的OP-Local Identifier会被返回,并且注册/登录能像其它OpenID提供者一样处理。

OpenID安全吗?

最可能的一种攻击方式可能会导致一个用户交互可能是中间攻击(man-in-the-middle attack)——在这里恶意用户拦截了用户电脑和OpenID提供者的交互。假设的攻击者在一个地方记录用户浏览器和OpenID的会话,并记录下请求初始化的密钥。在这种情况下,需要攻击者有很高的水平和相当完整的OpenID签名规则实现——简言之,在正常情况下这不会发生。

注意的是,尽管openid4java库支持使用JDBC持久化当前时间(nonce)跟踪,但是SpringSecurity OpenID当前没有作为一个配置属性暴露——所以当前时间只能在内存中跟踪。这意味着一个重复攻击可能在服务器重启后或集群环境下发生,在这里内存存储没有在不同服务器的JVM间复制。

小结

???????? 在本章中,我们了解了OpenID——一个相对很新的技术用来进行用户认证的凭证管理。OpenID在web中应用广泛,在最近一两年中在可用性和接受程度上发展迅速。现代web中大多数面向公众的站点都应该规划一些OpenID支持功能,JBCP Pets也不例外。

???????? 在本章中,我们:

l? 学习了OpenID认证机制并探究了它的整体结构和术语;

l??利用JBCP ?Pets站点,实现了OpenID的登录和自动用户注册功能;

l? 通过使用属性交换(AttributeExchange ,AX),了解了OpenID未来的基本信息管理;

l? 检查了OpenID登录响应的安全性。

???????? 在本章中,我们涉及到大多数常用基于web的外部认证方法。在下一章中,我们将会介绍一种最常用的基于目录的企业认证方式:LDAP。在我们要转到下一章的时候,请观察外部和内部认证机制的区别以及相似之处。

?

?

?

读书人网 >编程

热点推荐