X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fyourshouter%2FSocialConfig.java;h=40a0aa5f7c2132d3575f099351cfbc5e7fa8d64c;hb=f1e0b9b0179c176ad143862cbe56a24d319c87ba;hp=4573fbb50dcabc11c5f72a2e33a33eabe3ae6653;hpb=ca351a3eb7442fbb183aa62e1a58cd85bc1f2ef7;p=examples%2Ffacebook-app diff --git a/src/main/java/de/juplo/yourshouter/SocialConfig.java b/src/main/java/de/juplo/yourshouter/SocialConfig.java index 4573fbb..40a0aa5 100644 --- a/src/main/java/de/juplo/yourshouter/SocialConfig.java +++ b/src/main/java/de/juplo/yourshouter/SocialConfig.java @@ -3,6 +3,7 @@ package de.juplo.yourshouter; import javax.inject.Inject; +import javax.sql.DataSource; import org.apache.http.HttpRequestFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -11,6 +12,8 @@ import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.social.UserIdSource; import org.springframework.core.env.Environment; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.crypto.encrypt.Encryptors; import org.springframework.social.config.annotation.ConnectionFactoryConfigurer; import org.springframework.social.config.annotation.EnableSocial; import org.springframework.social.config.annotation.SocialConfigurerAdapter; @@ -19,9 +22,8 @@ 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.jdbc.JdbcUsersConnectionRepository; 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; @@ -37,6 +39,8 @@ import org.springframework.social.facebook.web.CanvasSignInController; @EnableSocial public class SocialConfig extends SocialConfigurerAdapter { + @Inject + DataSource dataSource; @Inject ConnectionSignUp connectionSignUp; @Inject @@ -66,23 +70,30 @@ public class SocialConfig extends SocialConfigurerAdapter } /** - * Configure an instance of {@link InMemoryUsersConnection} as persistent - * store of user/connection-mappings. + * {@inheritDoc} * - * At the moment, no special configuration is needed. + * Configure an instance of {@link JdbcUsersConnection} as persistent + * store of user/connection-mappings. + *

+ * The app-secret is reused as password for the encryption of the data. + * The salt can be changed in the pom.xml + *

+ * This does only work, if you have the Java Crypto Extension (JCE) in + * full strength version, since Spring Security is using a 256-bit key. * - * @param connectionFactoryLocator - * The {@link ConnectionFactoryLocator} will be injected by Spring. - * @return - * The configured {@link UsersConnectionRepository}. + * @see http://stackoverflow.com/a/17637354 */ @Override public UsersConnectionRepository getUsersConnectionRepository( ConnectionFactoryLocator connectionFactoryLocator ) { - InMemoryUsersConnectionRepository repository = - new InMemoryUsersConnectionRepository(connectionFactoryLocator); + JdbcUsersConnectionRepository repository = + new JdbcUsersConnectionRepository( + dataSource, + connectionFactoryLocator, + Encryptors.noOpText() + ); repository.setConnectionSignUp(connectionSignUp); return repository; } @@ -101,7 +112,7 @@ public class SocialConfig extends SocialConfigurerAdapter @Override public UserIdSource getUserIdSource() { - return new SecurityContextUserIdSource(); + return new SpringSecurityContextUserIdSource(); } @@ -129,26 +140,6 @@ 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, signInAdapter); - return controller; - } - /** * Configure the {@link CanvasSignInController} to enable sign-in through * the signed_request, that Facebook sends to the canvas-page.