<!-- settings for the Graph-API -->
<facebook.app.id>NOT_SET</facebook.app.id>
<facebook.app.secret>NOT_SET</facebook.app.secret>
+ <facebook.app.salt>NOT_SET</facebook.app.salt>
<facebook.app.canvas>NOT_SET</facebook.app.canvas>
<!-- settings for the Apache Commons Http-Client -->
<httpclient.timeout.connection>60000</httpclient.timeout.connection>
<httpclient.timeout.read>60000</httpclient.timeout.read>
<httpclient.logging.level>ERROR</httpclient.logging.level>
+ <!-- database settings for tests -->
+ <jdbc.groupId>com.h2database</jdbc.groupId>
+ <jdbc.artifactId>h2</jdbc.artifactId>
</properties>
<dependencies>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
+ <!-- Persistence -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${jdbc.groupId}</groupId>
+ <artifactId>${jdbc.artifactId}</artifactId>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
<build>
+import java.math.BigInteger;
import javax.inject.Inject;
+import javax.sql.DataSource;
import org.apache.http.HttpRequestFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
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;
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;
@EnableSocial
public class SocialConfig extends SocialConfigurerAdapter
{
+ @Inject
+ DataSource dataSource;
@Inject
ConnectionSignUp connectionSignUp;
@Inject
SignInAdapter signInAdapter;
+ @Value("${facebook.app.secret}")
+ String secret;
+ @Value("${facebook.app.salt}")
+ String salt;
+
/**
* Add a {@link FacebookConnectionFactory} to the configuration.
}
/**
- * 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.
+ * <p>
+ * The app-secret is reused as password for the encryption of the data.
+ * The salt can be changed in the <code>pom.xml</code>
+ * <p>
+ * 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.text(
+ secret,
+ String.format("%08x", new BigInteger(1, salt.getBytes()))
+ )
+ );
repository.setConnectionSignUp(connectionSignUp);
return repository;
}
--- /dev/null
+-- This SQL contains a "create table" that can be used to create a table that JdbcUsersConnectionRepository can persist
+-- connection in. It is, however, not to be assumed to be production-ready, all-purpose SQL. It is merely representative
+-- of the kind of table that JdbcUsersConnectionRepository works with. The table and column names, as well as the general
+-- column types, are what is important. Specific column types and sizes that work may vary across database vendors and
+-- the required sizes may vary across API providers.
+
+create table UserConnection (userId varchar(255) not null,
+ providerId varchar(255) not null,
+ providerUserId varchar(255),
+ rank int not null,
+ displayName varchar(255),
+ profileUrl varchar(512),
+ imageUrl varchar(512),
+ accessToken varchar(512) not null,
+ secret varchar(512),
+ refreshToken varchar(512),
+ expireTime bigint,
+ primary key (userId, providerId, providerUserId));
+create unique index UserConnectionRank on UserConnection(userId, providerId, rank);