Announcement Announcement Module
Collapse
No announcement yet.
Question about mapping users to social sites Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about mapping users to social sites

    Our local application user database is currently used to service multiple sites(front-ends).

    What would be the ideal way to extend the current spring social architecture so we could map local accounts to a group (List<>) of social accounts based on the site they're using?

    In the example of the UserAccount table used by Spring Social, I think it'd be something similar to adding a new column (i.e. localSiteId) we could key off of.

    How would you implement (or recomend doing) this?

    Thank you in advance for your time.

    Regards

  • #2
    This sounds similar to the question posed at http://forum.springsource.org/showth...r-twitter-apps. But in this case, I think that you're not so interested in using the different application ID/secret pairs and more interested in identifying which front-end is associated with a given connection. This is a much simpler problem to solve (albeit, not trivial).

    I'd say that you could add a new column to the UserConnection table. But then you'll also need to create a custom connection repository to be aware of that column. That'd probably mean that you'd need to change the signature of the connection repository methods so that you can identify the front-end app. And that means you'd need to change ConnectController/ProviderSignInController to capture the front-end app ID and feed that to the new connection repository. In short, you'll be subclassing and/or creating custom implementations of most of Spring Social's classes.

    To be fair, I've only given this problem a high-level thought...a deeper investigation might reveal that it's much easier or much harder than I described.

    Comment


    • #3
      Craig,

      Thanks for the response.

      I started running through and actually trying to implement the code changes required to do this, but, I think your assumption was pretty spot on. The more I worked on it, the more interfaces I started breaking and having to write myself. I'm basically rewriting much of the spring-social-core classes (reinventing the wheel).

      Could I request, instead, that spring-social-core be expanded to support multiple sites (perhaps default to a single site model with a localSiteId of "local" or something similar?) This could probably prove useful too to others doing things like virtualhosting or, like me, who have to support a central registration source for multiple external sites.

      I don't mind doing the work, but, if I do this on my own, I'm afraid it'll end up being such a customized implementation, I'll get left behind on any new versions/features from this point forward.

      Thanks for your consideration..

      Comment


      • #4
        You may request this and anything else you like via the issue tracker at https://jira.springsource.org/browse/SOCIAL. I can't guarantee that it will be bumped up in priority over anything else that's already in the pipeline, but if there's enough interest (e.g., votes for the issue), then that gives me reason to look into it.

        And, I welcome contributions. You say that you don't mind doing the work, but are afraid that you'll be left behind if you do a custom implementation. The good news is that since the work is in GitHub, you simply must fork the project, make the changes, monitor and merge in any changes upstream, and when you're done submit a pull request. GitHub is awesome for this kind of thing.

        FWIW, if you decide you want to fork and submit a pull request, know that I am quicker to accept and merge in the pull requests if the code you submit is consistent in styling to the existing codebase and if you include lots of tests around your work.

        Comment


        • #5
          Thanks Craig,

          I started working on this yesterday and will try to get it working ASAP so I can fork it and get some feedback

          Comment


          • #6
            I'm working on testing the code (but am new to Gradle), can you help point me in the right direction..

            I'm trying to find where in the spring-social-config test suite FakeSocialAuthenticationService is wired/instantiated.

            More specifically, when the test context is started up, where are the constructor arguments are being defined for:

            Code:
            	public FakeSocialAuthenticationService(String appId, String appSecret)
            Thanks in advance

            Comment


            • #7
              If you're talking about at configuration time, those are configured either in XML or JavaConfig where you enable support for a specific provider. In this case, since it's a fake for a test, that's in either SocialConfigNamespaceTest-context.xml or SocialConfig.java, depending on whether it's the test for XML config or the test for JavaConfig.

              If you're wanting to know the deeper details of how that works under the covers, then you'll need to look at how configuration stuff works. It's not an easy answer and it kind of depends again on whether you're doing XML config or JavaConfig. Essentially, almost all of the stuff under src/main/java in the spring-social-config (plus some support from Spring Framework core classes) work together to make that happen. I'd give you more details, but it'd take an entire article-length write-up to explain how it works. I encourage you to study and get to know how to create custom configuration support for Spring.

              (Note that even though it's tricky business to create custom configuration support, I've made it simple to extend what's already there for Spring Social. That is, unless what you're wanting to do requires you to change stuff deeper than the hooks that I exposed.)

              Comment


              • #8
                Thanks Craig,

                It's *slowly* starting to make more sense. I seriously envy your grasp on the language/concepts.

                Code:
                	protected BeanDefinition getConnectionFactoryBeanDefinition(String localSiteId, String appId, String appSecret, Map<String, Object> allAttributes) {
                		return BeanDefinitionBuilder.genericBeanDefinition(connectionFactoryClass).addConstructorArgValue(localSiteId).addConstructorArgValue(appId).addConstructorArgValue(appSecret).getBeanDefinition();
                	}
                	
                	protected BeanDefinition getAuthenticationServiceBeanDefinition(String localSiteId, String appId, String appSecret, Map<String, Object> allAttributes) {
                		return BeanDefinitionBuilder.genericBeanDefinition(authenticationServiceClass).addConstructorArgValue(localSiteId).addConstructorArgValue(appId).addConstructorArgValue(appSecret).getBeanDefinition();
                	}

                Comment


                • #9
                  we're making progress... hopefully i'll have something useful to contribute soon..

                  Comment


                  • #10
                    i think i hit a big snag in the road that might require me to rethink/redesign my approach.

                    I got the Spring Social libraries modified, compiled, and tested, but, when I tried to run a copy of my project code that links to real providers, I got an exception on startup. I didn't account for the provider APIs' dependency on the Spring Social core libraries.

                    Code:
                    Caused by: java.lang.NoSuchMethodError: org.springframework.social.connect.support.OAuth2ConnectionFactory.<init>(Ljava/lang/String;Lorg/springframework/social/oauth2/OAuth2ServiceProvider;Lorg/springframework/social/connect/ApiAdapter;)V
                    	at org.springframework.social.facebook.connect.FacebookConnectionFactory.<init>(FacebookConnectionFactory.java:45)
                    	at org.springframework.social.facebook.connect.FacebookConnectionFactory.<init>(FacebookConnectionFactory.java:35)
                    	at com.mydomain.social.config.SocialConfig.connectionFactoryLocator(SocialConfig.java:60)

                    I need to rethink my approach... Impacting the provider APIs and breaking their dependencies is a no-go.

                    back to the drawing board..

                    Comment


                    • #11
                      In the meantime, while i circle back on this, I opened a Jira request for this.

                      For anyone following/reading this thread, please take a minute to review/vote on the issue if you think it'd be a positive contribution.

                      https://jira.springsource.org/browse/SOCIAL-353


                      Thanks!

                      Comment

                      Working...
                      X