use of com.sforce.soap.partner.GetUserInfoResult 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;
}
Aggregations