Announcement Announcement Module
Collapse
No announcement yet.
Adding Spring Social to Spring MVC+Security app, step by step Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding Spring Social to Spring MVC+Security app, step by step

    I've written up a step by step guide to adding Spring Social to a Spring MVC and Spring Security Web app, in three parts:

    http://harmonicdevelopment.tumblr.co...mvc-and-spring

    Unlike the quick start the focus is on adding Spring Social features to an existing app that has its own sign up and sign in processes already, that are being powered by Spring MVC and Spring Security.

    It covers:

    1. Implementing persistence of social connection data
    2. Configuration details for Spring Social, Spring MVC, and Spring Security
    3. Adding "Sign In With ..." functionality
    4. Adding features to let existing users of your app connect their social accounts
    5. Integration with Spring Security, including "remember me" support

    Any feedback would be much appreciated, thanks.

  • #2
    Thanks for the articles. I scanned them briefly and like what I see. I'll try to find time soon to review them in more detail and send you feedback. In the meantime, I've posted links to the articles on Spring Social's homepage (under Buzz).

    Comment


    • #3
      Helpful

      That is very helpful to speed up on the integration.

      I will have some questions along the integration process.

      Here is my first set of questions:

      What is the difference between
      Code:
       List<SocialUser> findByUserIdAndProviderId(String userId, String providerId);
      and
      Code:
      List<SocialUser> findPrimaryByUserIdAndProviderId(String userId, String providerId);
      Both take the same set of parameters and return the same object type. What is the "primary"?
      Last edited by vw729; Dec 27th, 2011, 05:37 PM.

      Comment


      • #4
        Ah, good question. Spring Social allows for the possibility of, for example, associating multiple Twitter accounts with one user account in your application. Of these possibly multiple connections, one is considered the "primary". Here is part of the JavaDoc comment for Spring Social's ConnectionRepository.getPrimaryConnection(Class<A> apiType):

        * Get the "primary" connection the current user has to the provider of the given API e.g. Facebook.class.
        * If the user has multiple connections to the provider associated with the given apiType, this method returns the one with the top rank (or priority).

        In my code I have a "rank" field/column for the connections. I assign an incrementing value to that column for every new connection a user adds to a specific provider (e.g. Facebook). The first connection gets a rank of 0. For now I am just making that first connection, with rank == 0, the primary. A more full featured implementation would give the user some kind of UI for selecting a primary, I suppose.

        So, the difference between the two methods from my blog posts is that the "findPrimary..." method sorts by rank, ascending. I then call ".get(0)" on the results when calling that method, so I should probably just change the method to return SocialUser, not List<SocialUser>, to make things more clear.
        Last edited by sdouglass; Dec 27th, 2011, 02:24 PM.

        Comment


        • #5
          To be consistent with the product document, the Social User Connection Entity class shall use a compound key formed by userId, providerId, and providerUserId. Although a compound key Hibernate implementation is not as straight forward as a regular entity id, it is workable. Can you share your implementations on those DAO methods with collection parameters, namely,

          List<SocialUser> findByUserIdAndProviderUserIds(String userId, MultiValueMap<String, String> providerUserIds);

          Although you share a pseudo query, I don't know how it shall be handled for Hibernate.

          Comment


          • #6
            You can find Hibernate implementation code in the Spring Social JPA Quickstart:

            https://github.com/mschipperheyn/spr...Hibernate.java

            That was where I looked if I had any issues figuring out the Hibernate code for the queries.

            Comment

            Working...
            X