METAMODEL-1140: Allowed SalesforceDataContext without sec. token
authorDavid Krause <david.krause.de@gmail.com>
Sat, 13 May 2017 03:29:28 +0000 (20:29 -0700)
committerKasper Sørensen <i.am.kasper.sorensen@gmail.com>
Sat, 13 May 2017 03:31:06 +0000 (20:31 -0700)
Closes #143

CHANGES.md
salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java

index ebc7e66..0f6c990 100644 (file)
@@ -1,3 +1,5 @@
+ * [METAMODEL-1140] - Allowed SalesforceDataContext without a security token.
+
 ### Apache MetaModel 4.6.0
 
  * [METAMODEL-1136] - New connector for Amazon DynamoDB.
index e1f95aa..3076147 100644 (file)
@@ -77,7 +77,7 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement
         try {
             ConnectorConfig config = new ConnectorConfig();
             config.setUsername(username);
-            config.setPassword(password + securityToken);
+            config.setPassword(securityToken == null ? password : password + securityToken);
             config.setAuthEndpoint(endpoint);
             config.setServiceEndpoint(endpoint);
             _connection = Connector.newConnection(config);
@@ -88,7 +88,15 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement
 
     public SalesforceDataContext(String username, String password, String securityToken) {
         try {
-            _connection = Connector.newConnection(username, password + securityToken);
+            _connection = Connector.newConnection(username, securityToken == null ? password : password + securityToken);
+        } catch (ConnectionException e) {
+            throw SalesforceUtils.wrapException(e, "Failed to log in to Salesforce service");
+        }
+    }
+
+    public SalesforceDataContext(String username, String password) {
+        try {
+            _connection = Connector.newConnection(username, password);
         } catch (ConnectionException e) {
             throw SalesforceUtils.wrapException(e, "Failed to log in to Salesforce service");
         }