I am using Spring-Security's Openid for authentication using google. I want to recieve the email id from google server. so in my spring-security.xml i have set up
<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>
now I want to get it. I understand that the documentation tells us to use the following code.
OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)SecurityContextHolder.getContext().getAuthentication();
List<OpenIDAttribute> attributes = token.getAttributes();
can anybody write me the code snippet to take out the email attribute using this code???
You can iterate through the list of attributes to find the email address, as the OpenID sample application does.
Alternatively, you might want to follow the sample more closely and use a custom UserDetailsService
which creates specialized UserDetails
instance which you can then access elsewhere in your application.