Monday, December 10, 2012

Spring Social with JavaConfig (Part 2)

Review

In the previous section, we have discussed the functional requirements of our application. In this section we will study how to generate OAuth keys for Facebook and Twitter. These are required so that Spring Social can communicate with these social media sites.

Table of Contents

Click on a link to jump to that section:
  1. Functional Specs
  2. Generate OAuth keys
    • Facebook
    • Twitter
  3. Spring Social configuration
  4. Spring Security configuration
  5. JavaConfig
    • ApplicationInitializer.java
    • ApplicationContext.java
    • DataConfig.java
    • ThymeleafConfig.java
    • spring.properties
  6. View with Thymeleaf
  7. Layers
    • Domain
    • Repository
    • Service
    • Controller
  8. 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

Generate OAuth keys

Facebook

To generate a Facebook secret key, you need to sign-up for a Facebook account first. Once you have an account, follow these steps:
  1. Open a browser
  2. Visit https://developers.facebook.com/apps
  3. Click on Create New App
  4. Fill-in the App Name
  5. You will be redirected to the Basic settings page
  6. Now copy the App ID value. This is your client ID
  7. Then copy the App Secret value. This is your client secret

Note: The values need to be stored in the spring.properties file (see Part 5).

On my sample app, here's the Basic settings page. I've purposely changed the App ID and App Secret values:


Twitter

To generate a Twitter secret key, you need to sign-up for a Twitter account first. Once you have an account, follow these steps:
  1. Open a browser
  2. Visit https://dev.twitter.com/
  3. Visit the My applications page at https://dev.twitter.com/apps
  4. Click on Create a new application
  5. Fill-in the Name
  6. Fill-in the Description
  7. Fill-in the Website (You will need to invent a fictitious URL)
  8. You will be redirected to the Details tab of your new application
  9. Now copy the Consumer key value. This is your client ID
  10. Then copy the Consumer secret value. This is your client secret

Note: The values need to be stored in the spring.properties file (see Part 5).

On my sample app, here's the Details tab. I've purposely changed the Consumer key and Consumer secret values:



Next

In the next section, we will setup the Spring Social-related configuration through JavaConfig. Click here to proceed.
StumpleUpon DiggIt! Del.icio.us Blinklist Yahoo Furl Technorati Simpy Spurl Reddit Google I'm reading: Spring Social with JavaConfig (Part 2) ~ Twitter FaceBook

Subscribe by reader Subscribe by email Share

