From: Kai Moritz Date: Sat, 30 Jan 2016 02:21:46 +0000 (+0100) Subject: Refactored instantiation of helper classes: @Service instead of manual X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=ca351a3eb7442fbb183aa62e1a58cd85bc1f2ef7;p=examples%2Ffacebook-app Refactored instantiation of helper classes: @Service instead of manual --- diff --git a/src/main/java/de/juplo/yourshouter/SocialConfig.java b/src/main/java/de/juplo/yourshouter/SocialConfig.java index 4efa0e2..4573fbb 100644 --- a/src/main/java/de/juplo/yourshouter/SocialConfig.java +++ b/src/main/java/de/juplo/yourshouter/SocialConfig.java @@ -2,6 +2,7 @@ package de.juplo.yourshouter; +import javax.inject.Inject; import org.apache.http.HttpRequestFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,6 +17,7 @@ import org.springframework.social.config.annotation.SocialConfigurerAdapter; import org.springframework.social.connect.Connection; import org.springframework.social.connect.ConnectionFactoryLocator; import org.springframework.social.connect.ConnectionRepository; +import org.springframework.social.connect.ConnectionSignUp; import org.springframework.social.connect.UsersConnectionRepository; import org.springframework.social.connect.mem.InMemoryUsersConnectionRepository; import org.springframework.social.connect.web.ConnectController; @@ -35,6 +37,12 @@ import org.springframework.social.facebook.web.CanvasSignInController; @EnableSocial public class SocialConfig extends SocialConfigurerAdapter { + @Inject + ConnectionSignUp connectionSignUp; + @Inject + SignInAdapter signInAdapter; + + /** * Add a {@link FacebookConnectionFactory} to the configuration. * The factory is configured through the keys facebook.app.id @@ -75,7 +83,7 @@ public class SocialConfig extends SocialConfigurerAdapter { InMemoryUsersConnectionRepository repository = new InMemoryUsersConnectionRepository(connectionFactoryLocator); - repository.setConnectionSignUp(new ProviderUserIdConnectionSignUp()); + repository.setConnectionSignUp(connectionSignUp); return repository; } @@ -136,11 +144,8 @@ public class SocialConfig extends SocialConfigurerAdapter UsersConnectionRepository repository ) { - ProviderSignInController controller = new ProviderSignInController( - factoryLocator, - repository, - new UserCookieSignInAdapter() - ); + ProviderSignInController controller = + new ProviderSignInController(factoryLocator, repository, signInAdapter); return controller; } @@ -164,7 +169,7 @@ public class SocialConfig extends SocialConfigurerAdapter new CanvasSignInController( factoryLocator, repository, - new UserCookieSignInAdapter(), + signInAdapter, env.getProperty("facebook.app.id"), env.getProperty("facebook.app.secret"), env.getProperty("facebook.app.canvas") diff --git a/src/main/java/de/juplo/yourshouter/UserCookieSignInAdapter.java b/src/main/java/de/juplo/yourshouter/UserCookieSignInAdapter.java index ed1a8d5..88cf156 100644 --- a/src/main/java/de/juplo/yourshouter/UserCookieSignInAdapter.java +++ b/src/main/java/de/juplo/yourshouter/UserCookieSignInAdapter.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.social.connect.Connection; import org.springframework.social.connect.web.SignInAdapter; +import org.springframework.stereotype.Service; import org.springframework.web.context.request.NativeWebRequest; @@ -16,6 +17,7 @@ import org.springframework.web.context.request.NativeWebRequest; * * @author Kai Moritz */ +@Service public class UserCookieSignInAdapter implements SignInAdapter { private final static Logger LOG =