Search in sources :

Example 1 with FormContentProvider

use of org.eclipse.jetty.client.util.FormContentProvider in project camel by apache.

the class SalesforceSession method getLoginRequest.

/**
     * Creates login request, allows SalesforceSecurityHandler to create a login request for a failed authentication
     * conversation
     * 
     * @return login POST request.
     */
public Request getLoginRequest(HttpConversation conversation) {
    final String loginUrl = (instanceUrl == null ? config.getLoginUrl() : instanceUrl) + OAUTH2_TOKEN_PATH;
    LOG.info("Login at Salesforce loginUrl: {}", loginUrl);
    final Fields fields = new Fields(true);
    fields.put("client_id", config.getClientId());
    fields.put("format", "json");
    final Type type = config.getType();
    switch(type) {
        case USERNAME_PASSWORD:
            fields.put("client_secret", config.getClientSecret());
            fields.put("grant_type", "password");
            fields.put("username", config.getUserName());
            fields.put("password", config.getPassword());
            break;
        case REFRESH_TOKEN:
            fields.put("client_secret", config.getClientSecret());
            fields.put("grant_type", "refresh_token");
            fields.put("refresh_token", config.getRefreshToken());
            break;
        case JWT:
            fields.put("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer");
            fields.put("assertion", generateJwtAssertion());
            break;
        default:
            throw new IllegalArgumentException("Unsupported login configuration type: " + type);
    }
    final Request post;
    if (conversation == null) {
        post = httpClient.POST(loginUrl);
    } else {
        post = httpClient.newHttpRequest(conversation, URI.create(loginUrl)).method(HttpMethod.POST);
    }
    return post.content(new FormContentProvider(fields)).timeout(timeout, TimeUnit.MILLISECONDS);
}
Also used : Type(org.apache.camel.component.salesforce.SalesforceLoginConfig.Type) FormContentProvider(org.eclipse.jetty.client.util.FormContentProvider) Fields(org.eclipse.jetty.util.Fields) Request(org.eclipse.jetty.client.api.Request)

Aggregations

Type (org.apache.camel.component.salesforce.SalesforceLoginConfig.Type)1 Request (org.eclipse.jetty.client.api.Request)1 FormContentProvider (org.eclipse.jetty.client.util.FormContentProvider)1 Fields (org.eclipse.jetty.util.Fields)1