String cookie = null;
ConfigurationContext configContext = null;
String serverURL = null;
if (request == null || response == null) {
throw new IdentityException("Required attributes missing");
}
try {
session = request.getSession();
serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
configContext = (ConfigurationContext) session.getServletContext().getAttribute(
CarbonConstants.CONFIGURATION_CONTEXT);
cookie = (String) session.getAttribute(OpenIDAdminClient.OPENID_ADMIN_COOKIE);
client = new OpenIDAdminClient(configContext, serverURL, cookie);
if (OpenId.COMPLETE.equals(session.getAttribute(OpenId.ACTION))
|| OpenId.CANCEL.equals(session.getAttribute(OpenId.ACTION))) {
// Ready for authentication.
paramList = (ParameterList) session.getAttribute(OpenId.PARAM_LIST);
} else {
// Extract the parameters from the request.Authentication not
// completed.
paramList = new ParameterList(request.getParameterMap());
}
if (paramList == null) {
responseText = getErrorResponseText("Invalid OpenID authentication request");
if (log.isDebugEnabled()) {
log.debug("Invalid OpenID authentication request :" + responseText);
}
directResponse(response, responseText);
return null;
}
String mode = paramList.hasParameter(OpenId.ATTR_MODE) ? paramList
.getParameterValue(OpenId.ATTR_MODE) : null;
if (log.isDebugEnabled()) {
log.debug("OpenID authentication mode :" + mode);
}
if (OpenId.ASSOCIATE.equals(mode)) {
responseText = client.getOpenIDAssociationResponse(OpenIDUtil
.getOpenIDAuthRequest(request));
if (log.isDebugEnabled()) {
log.debug("Association created successfully");
}
} else if (OpenId.CHECKID_SETUP.equals(mode) || OpenId.CHECKID_IMMEDIATE.equals(mode)) {
return checkSetupOrImmediate(request, paramList);
} else if (OpenId.CHECK_AUTHENTICATION.equals(mode)) {
responseText = client.verify(OpenIDUtil.getOpenIDAuthRequest(request));
if (log.isDebugEnabled()) {
log.debug("Authentication verified successfully");
}
} else {
// Error response - oops..!!! we did not get a valid OpenID
// mode.
responseText = getErrorResponseText("No valid OpenID found in the authentication request");
if (log.isDebugEnabled()) {
log.debug("No valid OpenID found in the authentication request");
}
}
} catch (Exception e) {
responseText = getErrorResponseText(e.getMessage());
}
try {
// Return the result to the user.
directResponse(response, responseText);
} catch (IOException e) {
log.error(e.getMessage());
throw new IdentityException("OpenID redirect reponse failed");
}
return null;
}