Review
In the previous section, we have shown the steps on how to generate and retrieve the OAuth secret keys from Facebook and Twitter. In this section we will setup the Spring Social configuration settings through JavaConfig.Table of Contents
Click on a link to jump to that section:
- Functional Specs
- Generate OAuth keys
- Spring Social configuration
- Spring Security configuration
- JavaConfig
- ApplicationInitializer.java
- ApplicationContext.java
- DataConfig.java
- ThymeleafConfig.java
- spring.properties
- View with Thymeleaf
- Layers
- Domain
- Repository
- Service
- Controller
- Running the application
- Clone from GitHub
- Create the Database
- Run with Maven and Tomcat 7
- Run with Maven and Jetty 8
- Import to Eclipse
- Validate with W3C
Spring Social configuration
What is Spring Social?
Spring Social is an extension of the Spring Framework that allows you to connect your applications with Software-as-a-Service (SaaS) providers such as Facebook and Twitter.
Features:Source: http://www.springsource.org/spring-social
- An extensible service provider framework that greatly simplifies the process of connecting local user accounts to hosted provider accounts.
- A connect controller that handles the authorization flow between your Java/Spring web application, a service provider, and your users.
- Java bindings to popular service provider APIs such as Facebook, Twitter, LinkedIn, TripIt, and GitHub.
- A sign-in controller that enables users to authenticate with your application by signing in through a service provider.
Here's our Spring Social configuration:
SocialConfig.java
Let me explain the contents of this configuration:
- We have autowired the environment properties and the datasource
- We have declared a ConnectionFactoryLocator which allows us to register connections to Facebook and Twitter. Notice how we passed the OAuth secret IDs and secret keys to the locator
- We've declared a TextEncryptor for encrypting strings. This is required by Spring Social's JdbcUsersConnectionRepository
- JdbcUsersConnectionRepository is used for persisting connections to a database through JDBC
- ConnectionRepository allows a specific user to save and retrieve connections. We need to use this in conjunction with Spring Security because it provides us ready-made authenticated users. Notice how we assigned the current authenticated user
- ConnectController is a controller for managing the connection flow to social media sites
- HiddenHttpMethodFilter is required by Spring Social so that users can disconnect from social media sites. The filter needs to be declared in the web.xml or ApplicationInitializer
Note: If you need an in-depth explanation of each classes, please see the official Spring Social docs
0 komentar:
Post a Comment