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?
// 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));