Blogs

SpringSource Blog

Socializing Spring Applications

Craig Walls

Increasingly, web surfers are using the internet to connect with friends, family, and colleagues using social networking sites. Conversations that once took place over email are now taking place in short messages written on someone's Facebook wall or in a brief tweet on Twitter. Connections once made with a handshake are now created using LinkedIn. And when a face-to-face meetings are desired, travel details can be shared using TripIt.

Just as people are using these social networking sites to interact with each other, businesses are also finding ways to inject themselves into the social graph so that they can connect in a more personal way with their customers and also make their web sites an extension of their customers' social experiences.

This week, we are pleased to have released the first milestone of Spring Social, a new extension to Spring that aims to provide a platform upon which social-ready Spring applications may be built. I thought I'd take this opportunity to introduce you to Spring Social and give you a taste of what it offers.

Securely Sharing Social Data

On the surface, developing applications that interact with the various social networks may appear straightforward. Since most of the social networks offer a REST API, Spring's RestTemplate would seem to be all you need. But you'll quickly discover that those social REST APIs are protected by OAuth and that signing a request sent through RestTemplate with OAuth credentials is a non-trivial task.

OAuth is an open protocol that enables a user to share their data hosted on one or more service providers with another application. With access to that data, the application can aggregate, present, and process the information in ways that provide additional value beyond what the service providers themselves ever intended or imagined.

Virtually all of the major service providers support OAuth, including Twitter, Facebook, LinkedIn, TripIt, and Foursquare, as well as the Google and Yahoo APIs. Therefore, OAuth is essential to developing social-ready applications.

At the beginning of an OAuth-secured interaction is a back-and-forth conversation that is commonly known as the "OAuth Dance". In a typical OAuth Dance, there are three parties involved:

  • The service provider (such as Twitter or LinkedIn)
  • The user who wants to access or update data hosted by that service provider.
  • The consumer application that the user wants to share their data with.

The key steps in this dance are as follows:

  1. The consumer application directs the user to the service provider's site to sign in and authorize the consumer.
  2. Assuming that the user agrees to grant the consumer access to their data, the flow is sent back to the consumer application.
  3. The consumer application receives an access token from the service provider.

The access token received in step 3 is the "valet key" that must accompany any request to the service provider's REST API. In OAuth 1, this means that the access token, along with the request URL, parameters, and a few other bits of information are collected together in a base string, encrypted, and sent on the request in an Authorization header. Constructing this header and attaching it to the request is a complicated task. This is the reason that using RestTemplate to access OAuth-secured resources is difficult. If you get it wrong, the service provider will respond with an HTTP 401 for any resource you try to access and debugging the encrypted Authorization header is tricky.

Working with Social Templates

A key component of Spring Social is its collection of social templates. These templates (which leverage RestTemplate under the covers) expose operations of the service providers that they model, handling the intricacies of adding OAuth Authorization headers for you.

Spring Social 1.0.0.M1 includes 4 social templates to choose from:

  • TwitterTemplate
  • FacebookTemplate
  • LinkedInTemplate
  • TripItTemplate

To use any of these templates, simply create an instance of it, providing the OAuth connection details through constructor arguments. For example, to create an instance of TwitterTemplate:

TwitterTemplate twitter = new TwitterTemplate(apiKey, apiSecret, accessToken, accessTokenSecret);

The four parameters to TwitterTemplate's constructor are all Strings values. The API key and API secret are given to you when you register your application with Twitter (see http://dev.twitter.com/apps/new). The access token and access token secret are granted to your application on a per-user basis at the end of the OAuth Dance with Twitter. At this point, I'm going to assume that you've already obtained all four of these values; we'll circle back to how to manage API keys and tokens a little later.

Creating instances of the other social templates isn't much different. LinkedInTemplate and TripItTemplate each have constructors with the same argument list as the TwitterTemplate constructor shown above. Since Facebook's API security is based on OAuth 2, FacebookTemplate has a slightly simpler constructor that only requires the value of the access token:

FacebookTemplate facebook = new FacebookTemplate(accessToken);

