If our authenticated User is in stored in Session - (and quest in Showcase.)
Although I want to take advantage of using Spring Security at some point, we can only refactor so much of our existing application at this point, and I'm working on understanding Spring Social Showcase so I could leverage Spring Social.
I was stumped for a while on how, within Spring Social Showcase, the "facebook connect" part was working - Couldn't figure out how the ConnectionController was getting access to the logged-in user (userId.) If I'm understanding correctly it's related to the setup in SocialConfig where ConnectController is created from connectionFactoryLocator, connectionRepository so that the connectionRepository is created from the current logged in user of the Request. I'll try to research more on how Spring works there (I'm still somewhat green with Spring) but I thought the default Bean definition was "singleton" so I'm curious how, on different requests from different users using the Spring Social application, the bean ConnectController would end up with the appropriate user connectionRepository - I would have figured just one instance of ConnectionController would exist for the showcase as a singleton? I'm guessing it has something to do with the value="request", proxyMode=ScopedProxyMode.INTERFACES defined for the connectionRepository?)
My main questions is, since I'm not using a SecurityContextHolder to hold my authentication information, how should I get a handle to the HttpSession in my version of SocialConfig, so that I could pull the user out and be able to use the standard ConnectController when it's created from a ConnectionRepository instance:
Code:
@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public ConnectionRepository connectionRepository() {
//HttpSession even possible here ?????
User user = (User)session.getAttribute("user");
return usersConnectionRepository().createConnectionRepository(user.getUserId()));
}
Is there some other way I should handle this if (at least for now) the HttpSession is holding our authenticated User? I could of course create my own ConnectController and pull what I need out in there, but since ConnectionController is part of the core spring social library I figured I should try to leverage it 'as is' first if possible?
Thanks for any help
Spring MVC reference in non-Spring MVC code
Hi Craig,
Sure thing. I am tasked with integrating social networking into our existing site. Our legacy code uses a different MVC framework, with Spring MVC introduced only recently along with Spring Social. In lieu of a complete rewrite and code migration into Spring MVC, the new social code must play nice with the existing legacy framework.
I am using Spring Social to establish the Connections, and making them available in the existing (non-Spring) controllers for use. The only Social imports within the old framework are Connection, UserProfile and ProviderSignInUtils, with ProviderSignInUtils forcing a reference to Spring MVC.
It's not that big of a deal, and I have created a wrapper around ProviderSignInUtils to change the API to use the Servlet API classes, but thought it would be cleaner if Spring Social offered the alternatives.
Thanks,
-Frank