public UserDetails loadUserDetails ( OpenIDAuthenticationToken token ) { if ( token == null ) { return null ; } User user = new User ( ) ; user . setIdentifier ( token . getIdentityUrl ( ) ) ; user = loadUser ( user ) ; if ( user == null ) { // create new OpenID user String email = "email@domain.com" ; String firstName = null , lastName = null , fullName = null ; List < OpenIDAttribute > attributes = token . getAttributes ( ) ; for ( OpenIDAttribute attribute : attributes ) { if ( attribute . getName ( ) . equals ( "email" ) ) { email = attribute . getValues ( ) . get ( 0 ) ; } if ( attribute . getName ( ) . equals ( "firstname" ) ) { firstName = attribute . getValues ( ) . get ( 0 ) ; } if ( attribute . getName ( ) . equals ( "lastname" ) ) { lastName = attribute . getValues ( ) . get ( 0 ) ; } if ( attribute . getName ( ) . equals ( "fullname" ) ) { fullName = attribute . getValues ( ) . get ( 0 ) ; } } if ( fullName == null ) { if ( firstName == null ) { firstName = "No" ; } if ( lastName == null ) { lastName = "Name" ; } fullName = firstName . concat ( " " ) . concat ( lastName ) ; } user = new User ( ) ; user . setActive ( true ) ; user . setEmail ( email ) ; user . setName ( fullName ) ; user . setPassword ( Utils . generateSecurityToken ( ) ) ; user . setIdentifier ( token . getIdentityUrl ( ) ) ; String id = user . create ( ) ; if ( id == null ) { throw new BadCredentialsException ( "Authentication failed: cannot create new user." ) ; } } return new AuthenticatedUserDetails ( user ) ; }
Loads a user from the data store or creates a new user from an OpenID profile .