getResponse().setEntity(new JsonRepresentation(obj));
}
// cleanup of cookie
getResponse().getCookieSettings().remove(DESCRIPTOR_COOKIE);
CookieSetting disc = new CookieSetting(DESCRIPTOR_COOKIE, "");
disc.setMaxAge(0);
getResponse().getCookieSettings().add(disc);
// TODO save the identifier // send back to OAuth
return getResponse().getEntity();
}
String target = params.getFirstValue("openid_identifier");
if (target == null || target.length() == 0) {
// No target - might be Yadis discovery
String location = setXRDSHeader();
StringBuilder html = new StringBuilder();
html.append("<html><head><meta http-equiv=\"X-XRDS-Location\" content=\"");
html.append(location);
html.append("\"/></head></html>");
return new StringRepresentation(html.toString(),
MediaType.TEXT_HTML);
}
try {
StringBuilder returnToUrl = new StringBuilder();
returnToUrl.append(getReference().getBaseRef());
returnToUrl.append("?return=true");
// --- Forward proxy setup (only if needed) ---
// ProxyProperties proxyProps = new ProxyProperties();
// proxyProps.setProxyName("proxy.example.com");
// proxyProps.setProxyPort(8080);
// HttpClientFactory.setProxyProperties(proxyProps);
// perform discovery on the user-supplied identifier
List<?> discoveries = null;
discoveries = discovery.discover(target);
for (Object o : discoveries) {
if (o instanceof DiscoveryInformation) {
DiscoveryInformation di = (DiscoveryInformation) o;
log.info("Found - " + di.getOPEndpoint());
target = di.getOPEndpoint().toString();
}
}
ConsumerManager manager = getManager(target);
// try {
// discoveries = manager.discover(target);
// } catch (YadisException e) {
// log.info("Could not connect in time!!!!!!!!!!!!!!!!!!!!!!");
// return new
// StringRepresentation("Could not connect to Identity Server in time.",MediaType.TEXT_HTML);
// }
// attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = manager.associate(discoveries);
// store the discovery information in the user's session
// getContext().getAttributes().put("openid-disc", discovered);
String sessionId = String.valueOf(System
.identityHashCode(discovered));
session.put(sessionId, discovered);
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?