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
Next
In the next section, we will focus on Spring Security-related configuration. Click here to proceed.|
Share the joy:
|
Hi Mark,
ReplyDeleteI guess HiddenHttpMethodFilter is used for the following purpose:
If the client of your RESTful solution is a browser, not a costumed web client, then please beware that HTML only supports “GET” and “POST” methods, i.e. browsers might not know how to handle HTML form, whose action method is “PUT” or “DELETE”. To get around this, you can add a hidden filed in your web form to pass the “real” method type back to your web application. That is how Spring does it. They add a hidden “_method” parameter. And to make our life easier, Spring provides the HiddenHttpMethodFilter, which interprets and converts the hidden paramter into the corresponding HTTP method request. To do so, simply add this filter to your web.xml and map it to your Spring servlet.
PS: I copied this line from a blog.
how does the UsersConnectionRepository stores in userConnections table?
ReplyDeleteRight after the user logs in (authenticated and authorized), the UserConnectionRepository creates a record. See the bean declaration at SocialConfig.java
Delete