Skip to content

Commit 850b681

Browse files
committed
Plugin change to support Salesforce Security Token. PLUGIN-420 JIRA for details
1 parent f5bf1b7 commit 850b681

20 files changed

+92
-21
lines changed

docs/Salesforce-batchsink.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Configuration
1717

1818
**Password:** Salesforce password.
1919

20+
**Security Token:** Salesforce security Token. If the password does not contain the security token the plugin
21+
will append the token before authenticating with salesforce.
22+
2023
**Consumer Key:** Application Consumer Key. This is also known as the OAuth client id.
2124
A Salesforce connected application must be created in order to get a consumer key.
2225

docs/Salesforce-batchsource.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Configuration
1818

1919
**Password:** Salesforce password.
2020

21+
**Security Token:** Salesforce security Token. If the password does not contain the security token the plugin
22+
will append the token before authenticating with salesforce.
23+
2124
**Consumer Key:** Application Consumer Key. This is also known as the OAuth client id.
2225
A Salesforce connected application must be created in order to get a consumer key.
2326

docs/Salesforce-streamingsource.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Configuration
2525

2626
**Password:** Salesforce password.
2727

28+
**Security Token:** Salesforce security Token. If the password does not contain the security token the plugin
29+
will append the token before authenticating with salesforce.
30+
2831
**Consumer Key:** Application Consumer Key. This is also known as the OAuth client id.
2932
A Salesforce connected application must be created in order to get a consumer key.
3033

docs/SalesforceMultiObjects-batchsource.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Configuration
1818

1919
**Password:** Salesforce password.
2020

21+
**Security Token:** Salesforce security Token. If the password does not contain the security token the plugin
22+
will append the token before authenticating with salesforce.
23+
2124
**Consumer Key:** Application Consumer Key. This is also known as the OAuth client id.
2225
A Salesforce connected application must be created in order to get a consumer key.
2326

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
<surefire.redirectTestOutputToFile>true</surefire.redirectTestOutputToFile>
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3232
<!-- version properties -->
33-
<cdap.version>6.2.0-SNAPSHOT</cdap.version>
33+
<cdap.version>6.2.0</cdap.version>
3434
<junit.version>4.12</junit.version>
3535
<commons.io.version>2.6</commons.io.version>
3636
<commons.lang.version>2.6</commons.lang.version>
3737
<hadoop.version>2.3.0</hadoop.version>
3838
<spark2.version>2.1.3</spark2.version>
39-
<hydrator.version>2.4.0-SNAPSHOT</hydrator.version>
39+
<hydrator.version>2.4.0</hydrator.version>
4040
<commons.version>3.8.1</commons.version>
4141
<salesforce.api.version>45.0.0</salesforce.api.version>
4242
<cometd.java.client.version>4.0.0</cometd.java.client.version>

