}
} else {
try {
OpenIDAuthenticationToken token = openIDConsumer.endConsumption(request);
if (token.getStatus() == OpenIDAuthenticationStatus.SUCCESS) {
// Check that the OpenID isn't already mapped
String openId = token.getIdentityUrl();
if (securityRealm.getUserForOpenId(openId) != null) {
validationContext.addError("The OpenID supplied is already mapped to a user.");
} else {
// Add it
securityRealm.addOpenIdToUser(userDetails, openId);
return new RedirectView(blog.getUrl() + "/editUserPreferences.secureaction");
}
} else {
validationContext.addError(StringUtils.transformHTML(token.getMessage()));
}
} catch (OpenIDConsumerException oice) {
log.error("Error in consumer", oice);
validationContext.addError("Error adding OpenID " + oice.getMessage());