ParameterList request = new ParameterList(req.getParameterMap());
String mode = request.hasParameter("openid.mode") ?
request.getParameterValue("openid.mode") : null;
Message response;
String responseText;
if ("associate".equals(mode))
{
// --- process an association request ---
response = manager.associationResponse(request);
responseText = response.keyValueFormEncoding();
}
else if ("checkid_immediate".equals(mode))
{
String userSelectedClaimedId = (String) request.getParameter("openid.claimed_id").getValue();
String realm = (String) request.getParameter("openid.realm").getValue();
if (!isTrustedRealm(realm, userSelectedClaimedId)) {
response = DirectError.createDirectError("checkid_immediate is not supported");
responseText = response.keyValueFormEncoding();
directResponse(resp, responseText);
return;
}
// --- process an authentication request ---
AuthRequest authReq = null;
try {
authReq = AuthRequest.createAuthRequest(request, manager.getRealmVerifier());
} catch (Exception ex) {
throw new ServletException(ex);
}
String opLocalId = null;
// if the user chose a different claimed_id than the one in request
if (userSelectedClaimedId != null &&
userSelectedClaimedId.equals(authReq.getClaimed()))
{
//opLocalId = lookupLocalId(userSelectedClaimedId);
}
response = manager.authResponse(request,
opLocalId,
userSelectedClaimedId,
true,
false); // Sign after we added extensions.
if (response instanceof DirectError)
responseText = response.keyValueFormEncoding();
else
{
// Sign the auth success message.
// This is required as AuthSuccess.buildSignedList has a `todo' tag now.
try {
manager.sign((AuthSuccess) response);
} catch (Exception ex) {
throw new ServletException(ex);
}
responseText = response.keyValueFormEncoding();
}
}
else
{
// unsupported mode
// --- error response ---
response = DirectError.createDirectError("Unknown request");
responseText = response.keyValueFormEncoding();
}
directResponse(resp, responseText);
}