Search in sources :

Example 1 with ConnectionException

use of com.sforce.ws.ConnectionException 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)

Example 2 with ConnectionException

use of com.sforce.ws.ConnectionException in project tdi-studio-se by Talend.

the class SforceOAuthBulkConnection method renewSession.

@Override
protected void renewSession() throws ConnectionException {
    Token token;
    try {
        token = loginWithOAuth();
    } catch (Exception e) {
        throw new ConnectionException(e.getMessage());
    }
    String session_id = token.getAccess_token();
    String endpoint = OAuthClient.getBulkEndpoint(token, apiVersion);
    config.setSessionId(session_id);
    config.setRestEndpoint(endpoint);
}
Also used : Token(org.talend.salesforce.oauth.Token) ConnectionException(com.sforce.ws.ConnectionException) ConnectionException(com.sforce.ws.ConnectionException)

Aggregations

ConnectionException (com.sforce.ws.ConnectionException)2 UserModel (com.gitblit.models.UserModel)1 GetUserInfoResult (com.sforce.soap.partner.GetUserInfoResult)1 PartnerConnection (com.sforce.soap.partner.PartnerConnection)1 ConnectorConfig (com.sforce.ws.ConnectorConfig)1 Token (org.talend.salesforce.oauth.Token)1