spring-attic / spring-social

Allows you to connect your applications with SaaS providers such as Facebook and Twitter.
http://projects.spring.io/spring-social
Apache License 2.0
619 stars 351 forks source link

shouldn't ConnectionFactoryLocator be auto-configured in spring boot application? #165

Closed Zane-XY closed 9 years ago

Zane-XY commented 9 years ago

in the current spring-social-showcase-boot, I didn't see ConnectionFactoryLocator is configured anywhere, but in the latest code, the ProviderSignInUtils constructor has changed to

public ProviderSignInUtils( ConnectionFactoryLocator connectionFactoryLocator,UsersConnectionRepository connectionRepository) {
...
}

which means I need a ConnectionFactoryLocator and UsersConnectionRepository bean to create ProviderSignInUtils.

The recommended way of configure ConnectionFactoryLocator shown from the current reference:

@Bean
@Scope(value="singleton", proxyMode=ScopedProxyMode.INTERFACES)
public ConnectionFactoryLocator connectionFactoryLocator() {
    ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();

    registry.addConnectionFactory(new FacebookConnectionFactory(
        environment.getProperty("facebook.clientId"),
        environment.getProperty("facebook.clientSecret")));

    registry.addConnectionFactory(new TwitterConnectionFactory(
        environment.getProperty("twitter.consumerKey"),
        environment.getProperty("twitter.consumerSecret")));

    return registry;
}

duplicates the codes with spring-boot's autoconfigure class, like TwitterAutoConfiguration FacebookAutoConfiguration in the reading properties part, should a ConnectionFactoryLocator be configured when it detects the spring-social configuration in the application.properties?

It should also be useful to expose the $provider$ConnectionFactory bean created in the SocialAutoConfigurerAdapter subclasses:

@Override
protected ConnectionFactory<?> createConnectionFactory() {
            return new TwitterConnectionFactory(this.properties.getAppId(),
                    this.properties.getAppSecret());
}

then we can create ConnectionFactoryRegistry by just wiring existing factories.

Zane-XY commented 9 years ago

it seems the ConnectionFactoryLocator is configured in spring-social-config

@Bean
    public ConnectionFactoryLocator connectionFactoryLocator() {
        if (securityEnabled) {
            SecurityEnabledConnectionFactoryConfigurer cfConfig = new SecurityEnabledConnectionFactoryConfigurer();
            for (SocialConfigurer socialConfigurer : socialConfigurers) {
                socialConfigurer.addConnectionFactories(cfConfig, environment);
            }
            return cfConfig.getConnectionFactoryLocator();
        } else {
            DefaultConnectionFactoryConfigurer cfConfig = new DefaultConnectionFactoryConfigurer();
            for (SocialConfigurer socialConfigurer : socialConfigurers) {
                socialConfigurer.addConnectionFactories(cfConfig, environment);
            }
            return cfConfig.getConnectionFactoryLocator();
        }
    }