xll*_*uch 8 openid authentication spring registration spring-security
我正在使用带有OpenId登录和注册的spring security 3.0.2实现一个应用程序.我可以成功登录,但如果用户没有注册,我想做:
1)获取一些OpenId属性,如电子邮件和名称.
2)向用户显示仅包含这两个字段并填充OpenId URI的注册表单.
我一直在寻找,但我没有找到一种"优雅"的方式来做这件事.我想知道你是否可以在我的应用程序中找到一个解决方案来实现这个策略.
提前致谢.
在用户注册/登录之前,您无法显示电子邮件和姓名,因为他必须先允许该应用访问其个人资料.登录后,您可以使用openid,mail等向他显示此页面.
定义要使用的属性:
<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>
Run Code Online (Sandbox Code Playgroud)
然后在用户登录后访问属性:
OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)SecurityContextHolder.getContext().getAuthentication();
List<OpenIDAttribute> attributes = token.getAttributes();
Run Code Online (Sandbox Code Playgroud)
查看spring存储库和OpenId支持文档中的示例.
| 归档时间: |
|
| 查看次数: |
2433 次 |
| 最近记录: |