Search in sources :

Example 1 with GetUserInfoResult

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;
}
Also used : UserModel(com.gitblit.models.UserModel) ConnectorConfig(com.sforce.ws.ConnectorConfig) PartnerConnection(com.sforce.soap.partner.PartnerConnection) GetUserInfoResult(com.sforce.soap.partner.GetUserInfoResult) ConnectionException(com.sforce.ws.ConnectionException)

Aggregations

UserModel (com.gitblit.models.UserModel)1 GetUserInfoResult (com.sforce.soap.partner.GetUserInfoResult)1 PartnerConnection (com.sforce.soap.partner.PartnerConnection)1 ConnectionException (com.sforce.ws.ConnectionException)1 ConnectorConfig (com.sforce.ws.ConnectorConfig)1