我正在使用 Spring-Security 的 Openid 通过 google 进行身份验证。我想从谷歌服务器接收电子邮件 ID。所以在我的 spring-security.xml 中我已经设置了
<attribute-exchange>
<openid-attribute name="email" type="http://schema.openid.net/contact/email" required="true" />
<openid-attribute name="name" type="http://schema.openid.net/namePerson/friendly" />
</attribute-exchange>
现在我想得到它。据我了解,文档告诉我们使用以下代码。
OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)SecurityContextHolder.getContext().getAuthentication();
List<OpenIDAttribute> attributes = token.getAttributes();
任何人都可以给我编写代码片段以使用此代码取出电子邮件属性吗???
最佳答案
您可以遍历属性列表来查找电子邮件地址,如 the OpenID sample application does .
或者,您可能希望更仔细地遵循示例并使用自定义 UserDetailsService
来创建专门的 UserDetails
实例,然后您可以在应用程序中的其他位置访问该实例。
关于java - Spring Openid、OpenIDAuthenticationToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17481140/