8

I want to send information from our webapp (using Java and Spring) to the Salesforce REST APIs. I'm looking for an up-to-date example of how to use Spring Security to authenticate with OAuth to the Salesforce APIs. I just don't seem to be able to find many straightforward, standard configurations on the web for this.

I've been Googling for the past two days and the best thing I have found is this:

https://github.com/jesperfj/force-rest-api

I have gotten it up and running and it works with the account I am using. The problem is it's two years old. I'd much rather use something more recent.

What method are people using right now to connect to Salesforce's REST APIs using Java and Spring Security? A very simple example for my very simple self would be greatly appreciated.

Thanks.

  • I think generally we just use OAuth; are you looking for a library recommendation or just OAuth examples? – Mike Chale Oct 23 '13 at 12:37
  • 1
    Libraries would be great but I couldn't even find a recent example of a recent (this year), simple Spring example of connecting to Salesforce using OAuth. If you have such a link that would be a perfect answer to my question. – tikka Oct 23 '13 at 13:01
  • @tikka Take a look at my answer, what doesn't help is the library does not immediately leap out as a Force.com one! But it is! :) – Andrew Fawcett Oct 23 '13 at 23:21
7

The Salesforce Database.com Java SDK is what you need (ignore the fact it has Database.com in the title, it works with regular Force.com orgs as well!).

The SDK is built on existing Force.com APIs. A core service connector class is responsible for managing connections to the API for the application. You configure this connector using a connection URL string which can be provided in property files, system properties, or environment variables. The connector automatically handles session refreshes after expiration and it can use the OAuth module to inject the session ID. The connector uses WSC for the actual protocol implementation.

It also has this to say about the Spring integration...

This plugin enables you to use Spring Security for authentication and authorization in your applications. The Spring Security library uses the API Connector and the OAuth Connector to allow authentication via the Force.com APIs. There is also a custom Spring Security namespace that helps to simplify configuration.

I have been using this library effectively recently and have been quite pleased. My most recent project is the GitHub Salesforce Deploy tool, here you can see this example.

ForceServiceConnector connector = new ForceServiceConnector(ForceServiceConnector.getThreadLocalConnectorConfig());

The ForceServiceConnector allows you to obtain connections to the various Salesforce API's, as well as the Session Id if you need to make REST API calls. This article is also a good read and covers using the REST API's, Integrating Java Spring Apps on Heroku with Force.com REST APIs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.