use of com.sforce.soap.partner.PartnerConnection in project gitblit by gitblit.
the class SalesforceAuthProvider method authenticate.
@Override
public UserModel authenticate(String username, char[] password) {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(new String(password));
try {
PartnerConnection connection = Connector.newConnection(config);
GetUserInfoResult info = connection.getUserInfo();
String org = settings.getString(Keys.realm.salesforce.orgId, "0").trim();
if (!org.equals("0")) {
if (!org.equals(info.getOrganizationId())) {
logger.warn("Access attempted by user of an invalid org: " + info.getUserName() + ", org: " + info.getOrganizationName() + "(" + info.getOrganizationId() + ")");
return null;
}
}
logger.info("Authenticated user " + info.getUserName() + " using org " + info.getOrganizationName() + "(" + info.getOrganizationId() + ")");
String simpleUsername = getSimpleUsername(info);
UserModel user = null;
synchronized (this) {
user = userManager.getUserModel(simpleUsername);
if (user == null) {
user = new UserModel(simpleUsername);
}
setCookie(user);
setUserAttributes(user, info);
updateUser(user);
}
return user;
} catch (ConnectionException e) {
logger.error("Failed to authenticate", e);
}
return null;
}
use of com.sforce.soap.partner.PartnerConnection in project tdi-studio-se by Talend.
the class SforceBasicBulkConnection method renewSession.
@Override
protected void renewSession() throws ConnectionException {
ConnectorConfig partnerConfig = new ConnectorConfig();
partnerConfig.setAuthEndpoint(login_endpoint);
partnerConfig.setUsername(username);
partnerConfig.setPassword(password);
setProxyToConnection(partnerConfig);
// Creating the connection automatically handles login and stores
// the session in partnerConfig
new PartnerConnection(partnerConfig);
// The endpoint for the Bulk API service is the same as for the normal
// SOAP uri until the /Soap/ part. From here it's '/async/versionNumber'
String soapEndpoint = partnerConfig.getServiceEndpoint();
String restEndpoint = soapEndpoint.substring(0, soapEndpoint.indexOf("Soap/")) + "async/" + apiVersion;
// When PartnerConnection is instantiated, a login is implicitly
// executed and, if successful,
// a valid session is stored in the ConnectorConfig instance.
// Use this key to initialize a BulkConnection:
config.setSessionId(partnerConfig.getSessionId());
config.setRestEndpoint(restEndpoint);
}
Aggregations