Search in sources :

Example 1 with ConnectionFactoryLocator

use of org.springframework.social.connect.ConnectionFactoryLocator in project spring-boot by spring-projects.

the class ResourceServerTokenServicesConfigurationTests method springSocialUserInfo.

@Test
public void springSocialUserInfo() {
    EnvironmentTestUtils.addEnvironment(this.environment, "security.oauth2.resource.userInfoUri:http://example.com", "spring.social.facebook.app-id=foo", "spring.social.facebook.app-secret=bar");
    this.context = new SpringApplicationBuilder(SocialResourceConfiguration.class).environment(this.environment).web(WebApplicationType.SERVLET).run();
    ConnectionFactoryLocator connectionFactory = this.context.getBean(ConnectionFactoryLocator.class);
    assertThat(connectionFactory).isNotNull();
    SpringSocialTokenServices services = this.context.getBean(SpringSocialTokenServices.class);
    assertThat(services).isNotNull();
}
Also used : SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ConnectionFactoryLocator(org.springframework.social.connect.ConnectionFactoryLocator) Test(org.junit.Test)

Example 2 with ConnectionFactoryLocator

use of org.springframework.social.connect.ConnectionFactoryLocator in project engine by craftercms.

the class ConfigAwareConnectionFactoryLocator method getCurrentConnectionFactoryLocator.

protected ConnectionFactoryLocator getCurrentConnectionFactoryLocator() {
    Callback<ConnectionFactoryLocator> callback = new Callback<ConnectionFactoryLocator>() {

        @Override
        public ConnectionFactoryLocator execute() {
            HierarchicalConfiguration config = ConfigUtils.getCurrentConfig();
            ConnectionFactoryRegistry registry = null;
            if (config != null) {
                try {
                    SubnodeConfiguration socialConnectionsConfig = config.configurationAt(SOCIAL_CONNECTIONS_KEY);
                    for (ConfigurationParser<?> parser : configParsers) {
                        ConnectionFactory<?> factory = (ConnectionFactory<?>) parser.parse(socialConnectionsConfig);
                        if (factory != null) {
                            if (registry == null) {
                                registry = new ConnectionFactoryRegistry();
                            }
                            registry.addConnectionFactory(factory);
                        }
                    }
                } catch (IllegalArgumentException e) {
                // Ignore if != 1
                }
            }
            if (registry != null) {
                return registry;
            } else {
                return defaultLocator;
            }
        }
    };
    SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        return cacheTemplate.getObject(siteContext.getContext(), callback, CONNECTION_FACTORY_LOCATOR_CACHE_KEY);
    } else {
        return defaultLocator;
    }
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) ConnectionFactory(org.springframework.social.connect.ConnectionFactory) Callback(org.craftercms.commons.lang.Callback) SiteContext(org.craftercms.engine.service.context.SiteContext) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) ConnectionFactoryLocator(org.springframework.social.connect.ConnectionFactoryLocator) ConnectionFactoryRegistry(org.springframework.social.connect.support.ConnectionFactoryRegistry)

Aggregations

ConnectionFactoryLocator (org.springframework.social.connect.ConnectionFactoryLocator)2 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 SubnodeConfiguration (org.apache.commons.configuration.SubnodeConfiguration)1 Callback (org.craftercms.commons.lang.Callback)1 SiteContext (org.craftercms.engine.service.context.SiteContext)1 Test (org.junit.Test)1 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)1 ConnectionFactory (org.springframework.social.connect.ConnectionFactory)1 ConnectionFactoryRegistry (org.springframework.social.connect.support.ConnectionFactoryRegistry)1