Package org.openid4java.consumer

Examples of org.openid4java.consumer.ConsumerManager


        // setup OpenID
        try
        {
            // standard OpenID implementation
            openIDConsumerManager = new ConsumerManager();
            // assemble Step2 OpenID implementation; TODO: utilize a more
            // robust HTTPFetcher implementation since the DefaultHttpFetcher
            // may not be entirely thread safe due to connection manager
            // configuration in HttpComponents, (this is why there are 4
            // discrete instances of DefaultHttpFetcher used below).
            HostMetaFetcher step2GoogleHostMetaFetcher = new GoogleHostMetaFetcher(new DefaultHttpFetcher());
            HostMetaFetcher step2DefaultHostMetaFetcher = new DefaultHostMetaFetcher(new DefaultHttpFetcher());
            ThreadFactory parallelThreadFactory = new ThreadFactory()
            {
                public Thread newThread(Runnable r)
                {
                    Thread newThread = Executors.defaultThreadFactory().newThread(r);
                    newThread.setName(getClass().getSimpleName()+"-"+newThread.getName());
                    newThread.setDaemon(true);
                    return newThread;
                }
            };
            HostMetaFetcher step2HostMetaFetcher = new ParallelHostMetaFetcher(Executors.newFixedThreadPool(10, parallelThreadFactory), OPEN_ID_DISCOVERY_TIMEOUT_SECONDS, step2GoogleHostMetaFetcher, step2DefaultHostMetaFetcher);
            TrustRootsProvider step2XrdsTrustProvider = new DefaultTrustRootsProvider();
            CachedCertPathValidator step2XrdsCertPathValidator = new CachedCertPathValidator(step2XrdsTrustProvider);
            Verifier step2XrdsVerifier = new Verifier(step2XrdsCertPathValidator, new DefaultHttpFetcher());
            CertValidator step2XrdsCertValidator = new DefaultCertValidator();
            XrdDiscoveryResolver step2XrdResolver = new LegacyXrdsResolver(new DefaultHttpFetcher(), step2XrdsVerifier, step2XrdsCertValidator);
            HtmlResolver step2HtmlResolver = new HtmlResolver();
            YadisResolver step2YadisResolver = new YadisResolver();
            XriResolver step2XriResolver = new XriDotNetProxyResolver();
            Discovery2 step2Discovery = new Discovery2(step2HostMetaFetcher, step2XrdResolver, step2HtmlResolver, step2YadisResolver, step2XriResolver);
            openIDStep2ConsumerManager = new ConsumerManager();
            openIDStep2ConsumerManager.setDiscovery(step2Discovery);
        }
        catch (OpenIDException oide)
        {
            throw new ServletException("Unexpected OpenID exception: "+oide, oide);
View Full Code Here


                        }
                    }

                    // 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);
View Full Code Here

TOP

Related Classes of org.openid4java.consumer.ConsumerManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.