src/main/java/io/cdap/plugin/salesforce/SalesforceConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class SalesforceConstants {
2727
public static final String PROPERTY_CONSUMER_SECRET = "consumerSecret";
2828
public static final String PROPERTY_USERNAME = "username";
2929
public static final String PROPERTY_PASSWORD = "password";
30+
public static final String PROPERTY_SECURITY_TOKEN = "securityToken";
3031
public static final String PROPERTY_LOGIN_URL = "loginUrl";
3132

3233
public static final String CONFIG_CONSUMER_KEY = "mapred.salesforce.consumer.key";

src/main/java/io/cdap/plugin/salesforce/plugin/BaseSalesforceConfig.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import io.cdap.plugin.salesforce.SalesforceConstants;
2626
import io.cdap.plugin.salesforce.authenticator.AuthenticatorCredentials;
2727

28+
import javax.annotation.Nullable;
29+
2830
/**
2931
* Base configuration for Salesforce Streaming and Batch plugins
3032
*/
@@ -50,19 +52,27 @@ public class BaseSalesforceConfig extends ReferencePluginConfig {
5052
@Macro
5153
private String password;
5254

55+
@Name(SalesforceConstants.PROPERTY_SECURITY_TOKEN)
56+
@Description("Salesforce security token")
57+
@Nullable
58+
@Macro
59+
private String securityToken;
60+
5361
@Name(SalesforceConstants.PROPERTY_LOGIN_URL)
5462
@Description("Endpoint to authenticate to")
5563
@Macro
5664
private String loginUrl;
5765

5866
public BaseSalesforceConfig(String referenceName, String consumerKey, String consumerSecret,
59-
String username, String password, String loginUrl) {
67+
String username, String password, String loginUrl,
68+
@Nullable String securityToken) {
6069
super(referenceName);
6170
this.consumerKey = consumerKey;
6271
this.consumerSecret = consumerSecret;
6372
this.username = username;
6473
this.password = password;
6574
this.loginUrl = loginUrl;
75+
this.securityToken = securityToken;
6676
}
6777

6878
public String getConsumerKey() {
@@ -78,7 +88,7 @@ public String getUsername() {
7888
}
7989

8090
public String getPassword() {
81-
return password;
91+
return constructPasswordWithToken(password, securityToken);
8292
}
8393

8494
public String getLoginUrl() {
@@ -96,7 +106,7 @@ public void validate(FailureCollector collector) {
96106
}
97107

98108
public AuthenticatorCredentials getAuthenticatorCredentials() {
99-
return SalesforceConnectionUtil.getAuthenticatorCredentials(username, password,
109+
return SalesforceConnectionUtil.getAuthenticatorCredentials(username, getPassword(),
100110
consumerKey, consumerSecret, loginUrl);
101111
}
102112

@@ -111,7 +121,8 @@ public boolean canAttemptToEstablishConnection() {
111121
|| containsMacro(SalesforceConstants.PROPERTY_CONSUMER_SECRET)
112122
|| containsMacro(SalesforceConstants.PROPERTY_USERNAME)
113123
|| containsMacro(SalesforceConstants.PROPERTY_PASSWORD)
114-
|| containsMacro(SalesforceConstants.PROPERTY_LOGIN_URL));
124+
|| containsMacro(SalesforceConstants.PROPERTY_LOGIN_URL)
125+
|| containsMacro(SalesforceConstants.PROPERTY_SECURITY_TOKEN));
115126
}
116127

117128
private void validateConnection() {
@@ -125,4 +136,12 @@ private void validateConnection() {
125136
throw new RuntimeException("There was issue communicating with Salesforce. " + e.getMessage(), e);
126137
}
127138
}
139+
140+
private String constructPasswordWithToken(String password, @Nullable String securityToken) {
141+
if (securityToken != null && !securityToken.isEmpty() && !password.endsWith(securityToken)) {
142+
return password + securityToken;
143+
} else {
144+
return password;
145+
}
146+
}
128147
}

src/main/java/io/cdap/plugin/salesforce/plugin/sink/batch/SalesforceSinkConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public SalesforceSinkConfig(String referenceName, String clientId,
107107
String password, String loginUrl, String sObject,
108108
String operation, String externalIdField,
109109
String maxBytesPerBatch, String maxRecordsPerBatch,
110-
String errorHandling) {
111-
super(referenceName, clientId, clientSecret, username, password, loginUrl);
110+
String errorHandling, @Nullable String securityToken) {
111+
super(referenceName, clientId, clientSecret, username, password, loginUrl, securityToken);
112112
this.sObject = sObject;
113113
this.operation = operation;
114114
this.externalIdField = externalIdField;

src/main/java/io/cdap/plugin/salesforce/plugin/source/batch/SalesforceBaseSourceConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ protected SalesforceBaseSourceConfig(String referenceName,
8484
@Nullable String datetimeAfter,
8585
@Nullable String datetimeBefore,
8686
@Nullable String duration,
87-
@Nullable String offset) {
88-
super(referenceName, consumerKey, consumerSecret, username, password, loginUrl);
87+
@Nullable String offset,
88+
@Nullable String securityToken) {
89+
super(referenceName, consumerKey, consumerSecret, username, password, loginUrl, securityToken);
8990
this.datetimeAfter = datetimeAfter;
9091
this.datetimeBefore = datetimeBefore;
9192
this.duration = duration;

src/main/java/io/cdap/plugin/salesforce/plugin/source/batch/SalesforceBatchMultiSource.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ public void prepareRun(BatchSourceContext context) throws ConnectionException {
8383
String sObjectNameField = config.getSObjectNameField();
8484
context.setInput(Input.of(config.referenceName, new SalesforceInputFormatProvider(
8585
config, queries, getSchemaWithNameField(sObjectNameField, schemas), sObjectNameField)));
86-
86+
/* TODO PLUGIN-510
87+
* As part of [CDAP-16290], recordLineage function was introduced with out implementation.
88+
* To avoid compilation errors the code block is commented for future fix.
8789
Schema schema = context.getInputSchema();
8890
if (schema != null && schema.getFields() != null) {
8991
recordLineage(context, config.referenceName, schema,
9092
"Read", "Read from Salesforce MultiObjects.");
9193
}
94+
*/
9295
}
9396

9497
@Override

0 commit comments

Comments
 (0)