Once you have an instance of one of these social templates, what can you do with it? If you're using TwitterTemplate, perhaps you want to know the authenticated user's Twitter screen name:

String screenName = twitter.getProfileId();

Or for something a bit more involved, maybe you could send a tweet on behalf of the user:

twitter.updateStatus("Hey, I'm tweeting with #Spring Social!");

Similarly, with a FacebookTemplate in hand, you can post to the user's wall:

facebook.updateStatus("Spring Social can also post to Facebook!");

And if you want to examine a user's upcoming travel itineraries, TripItTemplate's getTrips() can oblige:

List trips = tripIt.getTrips();
for(Trip trip : trips) {
    System.out.println("I'm traveling to " + trip.getPrimaryLocation() +
                                 " on " + trip.getStartDate());
}

This is just a sampling of the kinds of things you can do with Spring Social's templates. Check out the API documentation to see the other operations that are available.

Managing OAuth Connections

When I created the TwitterTemplate instance above, I glossed over where the API key/secret and the access token came from. Initially, the access token would be received after a user authorizes the application to access their data hosted on the service provider. But you probably don't want to force your users to perform authorization every time they use your application, so you'll need a way to store the access tokens long-term for reuse in future sessions.

In its first milestone release Spring Social doesn't provide an OAuth token management strategy, leaving it up to the application to obtain and manage OAuth details for itself. This is something that we intend to address for 1.0 Milestone 2. In the meantime, however, we can look to Greenhouse for an example of how this might take shape.

In Greenhouse, all of the information about a service provider is stored in a relational database in a ServiceProvider table with the following schema:

As you can see, the ServiceProvider table includes, among other things, the provider's API key and secret. To access an individual service provider record, Greenhouse uses JdbcServiceProviderFactory, an implementation of a ServiceProvider interface:

package com.springsource.greenhouse.connect;

public interface ServiceProviderFactory {

    ServiceProvider getServiceProvider(String name);

    <S> ServiceProvider<S> getServiceProvider(String name, Class<S> serviceType);

}

