responseText = messageResponse.keyValueFormEncoding();
return directResponse(response, messageResponse.keyValueFormEncoding());
}
private String checkId(HttpServletRequest request, HttpServletResponse response, ParameterList parameterList) throws ServletException, IOException {
ServerManager manager = ((SimpleServiceProxy)getServiceProxy()).getServerManager();
HttpSession session = request.getSession();
Message messageResponse;
String responseText;
// interact with the user and obtain data needed to continue
String userSelectedId = null;
String userSelectedClaimedId = null;
User authenticatedAndApproved = null;
String email = "";
if (session.getAttribute("authenticatedAndApproved") == null) {
session.setAttribute("parameterlist", parameterList);
String wwwParams = wwwFormEncoding(parameterList);
String url = "login.jsp?" + wwwParams;
response.sendRedirect(url);
return null;
} else {
userSelectedId = (String) session.getAttribute("openid.claimed_id");
userSelectedClaimedId = (String) session.getAttribute("openid.identity");
authenticatedAndApproved = (User) session.getAttribute("authenticatedAndApproved");
// Remove the parameterlist so this provider can accept requests from elsewhere
session.removeAttribute("parameterlist");
session.setAttribute("authenticatedAndApproved", null);
}
// --- process an authentication request ---
AuthRequest authReq = null;
String opLocalId = null;
try {
authReq = AuthRequest.createAuthRequest(parameterList, manager.getRealmVerifier());
// if the user chose a different claimed_id than the one in request
if (userSelectedClaimedId != null && userSelectedClaimedId.equals(authReq.getClaimed())) {
//opLocalId = "http://localhost:8081/idp4java/idp";//lookupLocalId(userSelectedClaimedId);
}
} catch (MessageException e) {
e.printStackTrace();
throw new ServletException(e);
}
// --- process an authentication request ---
//messageResponse = manager.authResponse(parameterList, userSelectedId, userSelectedClaimedId, true);
messageResponse = manager.authResponse(parameterList, opLocalId, opLocalId, true);
if (messageResponse instanceof DirectError)
return directResponse(response, messageResponse.keyValueFormEncoding());
else {
try {
if (authReq.hasExtension(AxMessage.OPENID_NS_AX))
{
MessageExtension ext = authReq.getExtension(AxMessage.OPENID_NS_AX);
if (ext instanceof FetchRequest)
{
FetchRequest fetchReq = (FetchRequest) ext;
Map required = fetchReq.getAttributes(true);
Map optional = fetchReq.getAttributes(false);
if (required.containsKey("email"))
{
Map userDataExt = new HashMap();
userDataExt.put("email", "someone@someplace.com");
FetchResponse fetchResp = FetchResponse.createFetchResponse(fetchReq, userDataExt);
// (alternatively) manually add attribute values
//fetchResp.addAttribute("email", "http://schema.openid.net/contact/email", email);
messageResponse.addExtension(fetchResp);
}
}
else //if (ext instanceof StoreRequest)
{
throw new UnsupportedOperationException("TODO");
}
}
if (authReq.hasExtension(SRegMessage.OPENID_NS_SREG))
{
MessageExtension ext = authReq.getExtension(SRegMessage.OPENID_NS_SREG);
if (ext instanceof SRegRequest)
{
SRegRequest sregReq = (SRegRequest) ext;
List required = sregReq.getAttributes(true);
List optional = sregReq.getAttributes(false);
if (required.contains("email"))
{
// data released by the user
Map userDataSReg = new HashMap();
userDataSReg.put("email", "user@example.com");
SRegResponse sregResp = SRegResponse.createSRegResponse(sregReq, userDataSReg);
// (alternatively) manually add attribute values
//sregResp.addAttribute("email", email);
messageResponse.addExtension(sregResp);
}
}
else
{
throw new UnsupportedOperationException("TODO");
}
}
// Sign the auth success message.
// This is required as AuthSuccess.buildSignedList has a `todo' tag now.
manager.sign((AuthSuccess) messageResponse);
} catch (MessageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServerException e) {
// TODO Auto-generated catch block