}
}
// select consumer implementation based on provider
String providerConsumer = OPEN_ID_CONSUMER_INIT_PARAM_NAME_VALUE;
ConsumerManager providerOpenIDConsumerManager = openIDConsumerManager;
if (provider != null)
{
String consumer = getInitParameter(OPEN_ID_CONSUMER_INIT_PARAM_NAME_PREFIX+provider);
if ((consumer != null) && consumer.equals(STEP2_CONSUMER_INIT_PARAM_NAME_VALUE))
{
providerConsumer = STEP2_CONSUMER_INIT_PARAM_NAME_VALUE;
providerOpenIDConsumerManager = openIDStep2ConsumerManager;
}
}
// OpenID discovery
DiscoveryInformation discovered = null;
try
{
if (userSuppliedDiscoveryString != null)
{
List discoveries = null;
if (providerConsumer.equals(STEP2_CONSUMER_INIT_PARAM_NAME_VALUE))
{
// verify discovery string is likely a host name
if ((userSuppliedDiscoveryString.indexOf("://") == -1) && (userSuppliedDiscoveryString.indexOf('@') == -1) && (userSuppliedDiscoveryString.indexOf('=') == -1))
{
// Step2 OpenId discovery
IdpIdentifier providerIdentifier = new IdpIdentifier(userSuppliedDiscoveryString);
discoveries = providerOpenIDConsumerManager.getDiscovery().discover(providerIdentifier);
}
}
else
{
// standard OpenId discovery
discoveries = providerOpenIDConsumerManager.discover(userSuppliedDiscoveryString);
}
if ((discoveries != null) && !discoveries.isEmpty())
{
discovered = providerOpenIDConsumerManager.associate(discoveries);
}
}
}
catch (OpenIDException oide)
{
throw new RuntimeException("Unexpected OpenID discovery exception: "+oide, oide);
}
if (discovered == null)
{
throw new RuntimeException("No OpenID provider discovered for: "+userSuppliedDiscoveryString);
}
discoveredProvider = true;
// log OpenID provider
if (log.isDebugEnabled())
{
log.debug("Discovered OpenID provider endpoint: "+discovered.getOPEndpoint()+", ["+discovered.getClass().getSimpleName()+"]");
}
// save login state
httpSession.setAttribute(OPEN_ID_LOGIN_LOCALE_ATTR_NAME, request.getLocale());
httpSession.setAttribute(OPEN_ID_LOGIN_SERVER_NAME_ATTR_NAME, request.getServerName());
// save OpenID provider in session
httpSession.setAttribute(OPEN_ID_PROVIDER_ATTR_NAME, provider);
httpSession.setAttribute(OPEN_ID_DISCOVERY_INFO_ATTR_NAME, discovered);
// create OpenID authentication request and redirect
String authReturnToURL = openIDRealmURL+"/"+OpenIDConstants.OPEN_ID_AUTHENTICATED_REQUEST+"?"+OpenIDConstants.OPEN_ID_RETURN+"="+returnPath;
String authRedirectURL = null;
try
{
// authentication request
AuthRequest authRequest = providerOpenIDConsumerManager.authenticate(discovered, authReturnToURL, openIDRealmURL);
// request attribute exchange data
FetchRequest axRequest = FetchRequest.createFetchRequest();
axRequest.addAttribute("email", "http://axschema.org/contact/email", true);
axRequest.addAttribute("fullname", "http://axschema.org/namePerson", true);
axRequest.addAttribute("lastname", "http://axschema.org/namePerson/last", true);