To retrieve a Twitter service provider from the database, Greenhouse simply calls the getServiceProvider() method, passing in "twitter" (the provider's name) as a parameter. In the case of Twitter, this ultimately returns an instance of TwitterServiceProvider which is an implementation of the ServiceProvider interface.

The ServiceProvider has several methods, but two of them are interesting with regard to token management. The first, connect(), is used by Greenhouse to create a connection between one of its users and their social identity on the service provider:

void connect(Long accountId, AuthorizedRequestToken requestToken);

At the point where the connect() method is called, Greenhouse has gone through enough of the OAuth dance to have an authorized request token in hand. Passing those along with the user's account ID will create a connection in the AccountConnection table. The AccountConnection table has the following schema:

With the connection having been made, you can use ServiceProvider's getServiceOperations() method to get an instance of TwitterOperations (the interface that TwitterTemplate is based on):

TwitterOperations twitter = twitterProvider.getServiceOperations(accountId);

Under the covers of getServiceOperations(), the ServiceProvider implementation retrieves the access token and uses it along with its own API key and secret to construct a TwitterTemplate, freeing the application from having to deal with the access token directly.

In Greenhouse, the TwitterOperations instance is a request-scoped bean, created via a factory method in ServiceProvidersApiConfiguration, using Spring JavaConfig like this:

@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public TwitterOperations twitter(ServiceProvider<TwitterOperations> twitterProvider, @Value("#{request.getAttribute('account')}") Account account) {

    return twitterProvider.getServiceOperations(accountId(account));

}

As a Spring bean, the TwitterOperations can be injected into any other Spring bean that needs to exchange data with Twitter. For instance, in Greenhouse, the EventsController is the Spring MVC controller that handles web interaction for all event-oriented requests. It uses a TwitterOperations to post tweets about an event on the user's behalf. It is injected with the TwitterOperations bean through its constructor:

@Inject
public EventsController(EventRepository eventRepository, TwitterOperations twitterApi) {
    this.eventRepository = eventRepository;
    this.twitterApi = twitterApi;
}

As I mentioned, we intend to transition the ServiceProvider facility from Greenhouse to Spring Social in milestone 2. Obviously, the current implementation supports relational storage of OAuth details, but we're eager to hear from you with ideas on other implementations that maintain OAuth information in other kinds of stores.

Running Greenhouse

Although you can view the running Greenhouse application at http://greenhouse.springsource.org, you'll probably want to checkout the Greenhouse source code and try it out for yourself as you explore Spring Social. To do that, follow the following steps:

  1. Checkout the Greenhouse source code:
    git clone git://git.springsource.org/greenhouse/greenhouse.git
  2. Import the Greenhouse project into SpringSource Tool Suite
  3. Drag the Greenhouse project into the SpringSource tcServer (under the Servers tab) to deploy the application.
  4. Edit the run configuration for tcServer to add "-DspringProfiles=embedded" to the end of the list of VM arguments.
  5. Start the server and access http://localhost:8080/greenhouse in your web browser.

Step 4 is required because Greenhouse uses the new environment beans feature of Spring 3.1, which makes it possible to identify beans that will only be created for certain profiles. Setting that property indicates that the application should be run with the "embedded" profile.

Conclusion

Spring Social 1.0 M1 is the first step in an exciting quest to bring social networking capabilities to Spring. I encourage you to download Spring Social, check out the code, and provide feedback either through issue tracking, the Spring Social Forum, or via the Greenhouse mailing list.

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • Twitter
 

43 responses


  1. FYI: The pom.xml points to scribe 1.0.3 which isn't available in maven central. I had to change it to 1.0.7.


  2. Are you referring to the Greenhouse pom.xml? We're updating that right now.

    If you're referring to the Spring Social pom.xml, then you might want to pull the latest stuff. Spring Social no longer has a pom.xml! It's a Gradle-built project now (and refers to Scribe 1.0.6 as an optional dependency).


  3. Sorry, was referring to the Greenhouse pom.xml.


  4. No problem. Pull Greenhouse again…its pom.xml is referring to Scribe 1.0.7 now.


  5. Is this what Spring Roo 1.1 uses for its social networking features?


  6. Andrew: No, Spring Roo 1.1 keeps it fairly simple with a view-based Twitter widget from http://widgets.twimg.com/j/2/widget.js. Nonetheless, there may be some opportunity for introducing Roo with Spring Social for a richer set of social functionality in Roo. Any suggestions on what that might look like?


  7. It is a great ideal. I do have some questions, however.

    I try the Greenhouse sample. I get a null pointer exception after I select not to pull data from Facebook. If I select yes, the registration form is blank. So, what is the point to sign up from FB?


  8. Hello,
    are there any plans to integrate spring social with spring security?

    thanks & best,
    milan


  9. Is there a plan for supporting RSS and/or Atom too ?
    Or, is it supported through another Spring module ?
    Thanks.


  10. Nice to see Spring tackling the challenge of interacting with social networking sites. I guess consistency is important, but I with the API developers could come up with a word that was a little more inspiring than 'template.' It always makes me feel like I'm doing something mundane. Petty complaint, I know.

    We featured this blog post at the top of the TSS newsthread today.

    "Remember, Remember, The Fifth of November."


  11. Hey Vic,
    I am unable to reproduce your issue with connecting to Facebook in Greenhouse. Can you open a JIRA issue at https://jira.springframework.org/browse/GREENHOUSE that includes steps we can follow to reproduce the problem. Also, can you please include information about your environment. Are you getting this on the production instance of Greenhouse at http://greenhouse.springsource.org? Is this happening to you with a local embedded instance? Have you pulled down the latest code? All things to consider.

    Just to confirm, yes, you can Connect your Account with Facebook and after doing that "Sign in with Facebook". The point is you no longer have to enter your Greenhouse credentials to sign-in, you can simply one-click sign-in using your linked Facebook identity.

    Keith


  12. Milan,

    Spring Social does already build on Spring Security for OAuth. Specifically, it uses the "Spring Security OAuth" project lead by Ryan Heaton (http://www.linkedin.com/in/ryanheaton). The Spring Security OAuth project originated at Codehaus (see http://spring-security-oauth.codehaus.org/) and has recently moved under the org.springframework.security umbrella. As Craig mentioned in the article, it is used to sign requests to service providers such as Facebook and Twitter with the required Authorization details. Spring Social can also work with Scribe (https://github.com/fernandezpablo85/scribe-java), which is an OAuth client library lead by Pablo Fernandez (https://github.com/fernandezpablo85) that has a nice programmatic API.

    Were there other Spring Security-related features you'd like to see built upon in Spring Social? There are a number we have in mind, such as a model for social user identity, data encryption of OAuth keys, and reset password functionality (all three of which have been implemented in the Greenhouse reference application as a start). What do you have in mind?

    Keith


  13. Dominique,

    Spring MVC, part of the core Spring Framework project, provides support for ATOM and RSS feeds. If you need something that isn't already there, don't hesitate to open a enhancement request at https://jira.springframework.org/browse/SPR.

    Keith


  14. @Dominique De Vito
    RSS and ATOM is supported with Spring Integration (see http://blog.springsource.com/2010/10/29/spring-integration-2-0-release-candidate-1/), as well as other remoting adapters such as XMPP, FTP/SFTP and Twitter as well which will be refactored to use Spring Social as soon as the first release of Spring Social is out.


  15. I'm trying to use TwitterTemplate in my application. I have been able to login, through Twitter and authorize my application. My application had already used spring security username/password authentication. So, after I successfully authorize the app on Twitter, I will want to give access to the user to the protected resources. Is there an example how to update spring security configuration to do this? I have tried to look for an implementation of AuthenticationManger in Spring Social, but did not find one…
    Not sure that this is the right approach, so please give me some guide lines.

    Thanks,
    devsprint


  16. Devsprint,

    Have you reviewed the Greenhouse reference application code and behavior? It shows how you can connect your member Account to a service provider such as Twitter. Once you have signed in, your Principal identity (an Account object in Greenhouse's case), can then be used to obtain a reference to an authorized TwitterOperations API. That API can then be used to access protected resources in a strongly typed manner.

    Greenhouse uses Spring Security for the sign in process, and plugs in a custom AuthenticationManager implementation that authenticates Accounts using an AccountRepository. It's Spring Security config is defined in /WEB-INF/spring/security.xml. The UI @Controller used to connect member Accounts to ServiceProviders is defined in the com.springsource.greenhouse.connect package.

    Keith


  17. Hi Keith,

    For some reason, I can't reproduce the exception with the same browser on my PC. I, however, can reproduce the exception with another browser. I have submitted a bug report.

    I think this project is very exciting. It definitely will bring a lot of value to our clients.

    - Vic


  18. Unfortunately getting a bunch of errors when trying to build the project.

    mvn package =>

    [INFO] Error building POM (may not be this project's POM).
    Project ID: com.google.guava:guava:jar:r07
    Reason: Cannot find parent: com.google:google for project: com.google.guava:guava:jar:r07 for project com.google.guava:guava:jar:r07

    mvn eclipse:eclipse =>

    [INFO] Error building POM (may not be this project's POM).
    Project ID: org.apache.tiles:tiles-parent:pom:2.2.2
    Reason: Cannot find parent: org.apache.tiles:tiles-master for project: org.apache.tiles:tiles-parent:pom:2.2.2 for project org.apache.tiles:tiles-parent:pom:2.2.2


  19. Marc,
    I am unable to reproduce your build problem. You might want to try cleaning out your Maven repository for those two modules. Also, I would make sure you are using a recent version of Maven 2 or Maven 3. I happen to be building with Maven 2.2.0 locally on Mac OS.

    Keith


  20. Thank you, Keith.
    I'm using Maven 2.2.1 which came along with STS 2.5.0.
    Finally, it pointed out that the problem was caused by our archiva server.
    After fixing this, I was able to build the project without any issues.

    Marc


  21. Hello,

    Thanks for the great example. The app seems to build and run fine, but I noticed these 6 errors in the Problems tab. Just curious as to why these errors are occuring:

    No constructor with 0 arguments defined in class 'com.springsource.greenhouse.account.JdbcAccountRepository' security.xml /greenhouse/src/main/webapp/WEB-INF/spring line 40 Spring Beans Problem

    No constructor with 0 arguments defined in class 'com.springsource.greenhouse.activity.action.JdbcActionRepository' integration-activity.xml /greenhouse/src/main/resources/com/springsource/greenhouse/activity line 12 Spring Beans Problem

    No constructor with 0 arguments defined in class 'com.springsource.greenhouse.activity.badge.BadgeSystemFactoryBean' integration-activity.xml /greenhouse/src/main/resources/com/springsource/greenhouse/activity line 19 Spring Beans Problem

    No constructor with 0 arguments defined in class 'com.springsource.greenhouse.activity.badge.JdbcBadgeRepository' integration-activity.xml /greenhouse/src/main/resources/com/springsource/greenhouse/activity line 21 Spring Beans Problem

    No constructor with 0 arguments defined in class 'com.springsource.greenhouse.connect.JdbcServiceProviderFactory' security-oauth-consumer.xml /greenhouse/src/main/webapp/WEB-INF/spring line 7 Spring Beans Problem
    Unexpected exception parsing XML document from file [/Users/joseph/projects/greenhouse/src/main/webapp/WEB-INF/spring/security-oauth-provider.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.security.filterChainProxy' is defined security-oauth-provider.xml /greenhouse/src/main/webapp/WEB-INF/spring Unknown Spring Beans Problem


  22. Hey Shoop,

    I suggest upgrading to the latest version of the SpringSource Tool Suite (STS) (currently version 2.5.1). Greenhouse makes use of some Spring XML schemas that are not in the XML Catalog of previous STS versions, which probably explains those errors. Also, the latest version is intelligent and will actually use the XSD versions in your classpath for validation. This eliminates any issue with your XML catalog being out of sync with what actually is resolved at runtime.

    Best,

    Keith


  23. Hello,

    That looks really interesting! I looked at greenhouse, and there is something I am not sure to understand. I see how greenhouse uses the xxxTemplates to connect to Faceboook, Twitter, etc. In that case, we say that Greenhouse is a OAuth Consumer, right?

    What is not completely clear for me is what happens if I go to the "Develop" menu and register a new app. Is that for the use case where I would create a social app, that would be a OAuth Consumer to Greenhouse (and would therefore be able to access services/information managed by Greenhouse). In other words, do I understand correctly that Greenhouse is a OAuth Service Provider?

    If I understand correctly, then I wonder is there is an example for creating a Consumer to Greenhouse?

    Thanks!


  24. I just realized that there is a Greenhouse Template in the Spring Social Core project, which I guess will answer my question (http://git.springsource.org/spring-social/spring-social/trees/master/spring-social-core/src/main/java/org/springframework/social/greenhouse).


  25. Oliver,

    Yes, Greenhouse is both an OAuth Consumer and an OAuth Provider. There are currently two apps that have been developed against the Greenhouse ServiceProvider API: "Greenhouse for iPhone" and "Greenhouse for Android". And yes, for the latter, which is Java-based, we're able to directly use the GreenhouseTemplate support to invoke the Greenhouse API in a strongly-typed manner. You may also develop your own Greenhouse client apps as well, just like you can develop Twitter and LinkedIn clients, if you so choose–one of the coolest things about OAuth.

    We'll be talking a lot more about this in the upcoming week, and also show how to get both mobile Greenhouse clients running in your on local developer testing environment for exploration and testing.

    Keith


  26. Anybody already tried this with appengine hosted applications?


  27. Hi Keith, here are few things I noticed:
    1. In the greenhouse pom.xml,

    org.springframework.security.oauth
    spring-security-oauth
    1.0.0.BUILD-SNAPSHOT

    needs to be replaced by:

    org.springframework.security.oauth
    spring-security-oauth
    1.0.0.M1

    2. A NumberFormatException is thrown if the system's time zone is XX:30 (Example 3:30 or 4:30).
    3. The Sign in with Facebook and Connect to Facebook buttons that appear in Firefox, do not appear in IE.
    4. The application needs more testing.


  28. Hi John,

    Can you open a JIRA for #2 and #3 at http://jira.springframework.org. It's the best way to track this kind of stuff. Can you also include steps you followed to reproduce #2?

    I assume in #4 you mean "the application needs more automated tests".

    Keith


  29. Hiho

    I like what i am reading here about Spring Social however there are a few things that could be done in the interests of helping ppl get started a little quicker.

    * Dependencies – what are they ? There is no pom or text file.
    * Samples – plz bundle them with SSocial and not inside Greenhouse.
    * OAuth Authentication – as this is a required step at the least include a link that shows how its done.


  30. Hi guys,

    im experimenting on Spring Social and currently has this error below

    WARNING: GET request for "https://graph.facebook.com/me?access_token=XXXXX" resulted in 400 (Bad Request); invoking error handler

    (where XXXXXX above is the App Secret provided by facebook)

    anybody familiar with this error?

    the above error would result in this trace:

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 400 Bad Request
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

    Please help..


  31. Paul: If I understand you correctly, you plugged in the App Secret that Facebook gave (when you registered your application) as the access token. If so, then that's the problem. The API key and app secret are how your application identifies itself to Facebook, but you'll need an access token that identifies the user of your application to Facebook as well. This is typically done in a 3-way dance between the user, your application, and Facebook where the user tells Facebook that it's okay for your app to access their information. In the case of Facebook, this is most easily done using the from Facebook's XFBML tab library. (See the facebookConnect.jsp in the Greenhouse code for an example.)

    Once the user has granted access, the access token is written to a cookie. Spring Social's @FacebookAccessToken annotation can be used in a Spring MVC controller to extract it. (See FacebookConnectController.java in the Greenhouse code for an example.)


  32. tnx cwalls.. its now working!


  33. I dont think this would work on AppEngine.

    Has an ApacheCommons Dependency for HTTP


  34. after a couple of falls, i was able to run a working sample of Spring Social (yehey!)..but its only accessing Facebook (for now)

    here it is:

    http://www.adobocode.com/spring/accessing-facebook-using-spring-social

    hope this helps somebody.


  35. Spring Social and Greenhouse are still very new to me, so I am trying to confirm my understanding. I grabbed the code base for both the Greenhouse server (deployed locally on Tomcat) and for the Greenhouse android client (running in my emulator).

    Firstly, is it correct that in OAuth terms, the android application is an OAuth client and that the greenhouse server is an OAuth service provider for the event management? In other words, that the end-user is interacting with the android app, which forwards him to the greenhouse server app, which asks for an authorization (i.e. the user authorizes the android app to interact with his greenhouse events data)?

    Is my understanding correct?

    One thing, however, is that I did not find any way to manage events (create, delete). Neither from the web portal, nor from the android app. Is there anything I missed?


  36. Olivier: Your description of the relationship between the Android client and the Greenhouse server is correct. The only thing I might say differently is that the client offers very little in the way of event management–that is, it's mostly an event viewer.

    And you are also correct in saying that there's no way to create/delete events. It's a feature that we skipped in the lead-up to SpringOne/2GX and chose instead to just populate the event data ourselves.


  37. Thanks a lot for your feedback Craig. By the way, is this blog the best place to discuss opensocial and greenhouse. I have registered on the greenhouse mailing list, but it looks like there is almost no traffic. What are your thoughts?


  38. I am trying to understand how the framework works, and I came across the EventsController class, in Greenhouse.

    Firstly, I would like to confirm my understanding of the use case / expected behavior. Since Greenhouse demonstrates the behavior of a Service Provider, I guess that as I user, I can create "resources" (such as ratings, comments) around events. This is the information that third-party apps (like the android greenhouse app) would be able to read/write – once authorization has been given by the user.

    Based on that assumption, I believe that the EventsController class is where the security policy would be applied. In other words, when the methods in this class are called, the request has gone through the Spring Security chain – hence we know that the OAuth Consumer C1 is making the call on behalf of User U1. It is up to the EventsController to decide what U1 can see/modify in the Events information (the security policy could state that a user can only see his events, or that a user can see all events – the key point is that it is up to the app to define and apply the access rights model).

    When I look at the method signature, I don't understand the account parameter. I guess that this should represent the greenhouse user, and I imagine that it is probably set somewhere in the Spring Security chain (AccountExposingHandlerInterceptor, which sets a request attribute named 'account'?). It's more a Spring MVC question, but I don't see how the request attribute 'account' would end up in the 'account' method argument – so I am not sure that I got the picture right.

    When I look at the code, I have the feeling that what I get in account is the user identity within the Greenhouse space (the user on behalf of which the call is being made). Is there also a way to retrieve the identity of the OAuth Consumer that makes the call?

    /**
    * Write the list of event favorites to the body of the response.
    */
    @RequestMapping(value="/events/{eventId}/favorites", method=RequestMethod.GET, headers="Accept=application/json")
    public @ResponseBody List favorites(@PathVariable Long eventId, Account account) {
    return eventRepository.findEventFavorites(eventId, account.getId());
    }


  39. Olivier,

    We've recently superceded use of the Greenhouse mailing list for community discussion, in favor of a public forum at http://forum.springsource.org. We look forward to discussion with you there.

    The Account is the user Principal object, yes, and in the case of a client API invocation, models the user associated with the client-provided OAuth access token. If we had the requirement for user-specific permissions, or roles, I would expect those permissions to be accessible from the Account object. I'd like to better undertstand what other OAuth Consumer information you would need to implement your security policy? Sounds like something to discuss on the forum.

    BTW, see AccountExposingHandlerInterceptor and AccountWebArgumentResolver for extensions that enable the Account object to be injected into any @Controller method.

    Hope this helps,

    Keith


  40. Thanks Keith,

    I started a thread on the spring social forum to follow up with the discussion. Actually, what I am looking for is not the ability to assign roles to users, but rather to assign different permission levels to OAuth consumers.

    Typically, when the user is asked whether he authorizes Consumer A to access Provider B, I would like to be able to ask him whether he authorizes read access and/or write access (similarly to Twitter apps for instance). From what I have seen, this could be modeled by extending the AppConnection class. What I am not sure, is how I can best retrieve an AppConnection for a given user in order to enforce the security policy. Should I do a lookup from my service, or rather have the framework inject the AppConnection automatically (i.e. in my controllers, I would not only have an account paramter, but also an appconnection parameter).


  41. I received this error after I clicked on "Sign in with Facebook" button of the "spring-social-quickstart" sample:
    ====================================================
    GRAVE: Servlet.service() for servlet [appServlet] in context with path [/mvc-basic] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: userId cannot be null] with root cause
    java.lang.IllegalArgumentException: userId cannot be null
    at org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository.createConnectionRepository(JdbcUsersConnectionRepository.java:115)
    at org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository.findUserIdWithConnection(JdbcUsersConnectionRepository.java:89)
    at org.springframework.social.connect.web.ProviderSignInController.handleSignIn(ProviderSignInController.java:158)
    at org.springframework.social.connect.web.ProviderSignInController.oauth2Callback(ProviderSignInController.java:152)
    ====================================================

    Please note also that I set it up on the application.properties:
    facebook.clientId= App ID
    facebook.clientSecret= App Secret
    provided by facebook.

    Another strange think I notices with
    Cookie[] cookies = request.getCookies();
    and
    cookie.getName().equals("quickstart_user") which return any time false

    Could you please help me with that?
    Thx a lot.


  42. "mvc-basic" doesn't look like the Spring Social Quickstart app. The spring-social-quickstart project backing the Wiki page is located in the spring-social-samples repository. It should work. I would first get that running, then look at adapting the concepts to your project. Also, I recommend posting the questions you have on our Spring Social forum at http://forum.springsource.org. This blog is not the best place for user support.


  43. google will be part of the project ?

10 trackbacks

Leave a Reply