95 comments:

  1. Hi krams,
    I've cloned your app from Github repository to my eclipse workspace. When I'm trying to build you app I got an error in pom.xml saying

    "Plugin execution not covered by lifecycle configuration: com.mysema.maven:maven-apt-plugin:1.0:process (execution: default, phase: generate-sources)"

    I can't get that error why it is displaying.

    Can you please suggest me how to build and run this app?


    ReplyDelete
  2. Great tutorial. Maybe add something about where to place the callback url on the Facebook app page? Maybe I missed it. But I appreciate everything youve done. Thank you! I fixed the eclipse error for pom.xml by adding the following.. (if the text comes out wrong then this site might help http://wiki.eclipse.org/M2E_plugin_execution_not_covered)




    org.eclipse.m2e
    lifecycle-mapping
    1.0.0





    com.mysema.maven
    maven-apt-plugin
    [1.0.0,)

    process













    ReplyDelete
  3. Hi sir, i have a problem in connecting facebook so please help me where should i give client ID and client secretid then how to connect facebook


    error Not connected to provider 'facebook'
    Mar 28, 2013 5:14:47 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet spring threw exception
    org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "Connect to Facebook" (facebook/connect:18)

    ReplyDelete
  4. Good tutorial, thanks for putting this together.

    Minor problem in the ThymeleafConfig class line 24:

    resolver.addTemplateAlias("connect/twitterConnected","facebook/connected");

    Should be:

    resolver.addTemplateAlias("connect/twitterConnected","twitter/connected");

    Cheers!

    ReplyDelete
  5. http://2.bp.blogspot.com/-Zdm4t-LBf6U/UJpJEjh7xHI/AAAAAAAABd8/y2RpBfwD7UY/s45/aac46d979989dec1778616a451679a83.png

    ReplyDelete
  6. To generate a Twitter secret key, you need to sign-up for a Twitter account first. Once you have an account, follow these steps:Billig WOW Gold
    World of Warcraft Gold Kaufen Billig

    ReplyDelete
  7. Hello Krams,

    I really need your help on the expression-based access control tutorial. I don't know how to reach you. The question is the following.

    I have seen your posts about expression-based access control. Even though I am new for SpEL, I must use it to implement my spring security project. I want to implement attribute-based access control by using ACL and SpEL. But I failed to go further because of my SpEL limitation. I hope u can help me a little bit how to handle the following problem.

    Consider the following expressions to secure the method 'edit'.

    @PreAuthorize("hasPermission(#data, 'WRITE')and (#user.name == 'David')")
    public Boolean edit(ResourceData data, User user) {
    //do something
    return true;
    }

    Here, what I want to do is securing the method 'edit' by using the two SpELs. the first expression, i.e. hasPermission(#data, 'WRITE' works fine, because I am using ACL for this. But for the 2nd expression I am using database that stores user details of the class 'User'. Assume that I have member variable 'name' for the 'User' class and its corresponding getter and setter methods. I can retrieve 'name' values from DB. But I don't know how to pass those values in this expression, even I don't know how to compare the values in this expression. I am not using XML file for the 2nd expression, I have XML for for the first expression, i.e. for the ACL. By the way this method is quite similar to what you have implemented on the expression-based access control tutorial. The only difference is I want to add extra restrictions by considering user details which is saved from DB.

    Can u provide me some information please? Thanks in advance for your cooperation!

    ReplyDelete
  8. Hi Sir,
    I do follow all your post. its nice and very informative. I have learnt so many things from your post. Thanks you so much Sir for the blogs. Sir, Please keep updating your post. If you have any other blogs or website please do let me know. Thank you in advance.

    ReplyDelete
  9. Hi Sir,
    I do follow all your post. its nice and very informative. I have learnt so many things from your post. Thanks you so much Sir for the blogs. Sir, Please keep updating your post. If you have any other blogs or website please do let me know. Thank you in advance.

    ReplyDelete
  10. thank u for sharing this valuable information.it's very useful to learners.we are providing spring online training.
    spring ONLINE TRAINING

    ReplyDelete
  11. generate 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

    ReplyDelete
  12. I get a lot of great information from this blog. Thanks for sharing this valuable information to our vision. You have posted
    a trust worthy blog keep sharing.
    sap scm training
    sap fico training

    ReplyDelete
  13. This is a very well-written blog. I read and liked the blog and have also bookmarked you. All the best for future endeavors
    sap scm training
    sap fico training

    ReplyDelete
  14. I have read your blog its very attractive and impressive. I like it your blog.

    Spring 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

    ReplyDelete
  15. Very nice your blog and article. I like this blog thank for sharing.

    ทางบ้าน

    ReplyDelete
  16. i will provide you Backlinks and rank in google you website as compare to your competitor also get compititors backlinks list and make their backlinks yours.

    ReplyDelete
  17. Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more. You can take this oppurtunities to improve your stable career option.

    AWS Training in Chennai | Best AWS Training Institute in Chennai | AWS Training in Velachery | AWS Training in OMR | AWS Training with Placements

    ReplyDelete
  18. You done a really great job by sharing your blog.This information was very useful to us.

    AWS Training in Chennai | Best AWS Training Institute in Chennai

    ReplyDelete
  19. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune
    Data science training in kalyan nagar

    ReplyDelete
  20. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    Devops training in Chennai
    Devops training in Bangalore
    Devops Online training
    Devops training in Pune

    ReplyDelete
  21. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging.
    java training in annanagar | java training in chennai

    java training in marathahalli | java training in btm layout

    java training in rajaji nagar | java training in jayanagar

    java training in chennai

    ReplyDelete
  22. I have picked cheery a lot of useful clothes outdated of this amazing blog. I’d love to return greater than and over again. Thanks! 

    java training in chennai | java training in bangalore

    java training in tambaram | java training in velachery

    java training in omr | oracle training in chennai

    ReplyDelete
  23. 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.

    core java training in Electronic City

    Hibernate Training in electronic city

    spring training in electronic city

    java j2ee training in electronic city

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete

  25. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..

    angularjs Training in online

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

    ReplyDelete
  26. I found this informative and interesting blog so i think so its very useful and knowledge able.I would like to thank you for the efforts you have made in writing this article.
    python online training
    python training in OMR
    python training course in chennai

    ReplyDelete
  27. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

    angularjs Training in electronic-city

    ReplyDelete
  28. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic

    best openstack training in chennai | openstack course fees in chennai
    java training in chennai | primavera training in chennai

    ReplyDelete
  29. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea.
    here by i also want to share this.

    Java training in Chennai

    Java training in Bangalore

    Java online training

    Java training in Pune

    ReplyDelete
  30. I think this is one of the best blog for me because this is really helpful for me. Thanks for sharing this valuable information for free
    packers and movers in patna

    ReplyDelete
  31. ................................................................................
    read visit info.

    ReplyDelete
  32. This is best one article so far I have read online, I would like to appreciate you for making it very simple and easy
    Regards,
    Devops Training in Chennai | Devops Certification in Chennai

    ReplyDelete
  33. An amazing web journal I visit this blog, it's unbelievably wonderful. Oddly, in this blog's content made without a doubt and reasonable. The substance of data is informative.
    An astounding web diary I visit this blog, it's inconceivably magnificent. Strangely, in this current blog's substance made point of fact and sensible. The substance of information is instructive.
    A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  34. 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.
    Spring training in Electronic City

    ReplyDelete
  35. This comment has been removed by the author.

    ReplyDelete
  36. Thanks for sharing such a good blog.
    "Yaaron media is one of the rapidly growing digital marketing company in Hyderabad,india.Grow your business or brand name with best online, digital marketing companies in ameerpet, Hyderabad. Our Services digitalmarketing, SEO, SEM, SMO, SMM, e-mail marketing, webdesigning & development, mobile appilcation.
    "
    Best web designing companies in Hyderabad
    Best web designing & development companies in Hyderabad
    Best web development companies in Hyderabad

    ReplyDelete
  37. Spesial untuk Pemula! Berikut Situs Judi Resmi dengan Aman
    daftar samgong

    ReplyDelete
  38. Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free
    Get all of the best cars and motorcycles for free

    ReplyDelete
  39. Water Hack Burns 2 lb of Fat OVERNIGHT

    More than 160 thousand women and men are trying a easy and secret "liquids hack" to lose 1-2 lbs each and every night in their sleep.

    It is easy and works on everybody.

    This is how you can do it yourself:

    1) Take a glass and fill it up half full

    2) Then learn this weight loss HACK

    so you'll be 1-2 lbs lighter as soon as tomorrow!

    ReplyDelete
  40. Very useful and informative blog. Thank you so much for these kinds of informative blogs.

    7 tips to start a career in digital marketing

    “Digital marketing is the marketing of product or service using digital technologies, mainly on the Internet, but also including mobile phones, display advertising, and any other digital medium”. This is the definition that you would get when you search for the term “Digital marketing” in google. Let’s give out a simpler explanation by saying, “the form of marketing, using the internet and technologies like phones, computer etc”.

    we have offered to the advanced syllabus course digital marketing for available join now

    more details click the link now

    https://www.webdschool.com/web-development-course-in-chennai.html

    ReplyDelete
  41. Thank for this blog are more informative step by step and useful information.
    I here by attached my site would you see this blog

    Web designing trends in 2020

    When we look into the trends, everything which is ruling today’s world was once a start up and slowly begun getting into. But Now they have literally transformed our lives on a tremendous note. To name a few, Facebook, Whats App, Twitter can be a promising proof for such a transformation and have a true impact on the digital world.

    we have offered to the advanced syllabus course web design and development for available join now

    more details click the link now

    https://www.webdschool.com/web-development-course-in-chennai.html

    ReplyDelete
  42. This is how my friend Wesley Virgin's story starts in this SHOCKING AND CONTROVERSIAL video.

    As a matter of fact, Wesley was in the army-and soon after leaving-he revealed hidden, "MIND CONTROL" tactics that the government and others used to get anything they want.

    These are the same methods tons of celebrities (notably those who "come out of nothing") and the greatest business people used to become wealthy and famous.

    You probably know that you use only 10% of your brain.

    That's mostly because most of your brain's power is UNCONSCIOUS.

    Perhaps that thought has even taken place INSIDE OF YOUR own head... as it did in my good friend Wesley Virgin's head about seven years back, while driving an unregistered, beat-up bucket of a car with a suspended license and $3.20 on his banking card.

    "I'm absolutely frustrated with living paycheck to paycheck! When will I become successful?"

    You've taken part in those questions, ain't it so?

    Your success story is going to happen. You just need to take a leap of faith in YOURSELF.

    CLICK HERE TO LEARN WESLEY'S METHOD

    ReplyDelete
  43. I will recommend anyone looking for Business loan to Le_Meridian they helped me with Four Million USD loan to startup my Quilting business and it's was fast When obtaining a loan from them it was surprising at how easy they were to work with. They can finance up to the amount of $500,000.000.00 (Five Hundred Million Dollars) in any region of the world as long as there 1.9% ROI can be guaranteed on the projects.The process was fast and secure. It was definitely a positive experience.Avoid scammers on here and contact Le_Meridian Funding Service On. lfdsloans@lemeridianfds.com / lfdsloans@outlook.com. WhatsApp...+ 19893943740. if you looking for business loan.

    ReplyDelete
  44. WOW! I Love it...
    and i thing thats good for you >>


    DREAM MEANNING Thank you!

    ReplyDelete
  45. Really useful information. Thank you so much for sharing.It will help everyone.Keep Post.

    AI Training in Hyderabad

    ReplyDelete
  46. thanks for sharing we at SynergisticIT offer the best aws training california

    ReplyDelete

  47. Nice article and thanks for sharing with us. Its very informative

    Plots in PHARMA CITY


    ReplyDelete
  48. Good blog informatve for readers such a nice content keep posting thanks for sharing Beard Transplant

    ReplyDelete
  49. I liked your site very much, but brother, bsc 2nd year time table you have put DA in all these Directory Submission websites, why have you not added bsc.

    ReplyDelete
  50. good article I like the information you mentioned.thank you so much

    joker123


    ReplyDelete

  51. ufafc

    แตกง่าย แตกไว แตกในได้เลย

    ReplyDelete
  52. I was very happy to find this site. I would like to thank you for this special reading. Thank you very much
    wordpress Casino
    ufa88kh.blogspot Casino
    youtube Casino
    កាស៊ីណូអនឡាញ

    ReplyDelete
  53. Very informative and well-written post! Quite an interesting and nice topic chosen for the post. Your need social service our many type service here please check buy facebook followers

    Philips

    ReplyDelete
  54. Wireless LED Lights are designed to increase safety, security and convenience anywhere around the home. Signature features include motion.

    ReplyDelete
  55. I appreciate how this blog breaks down complex concepts into easy-to-understand explanations. The writer has a knack for simplifying technical topics without oversimplifying them. It's a go-to resource for beginners and seasoned professionals alike.
    Also, check Java training in Nagpur

    ReplyDelete
  56. This comment has been removed by the author.

    ReplyDelete