我正在使用 spring security 3.0.2 和 OpenId 登录和注册来实现一个应用程序。
我可以成功登录,但如果用户未注册,我想要执行以下操作:
1) 获取一些 OpenId 属性,例如电子邮件和姓名。
2) 向用户显示仅包含这两个字段和填写的 OpenId URI 的注册表单。
我已经搜索了很多,但没有找到一种“优雅”的方法来做到这一点。
我想知道你们中的一些人是否可以提出一个解决方案来在我的应用程序中实施此策略。
提前致谢。
在用户自己注册/登录之前,您无法显示电子邮件和姓名,因为他必须首先允许应用程序访问他的个人资料。您可以向他显示此页面以及他的 openid、邮件等after他登录了。
定义您要使用的属性:
<openid-login login-page="/openidlogin.jsp" authentication-failure-url="/openidlogin.jsp?login_error=true">
<attribute-exchange>
<openid-attribute name="email" type="http://schema.openid.net/contact/email" required="true" count="2"/>
<openid-attribute name="name" type="http://schema.openid.net/namePerson/friendly" />
</attribute-exchange>
</openid-login>
然后在用户登录后访问属性:
OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)SecurityContextHolder.getContext().getAuthentication();
List<OpenIDAttribute> attributes = token.getAttributes();
看看来自 spring 存储库的示例,以及OpenId 支持文档.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)