getResponse().getCookieSettings().add(
new CookieSetting(DESCRIPTOR_COOKIE, sessionId));
log.info("Setting DESCRIPTOR COOKIE");
// obtain a AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = manager.authenticate(discovered,
returnToUrl.toString()); // TODO maybe add TIMESTAMP?
// Domain wide realm add meta to main page
// http://localhost:8080/oauth/xrds?returnTo=http://localhost:8080/oauth/openid_login\r\n
// log.info("OpenID - REALM = " +
// getReference().getHostIdentifier());
// authReq.setRealm(getReference().getHostIdentifier().toString());
log.info("OpenID - REALM = " + getReference().getBaseRef());
authReq.setRealm(getReference().getBaseRef().toString());
// Attribute Exchange - getting optional and required
FetchRequest fetch = null;
String[] optional = params.getValuesArray("ax_optional", true);
for (String o : optional) {
if (!ax.containsKey(o)) {
log.warning("Not supported AX extension : " + o);
continue;
}
if (fetch == null)
fetch = FetchRequest.createFetchRequest();
fetch.addAttribute(o, ax.get(o), false);
}
String[] required = params.getValuesArray("ax_required", true);
for (String r : required) {
if (!ax.containsKey(r)) {
log.warning("Not supported AX extension : " + r);
continue;
}
if (fetch == null)
fetch = FetchRequest.createFetchRequest();
fetch.addAttribute(r, ax.get(r), true);
}
if (fetch != null) {
authReq.addExtension(fetch);
}
if (!discovered.isVersion2()) {
log.info("REDIRECTING TEMPORARY");
// Option 1: GET HTTP-redirect to the OpenID Provider endpoint
// The only method supported in OpenID 1.x
// redirect-URL usually limited ~2048 bytes
redirectTemporary(authReq.getDestinationUrl(true));
return null;
} else {
// Option 2: HTML FORM Redirection (Allows payloads >2048 bytes)
Form msg = new Form();
for (Object key : authReq.getParameterMap().keySet()) {
msg.add(key.toString(),
authReq.getParameterValue(key.toString()));
log.info("Adding to form - key " + key.toString()
+ " : value"
+ authReq.getParameterValue(key.toString()));
}
// Redirector dispatcher = new Redirector(getContext(),
// authReq.getOPEndpoint(),
// Redirector.MODE_SERVER_OUTBOUND);