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:
|
Subscribe by reader Subscribe by email Share
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
Deletehow I can use MongoDB instead of mysq?. i faced problems in configuration so what are the changes that i have to make? thank you for help
DeleteMark,
ReplyDeleteI'm having trouble instantiating connect controller. At the time it is created, there is no user logged in (app just starts). So, everytime it fails during connectionRepository() due to "no user signed in".
Please help!
-Ryan
I face exactly the same problem as Ryan.. its fails during connectionRepository() due to "no user signed in".
ReplyDeletecheers
Joerg
how I can use MongoDB instead of mysq?. i faced problems in configuration so what are the changes that i have to make? thank you for help
ReplyDeletegenerate OAuth keys for Facebook and Twitter (Online Java Training) Generate OAuth keys Java Training in Chennai Consumer key and Consumer secret values: J2EE Training in Chennai
ReplyDeleteThanks for all your information.Website is very nice and informative content.
ReplyDeleteMongoDB Training in Chennai
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteSpring online training Spring online training Spring Hibernate online training Spring Hibernate online training Java online training
spring training in chennai spring hibernate training in chennai
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletecore java training in Electronic City
Hibernate Training in electronic city
spring training in electronic city
java j2ee training in electronic city
Let me tell you something...
ReplyDeleteWhat I'm going to tell you may sound kind of weird, and maybe even a little "out there..."
BUT what if you could just click "PLAY" to LISTEN to a short, "musical tone"...
And magically attract MORE MONEY to your life??
What I'm talking about is BIG MONEY, even MILLIONS of DOLLARS!!
Do you think it's too EASY?? Think it's IMPOSSIBLE?!?
Well, I've got news for you.
Usually the greatest blessings in life are the SIMPLEST!!
Honestly, I will provide you with PROOF by allowing you to listen to a real-life "magical money tone" I've produced...
You just hit "PLAY" and you will start having more money come into your life... starting almost INSTANTLY...
GO here now to play this marvelous "Miracle Money-Magnet Tone" - as my gift to you!!
I enjoyed your blog Thanks for sharing such an informative post. We are also providing the best services click on below links to visit our website.
ReplyDeletedigital marketing company in nagercoil
digital marketing services in nagercoil
digital marketing agency in nagercoil
best marketing services in nagercoil
SEO company in nagercoil
SEO services in nagercoil
social media marketing in nagercoil
social media company in nagercoil
PPC services in nagercoil
digital marketing company in velachery
digital marketing company in velachery
digital marketing services in velachery
digital marketing agency in velachery
SEO company in velachery
SEO services in velachery
social media marketing in velachery
social media company in velachery
PPC services in velachery
online advertisement services in velachery
online advertisement services in nagercoil
web design company in nagercoil
web development company in nagercoil
website design company in nagercoil
website development company in nagercoil
web designing company in nagercoil
website designing company in nagercoil
best web design company in nagercoil
web design company in velachery
web development company in velachery
website design company in velachery
website development company in velachery
web designing company in velachery
website designing company in velachery
best web design company in velachery
Thanks for Sharing - ( Groarz branding solutions )