*/
@Override
@Transactional
public UserDetails loadUserByUsername(String userOpenId)
throws UsernameNotFoundException, DataAccessException {
OpenIdCredential credential = openIDCredentialDAO.findCredential(userOpenId);
if(credential == null) {
User newUser = userFactory.createNewUser();
newUser.setDisplayName(userOpenId);
credential = new OpenIdCredential();
credential.setOpenIdIdentifier(userOpenId);
newUser = userWriter.createUser(newUser);
credentialsWriter.addCredential(newUser, credential);
}
User user = credential == null ? null : credential.getUser();
if(user == null) {
throw new BusinessLogicException("Cannot obtain user by specified openId:" + userOpenId);
}
return new ZEUserDetails(Collections.<GrantedAuthority>singletonList(
new GrantedAuthorityImpl(Role.ACEGITOKEN_USER)), user, credential);