log.debug("Return to URL '{}'", returnToUrl);
// Create a consumer manager for this specific request and cache it
// (this is to preserve session state such as nonce values etc)
ConsumerManager consumerManager = new ConsumerManager();
InMemoryOpenIDCache.INSTANCE.putConsumerManager(sessionToken, consumerManager);
// Perform discovery on the user-supplied identifier
List discoveries = consumerManager.discover(identifier);
// Attempt to associate with the OpenID provider
// and retrieve one service endpoint for authentication
DiscoveryInformation discovered = consumerManager.associate(discoveries);
// Create a memento to rebuild the discovered information in a subsequent request
DiscoveryInformationMemento memento = new DiscoveryInformationMemento();
if (discovered.getClaimedIdentifier() != null) {
memento.setClaimedIdentifier(discovered.getClaimedIdentifier().getIdentifier());
}
memento.setDelegate(discovered.getDelegateIdentifier());
if (discovered.getOPEndpoint() != null) {
memento.setOpEndpoint(discovered.getOPEndpoint().toString());
}
memento.setTypes(discovered.getTypes());
memento.setVersion(discovered.getVersion());
// Create a temporary User to preserve state between requests without
// using a session (we could be in a cluster)
User tempUser = new User(null, sessionToken);
tempUser.setOpenIDDiscoveryInformationMemento(memento);
tempUser.setSessionToken(sessionToken);
// Persist the User
InMemoryUserCache.INSTANCE.put(sessionToken, tempUser);
// Build the AuthRequest message to be sent to the OpenID provider
AuthRequest authReq = consumerManager.authenticate(discovered, returnToUrl);
// Build the FetchRequest containing the information to be copied
// from the OpenID provider
FetchRequest fetch = FetchRequest.createFetchRequest();
// Attempt to decode each entry