String claimedIdentity = request.getParameter("openid_identifier");
try {
String returnToUrl = request.getRequestURL().toString();
String realm = PebbleContext.getInstance().getConfiguration().getUrl();
String openIdUrl = openIDConsumer.beginConsumption(request, claimedIdentity, returnToUrl, realm);
return new RedirectView(openIdUrl);
} catch (OpenIDConsumerException oice) {
log.error("Error adding OpenID", oice);
validationContext.addError("Error adding OpenID " + oice.getMessage());
}
} 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()));
}