Refactored instantiation of helper classes: @Service instead of manual
authorKai Moritz <kai@juplo.de>
Sat, 30 Jan 2016 02:21:46 +0000 (03:21 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 1 Feb 2016 17:53:31 +0000 (18:53 +0100)
src/main/java/de/juplo/yourshouter/SocialConfig.java
src/main/java/de/juplo/yourshouter/UserCookieSignInAdapter.java

index 4efa0e2..4573fbb 100644 (file)
@@ -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 <code>facebook.app.id</code>
@@ -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")
index ed1a8d5..88cf156 100644 (file)
@@ -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 =