X-Git-Url: http://juplo.de/gitweb/?p=examples%2Ffacebook-app;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fyourshouter%2FSocialConfig.java;h=fc136adc0d5d823da6726f741fb4442a02202413;hp=53087095376ef0cfa2384cdc5efeeb2b9efed71d;hb=2050f0ba66eda0003559b4f4b13aabf31ade350e;hpb=931f5c9b9a43acb81775e995a613bd0c5b8aab52
diff --git a/src/main/java/de/juplo/yourshouter/SocialConfig.java b/src/main/java/de/juplo/yourshouter/SocialConfig.java
index 5308709..fc136ad 100644
--- a/src/main/java/de/juplo/yourshouter/SocialConfig.java
+++ b/src/main/java/de/juplo/yourshouter/SocialConfig.java
@@ -17,8 +17,11 @@ import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.mem.InMemoryUsersConnectionRepository;
import org.springframework.social.connect.web.ConnectController;
+import org.springframework.social.connect.web.ProviderSignInController;
+import org.springframework.social.connect.web.SignInAdapter;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.connect.FacebookConnectionFactory;
+import org.springframework.social.facebook.web.CanvasSignInController;
/**
@@ -70,22 +73,25 @@ public class SocialConfig extends SocialConfigurerAdapter
{
InMemoryUsersConnectionRepository repository =
new InMemoryUsersConnectionRepository(connectionFactoryLocator);
+ repository.setConnectionSignUp(new ProviderUserIdConnectionSignUp());
return repository;
}
/**
- * Configure a {@link UserIdSource}, that is equivalent to the one, that is
- * created by Spring-Boot.
+ * Configure our new implementation of {@link UserIdSource}, that retrieves
+ * the current user from the {@link SecurityContext}.
*
* @return
* An instance of {@link AnonymousUserIdSource}.
*
- * @see {@link AnonymousUserIdSource}
+ * @see {@link SecurityContextUserIdSource}
+ * @see {@link SecurityContext}
+ * @see {@link UserCookieInterceptor}
*/
@Override
public UserIdSource getUserIdSource()
{
- return new AnonymousUserIdSource();
+ return new SecurityContextUserIdSource();
}
@@ -113,6 +119,56 @@ public class SocialConfig extends SocialConfigurerAdapter
return controller;
}
+ /**
+ * Configure the {@link ProviderSignInController} to use our implementation
+ * of {@link SignInAdapter} to sign in the user by storing the ID in the
+ * {@link SecurityContext} and the user-cookie.
+ *
+ * @param factoryLocator The {@link ConnectionFactoryLocator} will be injected by Spring.
+ * @param repository The {@link UserConnectionRepository} will be injected by Spring.
+ * @return The configured {@link ProviderSignInController}
+ */
+ @Bean
+ public ProviderSignInController signInController(
+ ConnectionFactoryLocator factoryLocator,
+ UsersConnectionRepository repository
+ )
+ {
+ ProviderSignInController controller = new ProviderSignInController(
+ factoryLocator,
+ repository,
+ new UserCookieSignInAdapter()
+ );
+ return controller;
+ }
+
+ /**
+ * Configure the {@link CanvasSignInController} to enable sign-in through
+ * the signed_request
, that Facebook sends to the canvas-page.
+ *
+ * @param factoryLocator The {@link ConnectionFactoryLocator} will be injected by Spring.
+ * @param repository The {@link UserConnectionRepository} will be injected by Spring.
+ * @param env The {@link Environment}, to read additional parameters from.
+ * @return The configured {@link CanvasSignInController}
+ */
+ @Bean
+ public CanvasSignInController canvasSignInController(
+ ConnectionFactoryLocator factoryLocator,
+ UsersConnectionRepository repository,
+ Environment env
+ )
+ {
+ return
+ new CanvasSignInController(
+ factoryLocator,
+ repository,
+ new UserCookieSignInAdapter(),
+ env.getProperty("facebook.app.id"),
+ env.getProperty("facebook.app.secret"),
+ env.getProperty("facebook.app.canvas")
+ );
+ }
+
/**
* Configure a scoped bean named facebook
, that enables
* access to the Graph-API in the name of the current user.