Using Single Sign-On

Single Sign-On (SSO) is a process that allows network users to access all authorized network resources without having to log in to each resource separately. For example, implementing SSO for users within an organization allows each user to authenticate to Salesforce without providing a separate set of Salesforce credentials.

To connect using SSO, you must specify the following connection properties:

  • SessionId
  • Endpoint

You specify the properties in the connection URL. For more information about the syntax of the connection URL, see Building the Connection URL.

Examples

The following is an example connection URL for connecting to Salesforce using SSO:

jdbc:salesforce://localhost;SessionId=00D200000000CHe!ARcAQHssZWpji3UG5UEz6G6XI1pC.llAllcu7wjvvVojrsXpnSFgAjmhDnzQwYwWJAlaOPm8Y_q_7BfRkJ9E76.5oYNVO4DC;Endpoint=https://login.salesf

orce.com/services/Soap/u/48.0

The following code demonstrates how to set connection properties to use SSO authentication with a partner solution:

// The following packages are used in SSO authentication.

import com.sforce.soap.partner.*;

import com.sforce.ws.ConnectionException;

...

// --- DEFINE PROPERTIES FOR THE CONNECTION ---

Properties ConnectionProperties = new Properties();

String SessionID;

String ServiceURL;

try {

// Single Sign-On (SSO) allows a user to sign in once to

// obtain a Session ID. The Session ID is valid until

// the user signs out.

PartnerConnection pConnection = Connector.newConnection("user@demo.com", "salesforce123");

LoginResult lResult = pConnection.login("user@demo.com", "salesforce123");

// The Session ID and Service URL are obtained from an

// existing connection.

SessionID = lResult.getSessionId();

ServiceURL = lResult.getServerUrl();

ConnectionProperties.setProperty("SessionId", SessionID);

ConnectionProperties.setProperty("Endpoint", ServiceURL);

} catch (ConnectionException ce) {

// Handle errors

ce.printStackTrace();

}

// --- END PROPERTIES ---