This is an automated email from the ASF dual-hosted git repository.

jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new af79dc54e50d CAMEL-27891: camel-salesforce: fix the integration test 
setup script (#31163)
af79dc54e50d is described below

commit af79dc54e50deae530a159ef78c6c5b1911d40da
Author: James Netherton <[email protected]>
AuthorDate: Tue Dec 1 10:21:21 2026 +0000

    CAMEL-27891: camel-salesforce: fix the integration test setup script 
(#31163)
    
    The SF CLI based setup no longer worked against current orgs and SF CLI
    versions:
    
    - Stop generating and deploying the CamelSalesforceIntegrationTests 
connected
      app, which Salesforce rejects and the tests do not use. Delete the copy
      generated by earlier versions, which holds a secret
    - Read the client id, client secret and refresh token with
      sf org auth show-sfdx-auth-url, as sf org display now redacts the auth 
URL,
      and store the username, which the approval and composite batch tests need
    - Remove the username/password mode; use an existing org by logging in with
      sf org login web and setting it as the local target-org
    - Fail early when there is no refresh token and nothing else provides
      credentials, or when a password is set as well without an auth type, 
before
      creating a scratch org
    - Make the stored credentials readable by the user only, and delete the
      connected app credentials stored by earlier versions
    - Skip SalesforceClientCredentialsFlowManualIT unless the user sets a client
      secret, as the setup no longer provides an app for that flow
    - Update the READMEs and the sample login properties
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../camel-salesforce-component/README.md           |  23 +--
 .../camel-salesforce-component/pom.xml             |  14 +-
 .../component/salesforce/LoginConfigHelper.java    |  27 ++-
 .../SalesforceClientCredentialsFlowManualIT.java   |   7 +
 .../camel-salesforce/it/resources/.gitignore       |   2 +-
 .../CamelSalesforceIntegrationTests.connectedApp   |  29 ----
 components/camel-salesforce/it/resources/README.md |  69 ++++----
 .../it/resources/setup-salesforce.sh               | 188 ++++++++-------------
 ...forceIntegrationTests.connectedApp-template.xml |  30 ----
 .../test-salesforce-login.sample.properties        |  18 +-
 10 files changed, 144 insertions(+), 263 deletions(-)

diff --git a/components/camel-salesforce/camel-salesforce-component/README.md 
b/components/camel-salesforce/camel-salesforce-component/README.md
index 51279b72e34c..6a365f41b192 100644
--- a/components/camel-salesforce/camel-salesforce-component/README.md
+++ b/components/camel-salesforce/camel-salesforce-component/README.md
@@ -17,28 +17,9 @@ There is a companion maven plugin 
[camel-salesforce-plugin](https://github.com/a
 
 In order to run the integration tests you need a Salesforce Developer account. 
You can get a Salesforce Developer account by visiting 
[developer.salesforce.com](https://developer.salesforce.com/) and sign up for 
one.
 
-As of 2.19 we maintain any Salesforce setup needed to run the integration 
tests in the `it/resources/salesforce` directory, the files there are generated 
by the _Salesforce Migration Tool_ that you can freely download from [Force.com 
Migration 
Tool](https://developer.salesforce.com/page/Force.com_Migration_Tool). This is 
an Apache Ant extension, by which you get additional Ant tasks to retrieve and 
to upload configuration, classes, schema changes and such. Download it and 
place the `ant- [...]
-
-We have integrated _Salesforce Migration Tool_ into the Maven 
_integration-test_ lifecycle phase and it should run and update your Salesforce 
instance to a state capable of running integration tests. Start by creating 
`test-salesforce-login.properties` in the parent Maven module 
(`camel-salesforce`), you can use `test-salesforce-login.sample.properties` as 
reference.
-
-**Note:** Remember that if you do not relax IP restrictions, by default you'll 
need to append the security token on the password you place in the 
`test-salesforce-login.properties` file.
-
-Before running the tests for the first time run the migration by invoking 
Maven from the `camel-salesforce-component` Maven module directory:
-
-    $ mvn -Pintegration 
resources:copy-resources@copy-test-salesforce-login-properties \
-      resources:copy-resources@set-connected-app-client-id 
antrun:run@setup-salesforce-instance
-
-This will create a _Connected App_ with predefined Consumer Key (the one 
mentioned in the comment one in `test-salesforce-login.sample.properties`) and 
_Consumer Secret_ (`clientSecret`) with the name of 
`CamelSalesforceIntegrationTests`.
-
-Note that this deployment is run every time you run the integration tests by 
issuing from the `camel-salesforce-component` Maven module directory:
+The setup is described in 
[`it/resources/README.md`](../it/resources/README.md). The metadata the tests 
need is in `it/resources/sfdx-project/salesforce-source`, and running the tests 
from this directory deploys it:
 
     $ mvn -Pintegration verify
-                                                     
-However, once the deployment is successful, subsequent deployments are 
redundant, but harmless as it is an idempotent operation.
-
-If you need any custom fields, Apex classes or other configuration changes 
done, make sure to download them using the _Salesforce Migration Tool_ and 
include them in `it/resources/salesforce` directory.
-
-After the initial successful deployment, in salesforce go to Setup > App 
Manager, find the CamelSalesforceIntegrationTests app and click View. Copy the 
Consumer Key and Consumer Secret values into salesforce.client.id and 
salesforce.client.secret respectively.
 
 The deployment includes a permission set called `Hard Delete Permission Set` 
which contains the Hard Delete
 permission as well as field-level permissions needed to run the integration 
tests. You can assign this 
@@ -66,7 +47,7 @@ Install the Warehouse package, tested with _Spring 2013_ 
(version 1.2) that can
  - create new ApexClass named `MerchandiseRestResource` with the content of 
`MerchandiseRestResource.apxc`
  - deactivate the `Contact Duplicate Rule` in salesforce configuration
  - add `Account` to selected entities for change data capture in the 
_Integrations/Change Data Capture_ menu
- - add the `Hard Delete Permission Set` to the CamelSalesforceIntegrationTests 
Connected App (e.g. Setup/ConnectedApp/ManagePermissionSets)
+ - add the `Hard Delete Permission Set` to the connected application the tests 
log in with (e.g. Setup/ConnectedApp/ManagePermissionSets)
 
 You'll need to access a Merchandise record and run a `Test Report` in order 
for them to appear in _Recent Items_ and _Recent Reports_. Do this by accessing 
_Warehouse_ application from the menu in the top right, and selecting 
_Merchandise_ click _Go!_ (preselected is View: _All_) and click on the single 
Merchandise item available. Next go to Reports and select and run _Test Report_ 
from _Test Reports_. This is needed by the integration tests as they access 
recent items and recently run reports.
 
diff --git a/components/camel-salesforce/camel-salesforce-component/pom.xml 
b/components/camel-salesforce/camel-salesforce-component/pom.xml
index bc037db6bc5c..d25bc881337b 100644
--- a/components/camel-salesforce/camel-salesforce-component/pom.xml
+++ b/components/camel-salesforce/camel-salesforce-component/pom.xml
@@ -348,12 +348,12 @@ EASIEST OPTION - Auto Scratch Org:
 2. Run tests (scratch org auto-created):
    mvn clean verify -Pintegration
 
-ALTERNATIVE - Traditional Org:
-   - Set SALESFORCE_USERNAME, SALESFORCE_PASSWORD, and SALESFORCE_LOGIN_URL
-   - Or configure in test-salesforce-login.properties
+ALTERNATIVE - An org you have logged in to:
+   Run this in it/resources/sfdx-project:
+   sf config set target-org=<username or alias>
 
 Source metadata location:
-${salesforce.component.root}/it/resources/salesforce-source]]></message>
+${salesforce.component.root}/it/resources/sfdx-project/salesforce-source]]></message>
                                         </requireFilesExist>
                                     </rules>
                                     <fail>true</fail>
@@ -401,12 +401,12 @@ 
${salesforce.component.root}/it/resources/salesforce-source]]></message>
                                         
<argument>setup-salesforce.sh</argument>
                                     </arguments>
                                     <environmentVariables>
-                                        
<SALESFORCE_USERNAME>${env.SALESFORCE_USERNAME}</SALESFORCE_USERNAME>
-                                        
<SALESFORCE_PASSWORD>${env.SALESFORCE_PASSWORD}</SALESFORCE_PASSWORD>
-                                        
<SALESFORCE_LOGIN_URL>${env.SALESFORCE_LOGIN_URL}</SALESFORCE_LOGIN_URL>
                                         
<SALESFORCE_DEV_HUB>${env.SALESFORCE_DEV_HUB}</SALESFORCE_DEV_HUB>
                                         
<SALESFORCE_DEPLOY_SOURCE>${env.SALESFORCE_DEPLOY_SOURCE}</SALESFORCE_DEPLOY_SOURCE>
                                         
<SALESFORCE_SCRATCH_ORG_DURATION>${env.SALESFORCE_SCRATCH_ORG_DURATION}</SALESFORCE_SCRATCH_ORG_DURATION>
+                                        <!-- -D options reach the tests as 
system properties, the script checks them -->
+                                        
<MAVEN_SALESFORCE_PASSWORD>${salesforce.password}</MAVEN_SALESFORCE_PASSWORD>
+                                        
<MAVEN_SALESFORCE_AUTH_TYPE>${salesforce.auth.type}</MAVEN_SALESFORCE_AUTH_TYPE>
                                     </environmentVariables>
                                 </configuration>
                             </execution>
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/LoginConfigHelper.java
 
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/LoginConfigHelper.java
index 6ef9f492b84c..49b32747357a 100644
--- 
a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/LoginConfigHelper.java
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/LoginConfigHelper.java
@@ -20,9 +20,11 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.util.Set;
 
 import org.apache.camel.support.jsse.KeyStoreParameters;
 import org.apache.camel.util.ObjectHelper;
@@ -44,13 +46,18 @@ public final class LoginConfigHelper {
 
     private final Map<String, String> configuration;
 
+    // Keys set by the properties file, environment variables or system 
properties, not by the setup script
+    private final Set<String> userConfiguredKeys;
+
     private LoginConfigHelper() {
         configuration = new HashMap<>();
+        userConfiguredKeys = new HashSet<>();
         loadConfiguration();
     }
 
     public static void reloadCredentials() {
         INSTANCE.configuration.clear();
+        INSTANCE.userConfiguredKeys.clear();
         INSTANCE.loadConfiguration();
     }
 
@@ -61,7 +68,7 @@ public final class LoginConfigHelper {
         // 2. Load from properties file (overrides SF CLI)
         try {
             final ResourceBundle properties = 
ResourceBundle.getBundle("test-salesforce-login");
-            properties.keySet().forEach(k -> configuration.put(k, 
properties.getString(k)));
+            properties.keySet().forEach(k -> putUserConfigured(k, 
properties.getString(k)));
         } catch (final MissingResourceException ignored) {
             // ignoring if missing
         }
@@ -69,12 +76,19 @@ public final class LoginConfigHelper {
         // 3. Environment variables (overrides properties file)
         System.getenv().keySet().stream()//
                 .filter(k -> k.startsWith("SALESFORCE_") && 
isNotEmpty(System.getenv(k)))
-                .forEach(k -> configuration.put(fromEnvName(k), 
System.getenv(k)));
+                .forEach(k -> putUserConfigured(fromEnvName(k), 
System.getenv(k)));
 
         // 4. System properties (highest priority)
         System.getProperties().keySet().stream().map(String.class::cast)
                 .filter(k -> k.startsWith("salesforce.") && 
isNotEmpty(System.getProperty(k)))
-                .forEach(k -> configuration.put(k, System.getProperty(k)));
+                .forEach(k -> putUserConfigured(k, System.getProperty(k)));
+    }
+
+    private void putUserConfigured(String key, String value) {
+        configuration.put(key, value);
+        if (isNotEmpty(value)) {
+            userConfiguredKeys.add(key);
+        }
     }
 
     private void loadFromSfCliCredentials() {
@@ -221,6 +235,13 @@ public final class LoginConfigHelper {
         }
     }
 
+    /**
+     * Whether the user configured the given key, rather than the setup script 
storing it.
+     */
+    public static boolean isUserConfigured(String key) {
+        return INSTANCE.userConfiguredKeys.contains(key);
+    }
+
     public static SalesforceLoginConfig getLoginConfig() {
         return INSTANCE.createLoginConfig();
     }
diff --git 
a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceClientCredentialsFlowManualIT.java
 
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceClientCredentialsFlowManualIT.java
index f96bf398e4b6..50d20e54c20d 100644
--- 
a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceClientCredentialsFlowManualIT.java
+++ 
b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceClientCredentialsFlowManualIT.java
@@ -20,11 +20,18 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.component.salesforce.api.dto.Limits;
 import org.apache.camel.test.junit6.CamelTestSupport;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
+@EnabledIf("hasClientSecret")
 public class SalesforceClientCredentialsFlowManualIT extends CamelTestSupport {
 
+    // The setup script stores the secret of the app the org was logged in 
with, which may not allow this flow
+    static boolean hasClientSecret() {
+        return LoginConfigHelper.isUserConfigured("salesforce.client.secret");
+    }
+
     @Test
     public void shouldLoginUsingJwtBearerToken() {
         final Limits limits = template.requestBody("salesforce:limits", null, 
Limits.class);
diff --git a/components/camel-salesforce/it/resources/.gitignore 
b/components/camel-salesforce/it/resources/.gitignore
index 5d15c101666e..c14831d9a600 100644
--- a/components/camel-salesforce/it/resources/.gitignore
+++ b/components/camel-salesforce/it/resources/.gitignore
@@ -6,7 +6,7 @@ sfdx-project/.sf/
 *.json.bak
 .sfdx-url
 
-# Generated connected app (created from .template file by setup script)
+# Connected app generated by earlier versions of the setup script, holds a 
secret
 
sfdx-project/salesforce-source/main/default/connectedApps/CamelSalesforceIntegrationTests.connectedApp-meta.xml
 
 # User-specific local files (created by setup script)
diff --git 
a/components/camel-salesforce/it/resources/CamelSalesforceIntegrationTests.connectedApp
 
b/components/camel-salesforce/it/resources/CamelSalesforceIntegrationTests.connectedApp
deleted file mode 100644
index 0dbb442a6a6c..000000000000
--- 
a/components/camel-salesforce/it/resources/CamelSalesforceIntegrationTests.connectedApp
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  See the NOTICE file distributed with
-  this work for additional information regarding copyright ownership.
-  The ASF licenses this file to You under the Apache License, Version 2.0
-  (the "License"); you may not use this file except in compliance with
-  the License.  You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
-<ConnectedApp xmlns="http://soap.sforce.com/2006/04/metadata";>
-    <contactEmail>[email protected]</contactEmail>
-    <label>CamelSalesforceIntegrationTests</label>
-    <oauthConfig>
-        
<callbackUrl>https://login.salesforce.com/services/oauth2/success</callbackUrl>
-        
<certificate>MIIC1TCCAb2gAwIBAgIEM3ZMGjANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDEw9TYWxlc2ZvcmNlIHRlc3QwIBcNMTcwMzE0MjIxMjU0WhgPMjExNzAyMTgyMjEyNTRaMBoxGDAWBgNVBAMTD1NhbGVzZm9yY2UgdGVzdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbZinVCZerzZvyyQlfE6nMpEQRfVsjpcfT01UTG/bwzWorP7YRpGkDW7Q4eu6IPrHtohkhM3JtsSVka5jfS1iEguMXLdNkEyMjMiBrWJeyGfcISF1yazgqLxxwcwGjMn3C9xV5tBxiRSqtMrV1iRx3fxmLue1UnZjSyUaG+Vi+FcKxqre5ixApeDCZHLONxBy3mjWK4GIeBBbUqQqy3LNrT6B34WdNX8vTslpTKOlmLyycEI/Rx+A4lNaultrJHdnRhGBr
 [...]
-        <!--consumerKey>${salesforce.client.id}</consumerKey>
-        <consumerSecret>${salesforce.client.secret}</consumerSecret-->
-        <scopes>Api</scopes>
-        <scopes>RefreshToken</scopes>
-    </oauthConfig>
-</ConnectedApp>
diff --git a/components/camel-salesforce/it/resources/README.md 
b/components/camel-salesforce/it/resources/README.md
index ccd8c39ad9a9..578f9c802b6f 100644
--- a/components/camel-salesforce/it/resources/README.md
+++ b/components/camel-salesforce/it/resources/README.md
@@ -47,8 +47,7 @@ When integration tests are run via maven, 
`setup-salesforce.sh` is executed and
    ```bash
    sf config get target-org --verbose
    ```
-2. **Auto-Create Scratch Org**: If no credentials provided and no local org 
exists, a new scratch org is created
-3. **Traditional Org**: If username/password credentials are provided, 
authenticate with those
+2. **Auto-Create Scratch Org**: If no local org exists, a new scratch org is 
created
 
 All operations use the **Salesforce CLI's local default org** mechanism, 
scoped to the project directory.
 
@@ -59,10 +58,10 @@ sf config unset target-org
 
 ### Option A: Scratch Orgs
 
-If you have a Dev Hub authenticated and don't provide any credentials, a 
scratch org is automatically created on the first run and reused on subsequent 
runs:
+If you have a Dev Hub authenticated, a scratch org is automatically created on 
the first run and reused on subsequent runs:
 
 ```bash
-# One-time setup: Authenticate to Dev Hub
+# One-time setup: enable Dev Hub in the org (Setup > Dev Hub; this cannot be 
undone), then authenticate to it
 sf org login web --set-default-dev-hub
 
 # First run - scratch org is automatically created and set as local default
@@ -76,7 +75,7 @@ mvn clean verify -Pintegration
 - **First run**: Creates a new scratch org with a unique name (e.g., 
`camel-sf-test-1733123456`)
 - Sets it as the **local default org** (stored in 
`sfdx-project/.sf/config.json`)
 - Deploys the source metadata to the org
-- Extracts the **refresh token** from SF CLI and stores it for test 
authentication
+- Extracts the **refresh token** and username from SF CLI and stores them for 
test authentication
 - Runs the integration tests
 - **Subsequent runs**: Detects existing local target-org and reuses it (skips 
org creation)
 - The scratch org remains available for 7 days by default
@@ -96,34 +95,21 @@ The scratch org is configured as the local default. You can:
 - Delete when done: `sf org delete scratch --target-org <alias> --no-prompt`
 - Reset to create a new org: `sf config unset target-org`
 
-### Option B: Traditional Salesforce Orgs
+### Option B: An Org You Have Logged In To
 
-**Important:** Before using username-password authentication, you must enable 
this OAuth flow in your Salesforce org:
-
-1. Go to **Setup** → **OAuth and OIDC Settings**
-   - Direct URL: `/lightning/setup/OauthOidcSettings/home`
-2. Enable **"Allow OAuth Username-Password Flows"**
-3. Save your changes
-
-This setting is disabled by default in newer Salesforce orgs for security 
reasons. Scratch orgs created by the setup script have this setting enabled 
automatically via the scratch org definition.
-
-Set the following environment variables:
+Log in with the web flow and set the org as the local target-org. The script 
deploys the metadata to it, which stays in
+the org, and the tests can use up its daily API allowance.
 
 ```bash
-export SALESFORCE_USERNAME="[email protected]"
-export SALESFORCE_PASSWORD="your-password-and-security-token"
-export SALESFORCE_LOGIN_URL="https://login.salesforce.com";  # or 
https://test.salesforce.com for sandbox
+sf org login web --alias my-test-org
+
+cd it/resources/sfdx-project
+sf config set target-org=my-test-org
+cd -
 
 mvn clean verify -Pintegration
 ```
 
-**How it works:**
-- **First run**: Authenticates to your org with username/password
-- Sets it as the **local default org** (alias: `camel-sf-integration`)
-- Deploys the source metadata
-- Runs the integration tests
-- **Subsequent runs**: Detects existing local target-org and reuses it (skips 
authentication)
-
 ### Additional Configuration Options
 
 #### Custom Scratch Org Duration             
@@ -146,32 +132,39 @@ export SALESFORCE_DEV_HUB="[email protected]"
 mvn clean verify -Pintegration
 ```
 
-#### Use a Specific Existing Org
-Set any org as the default before running tests:
-```bash
-# Login to a new org and set as default
-sf org login web --alias my-test-org --set-default
+## Client credentials test
 
-# Or set an already-authenticated org as default
-sf config set target-org my-existing-org
+`SalesforceClientCredentialsFlowManualIT` needs a client secret, which the 
setup does not provide because
+Salesforce restricts creating connected apps. It is skipped unless you set the 
secret of an app of your own that allows
+the client credentials flow, in a `SALESFORCE_*` variable, 
`test-salesforce-login.properties` or a `-D` option. Run it on its own, because 
these variables apply to every test in the run, and the other tests need
+the app the org was logged in with:
 
-mvn clean verify -Pintegration
+```bash
+export SALESFORCE_CLIENT_ID=<consumer key>
+export SALESFORCE_CLIENT_SECRET=<consumer secret>
+mvn verify -Pintegration -Dit.test=SalesforceClientCredentialsFlowManualIT
 ```
 
+## Other Credentials
+
+The script stores a refresh token, and `SALESFORCE_*` variables, 
`test-salesforce-login.properties` and `-D` options
+override what it stores. If a password is set in any of them as well, the 
tests cannot choose how to log in, so the
+script stops. Unset `SALESFORCE_PASSWORD` and `salesforce.password`, or set 
`SALESFORCE_AUTH_TYPE=REFRESH_TOKEN`.
+
+If an org has no refresh token to store, for example after a JWT login, the 
script only continues when one of these
+provides the credentials for the tests.
+
 ## Environment Variables
 
 | Variable | Description | Default | Required |
 |----------|-------------|---------|----------|
-| `SALESFORCE_USERNAME` | Username for traditional org | - | No* |
-| `SALESFORCE_PASSWORD` | Password + security token for traditional org | - | 
No* |
-| `SALESFORCE_LOGIN_URL` | Login URL for traditional org | 
`https://login.salesforce.com` | No |
 | `SALESFORCE_DEV_HUB` | Dev Hub username (skips auto-detection) | 
Auto-detected | No |
 | `SALESFORCE_DEPLOY_SOURCE` | Deploy source to org | `true` | No |
 | `SALESFORCE_SCRATCH_ORG_DURATION` | Scratch org lifetime in days (1-30) | 
`7` | No |
 
 **How SF CLI Tracks Orgs:**
 - All org authentication is stored **locally** in `sfdx-project/.sf/` 
directory (git-ignored)
-- The script sets the authenticated/created org as the **local default** (not 
global)
+- The script sets the created org as the **local default** (not global)
 - Subsequent runs automatically detect and reuse the local target-org
 - This keeps the project isolated from other SF CLI usage on your machine
 - Use `sf org display` to see which org is currently the local default
diff --git a/components/camel-salesforce/it/resources/setup-salesforce.sh 
b/components/camel-salesforce/it/resources/setup-salesforce.sh
index b8607178dcac..d093f6c6cd7b 100755
--- a/components/camel-salesforce/it/resources/setup-salesforce.sh
+++ b/components/camel-salesforce/it/resources/setup-salesforce.sh
@@ -20,9 +20,7 @@
 set -e
 
 # Script to setup Salesforce environment for Camel Salesforce component 
integration tests
-# This script supports two modes:
-# 1. Scratch org creation and deployment
-# 2. Traditional org with username/password authentication
+# It uses the local target-org of sfdx-project if there is one, and otherwise 
creates a scratch org
 
 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 PROJECT_DIR="$SCRIPT_DIR/sfdx-project"
@@ -56,10 +54,32 @@ fi
 echo "✓ jq found: $(jq --version)"
 echo ""
 
-# Determine mode of operation based on provided credentials
 DEPLOY_SOURCE="${SALESFORCE_DEPLOY_SOURCE:-true}"
-USERNAME="${SALESFORCE_USERNAME}"
-PASSWORD="${SALESFORCE_PASSWORD}"
+
+# The tests read these as well, and they take priority over the credentials 
stored below
+LOGIN_PROPERTIES="$SCRIPT_DIR/../../test-salesforce-login.properties"
+
+# Whether a login setting is set in the environment, as a Maven property 
(passed by the pom) or in the properties file
+has_login_setting() {
+    local env_value="$1" maven_value="$2" key="$3"
+    [ -n "$env_value" ] || [ -n "$maven_value" ] \
+        || grep -qE 
"^[[:space:]]*${key//./\\.}[[:space:]]*=[[:space:]]*[^[:space:]]" 
"$LOGIN_PROPERTIES" 2>/dev/null
+}
+
+if has_login_setting "$SALESFORCE_PASSWORD" "$MAVEN_SALESFORCE_PASSWORD" 
salesforce.password; then
+    HAS_PASSWORD=true
+fi
+if has_login_setting "$SALESFORCE_AUTH_TYPE" "$MAVEN_SALESFORCE_AUTH_TYPE" 
salesforce.auth.type; then
+    HAS_AUTH_TYPE=true
+fi
+
+fail_on_password_with_refresh_token() {
+    if [ -n "$HAS_PASSWORD" ] && [ -z "$HAS_AUTH_TYPE" ]; then
+        echo "ERROR: A Salesforce password is set as well as the refresh 
token, so the tests cannot choose how to log in."
+        echo "Unset SALESFORCE_PASSWORD and salesforce.password, or set 
SALESFORCE_AUTH_TYPE=REFRESH_TOKEN."
+        exit 1
+    fi
+}
 
 # Change to project directory to check for local target-org
 cd "$PROJECT_DIR"
@@ -74,10 +94,12 @@ if [ -n "$EXISTING_TARGET_ORG" ]; then
     echo ""
     # Skip org creation, proceed to deployment
 
-# Auto-detect mode: if no username/password, try creating a scratch org
-elif [ -z "$USERNAME" ] && [ -z "$PASSWORD" ]; then
-    echo "Mode: Auto-Create Scratch Org (no credentials provided)"
-    echo "------------------------------------------------"
+else
+    echo "Mode: Auto-Create Scratch Org"
+    echo "-----------------------------"
+
+    # A scratch org always has a refresh token, so check before creating one
+    fail_on_password_with_refresh_token
 
     # Get Dev Hub username - check if explicitly provided first
     DEV_HUB="${SALESFORCE_DEV_HUB}"
@@ -88,16 +110,15 @@ elif [ -z "$USERNAME" ] && [ -z "$PASSWORD" ]; then
     fi
 
     if [ -z "$DEV_HUB" ]; then
-        echo "ERROR: No credentials or scratch org alias provided, and no 
default Dev Hub set"
+        echo "ERROR: No local target-org and no default Dev Hub set"
         echo ""
         echo "To run integration tests, you must either:"
         echo ""
-        echo "1. Provide traditional org credentials:"
-        echo "   export SALESFORCE_USERNAME=\"[email protected]\""
-        echo "   export SALESFORCE_PASSWORD=\"your-password-and-token\""
-        echo ""
-        echo "2. Authenticate to a Dev Hub and set it as default (for 
automatic scratch org creation):"
+        echo "1. Authenticate to a Dev Hub and set it as default (for 
automatic scratch org creation):"
         echo "   sf org login web --set-default-dev-hub"
+        echo ""
+        echo "2. Use an org you have logged in to, by running this in 
$PROJECT_DIR:"
+        echo "   sf config set target-org=<username or alias>"
         exit 1
     fi
     echo "✓ Using Dev Hub: $DEV_HUB"
@@ -120,99 +141,17 @@ elif [ -z "$USERNAME" ] && [ -z "$PASSWORD" ]; then
 
     # SF CLI automatically sets the created scratch org as default, no need to 
specify TARGET_ORG
 
-else
-    echo "Mode: Traditional Org"
-    echo "--------------------"
-
-    LOGIN_URL="${SALESFORCE_LOGIN_URL:-https://login.salesforce.com}";
-
-    if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
-        echo "ERROR: SALESFORCE_USERNAME and SALESFORCE_PASSWORD environment 
variables must be set"
-        echo ""
-        echo "Set environment variables:"
-        echo "  export SALESFORCE_USERNAME=\"[email protected]\""
-        echo "  export SALESFORCE_PASSWORD=\"your-password-and-token\""
-        exit 1
-    fi
-
-    echo "Authenticating to: $LOGIN_URL"
-    echo "Username: $USERNAME"
-
-    # Authenticate using username/password
-    ORG_ALIAS="camel-sf-integration"
-
-    # Use sfdx auth command for username/password flow
-    sf org login sfdx-url \
-        --sfdx-url-stdin \
-        --alias "$ORG_ALIAS" \
-        --set-default <<< "force://$USERNAME:$PASSWORD@$(echo $LOGIN_URL | sed 
's|https://||')"
-
-    echo "✓ Authenticated successfully"
-    echo ""
 fi
 
+# Earlier versions of this script generated a connected app, which Salesforce 
rejects, and stored its secret
+rm -f 
salesforce-source/main/default/connectedApps/CamelSalesforceIntegrationTests.connectedApp-meta.xml
 \
+    .local/connected-app-credentials.json
+
 # Deploy source if requested
 if [ "$DEPLOY_SOURCE" = "true" ]; then
     echo "Deploying source to org..."
     echo "-------------------------"
 
-    # Generate OAuth credentials for the connected app from template
-    
CONNECTED_APP_TEMPLATE="config/CamelSalesforceIntegrationTests.connectedApp-template.xml"
-    
CONNECTED_APP_FILE="salesforce-source/main/default/connectedApps/CamelSalesforceIntegrationTests.connectedApp-meta.xml"
-    CONNECTED_APP_CREDENTIALS=".local/connected-app-credentials.json"
-
-    # Ensure .local directory exists
-    mkdir -p .local
-
-    # Check if we have existing valid connected app credentials (separate from 
auth credentials)
-    EXISTING_CLIENT_ID=""
-    EXISTING_CLIENT_SECRET=""
-    if [ -f "$CONNECTED_APP_CREDENTIALS" ]; then
-        EXISTING_CLIENT_ID=$(jq -r '.clientId // empty' 
"$CONNECTED_APP_CREDENTIALS")
-        EXISTING_CLIENT_SECRET=$(jq -r '.clientSecret // empty' 
"$CONNECTED_APP_CREDENTIALS")
-    fi
-
-    if [ -n "$EXISTING_CLIENT_ID" ] && [ -n "$EXISTING_CLIENT_SECRET" ]; then
-        # Valid credentials exist - connected app was previously created
-        # Deploy without consumerKey/consumerSecret (can't update these)
-        echo "Existing connected app credentials found - deploying without 
regenerating keys..."
-
-        # Generate connected app file without credentials (for update)
-        sed -e '/{{CONSUMER_KEY}}/d' \
-            -e '/{{CONSUMER_SECRET}}/d' \
-            "$CONNECTED_APP_TEMPLATE" > "$CONNECTED_APP_FILE"
-
-        echo "✓ Using existing connected app credentials"
-
-    elif [ -f "$CONNECTED_APP_TEMPLATE" ]; then
-        # First time setup - generate new credentials
-        echo "Generating OAuth credentials for connected app..."
-
-        # Generate random credentials using /dev/urandom
-        # Consumer Key: alphanumeric only (per Salesforce docs)
-        CONSUMER_KEY=$(head -c 48 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | 
head -c 64)
-        # Consumer Secret: uppercase hex (matching Salesforce's own format)
-        CONSUMER_SECRET=$(head -c 32 /dev/urandom | xxd -p | tr -d '\n' | tr 
'a-f' 'A-F' | head -c 64)
-
-        # Generate connected app file from template with credentials
-        sed -e "s|{{CONSUMER_KEY}}|${CONSUMER_KEY}|g" \
-            -e "s|{{CONSUMER_SECRET}}|${CONSUMER_SECRET}|g" \
-            "$CONNECTED_APP_TEMPLATE" > "$CONNECTED_APP_FILE"
-
-        # Save connected app credentials for future deployments
-        cat > "$CONNECTED_APP_CREDENTIALS" << EOF
-{
-    "clientId": "$CONSUMER_KEY",
-    "clientSecret": "$CONSUMER_SECRET"
-}
-EOF
-
-        echo "✓ OAuth credentials generated and saved"
-    else
-        echo "ERROR: Connected app template not found: $CONNECTED_APP_TEMPLATE"
-        exit 1
-    fi
-
     # Deploy the source (SF CLI uses the default org automatically)
     sf project deploy start \
         --source-dir salesforce-source \
@@ -231,38 +170,49 @@ fi
 # Get org information including refresh token
 echo ""
 echo "Retrieving org information..."
-ORG_INFO=$(sf org display --verbose --json)
+ORG_INFO=$(sf org display --json)
 INSTANCE_URL=$(echo "$ORG_INFO" | jq -r '.result.instanceUrl')
 ORG_USERNAME=$(echo "$ORG_INFO" | jq -r '.result.username')
-SFDX_AUTH_URL=$(echo "$ORG_INFO" | jq -r '.result.sfdxAuthUrl // empty')
 
-# Extract refresh token from sfdxAuthUrl (format: 
force://clientId::refreshToken@instanceUrl)
-if [ -n "$SFDX_AUTH_URL" ]; then
-    REFRESH_TOKEN=$(echo "$SFDX_AUTH_URL" | sed -n 
's|force://[^:]*::\([^@]*\)@.*|\1|p')
+# sf org display redacts the auth URL, whose format is 
force://clientId:clientSecret:refreshToken@instanceUrl
+SFDX_AUTH_URL=$(sf org auth show-sfdx-auth-url --json | jq -r 
'.result.sfdxAuthUrl // empty')
+CLIENT_ID=$(echo "$SFDX_AUTH_URL" | sed -n 's|force://\([^:]*\):.*|\1|p')
+CLIENT_SECRET=$(echo "$SFDX_AUTH_URL" | sed -n 
's|force://[^:]*:\([^:]*\):.*|\1|p')
+REFRESH_TOKEN=$(echo "$SFDX_AUTH_URL" | sed -n 
's|force://[^:]*:[^:]*:\([^@]*\)@.*|\1|p')
+
+if [ -z "$REFRESH_TOKEN" ]; then
+    if [ -n "$HAS_PASSWORD" ] || [ -n "$SALESFORCE_REFRESH_TOKEN" ] || [ -n 
"$SALESFORCE_KEYSTORE_RESOURCE" ] || [ -f "$LOGIN_PROPERTIES" ]; then
+        echo "WARNING: No refresh token for $ORG_USERNAME, the tests must get 
their credentials elsewhere"
+    else
+        echo "ERROR: Could not get a refresh token for $ORG_USERNAME"
+        echo "It is only available for orgs authenticated with a web-based 
OAuth flow, such as scratch orgs."
+        exit 1
+    fi
+else
+    fail_on_password_with_refresh_token
 fi
 
 echo "✓ Instance URL: $INSTANCE_URL"
 echo "✓ Username: $ORG_USERNAME"
-if [ -n "$REFRESH_TOKEN" ]; then
-    echo "✓ Refresh token available"
-fi
 
 # Store credentials for integration tests
-# Using refresh token flow with PlatformCLI (SF CLI's built-in connected app)
+# Using refresh token flow with the app the org was logged in with, by default 
PlatformCLI (SF CLI's built-in connected app)
 CREDENTIALS_FILE="$PROJECT_DIR/.local/test-credentials.json"
 
-# Ensure .local directory exists
+# Only the user may read the credentials; chmod as well, as rewriting a file 
keeps its permissions
 mkdir -p "$PROJECT_DIR/.local"
+chmod 700 "$PROJECT_DIR/.local"
 echo ""
 echo "Storing credentials for integration tests..."
 
-cat > "$CREDENTIALS_FILE" << EOF
-{
-    "clientId": "PlatformCLI",
-    "refreshToken": "${REFRESH_TOKEN:-}",
-    "instanceUrl": "$INSTANCE_URL"
-}
-EOF
+umask 077
+touch "$CREDENTIALS_FILE"
+chmod 600 "$CREDENTIALS_FILE"
+# Values go through the environment, not the command line, where other users 
could see the secrets
+SF_CLIENT_ID="${CLIENT_ID:-PlatformCLI}" SF_CLIENT_SECRET="$CLIENT_SECRET" 
SF_REFRESH_TOKEN="$REFRESH_TOKEN" \
+    SF_USERNAME="$ORG_USERNAME" SF_INSTANCE_URL="$INSTANCE_URL" \
+    jq -n '{clientId: env.SF_CLIENT_ID, clientSecret: env.SF_CLIENT_SECRET, 
refreshToken: env.SF_REFRESH_TOKEN,
+            username: env.SF_USERNAME, instanceUrl: env.SF_INSTANCE_URL}' > 
"$CREDENTIALS_FILE"
 
 echo "✓ Credentials stored in: $CREDENTIALS_FILE"
 
diff --git 
a/components/camel-salesforce/it/resources/sfdx-project/config/CamelSalesforceIntegrationTests.connectedApp-template.xml
 
b/components/camel-salesforce/it/resources/sfdx-project/config/CamelSalesforceIntegrationTests.connectedApp-template.xml
deleted file mode 100644
index 1fdddf513740..000000000000
--- 
a/components/camel-salesforce/it/resources/sfdx-project/config/CamelSalesforceIntegrationTests.connectedApp-template.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-
--->
-<ConnectedApp xmlns="http://soap.sforce.com/2006/04/metadata";>
-    <contactEmail>[email protected]</contactEmail>
-    <label>CamelSalesforceIntegrationTests</label>
-    <oauthConfig>
-        
<callbackUrl>https://login.salesforce.com/services/oauth2/success</callbackUrl>
-        <consumerKey>{{CONSUMER_KEY}}</consumerKey>
-        <consumerSecret>{{CONSUMER_SECRET}}</consumerSecret>
-        <scopes>Api</scopes>
-        <scopes>RefreshToken</scopes>
-    </oauthConfig>
-</ConnectedApp>
diff --git 
a/components/camel-salesforce/test-salesforce-login.sample.properties 
b/components/camel-salesforce/test-salesforce-login.sample.properties
index 2b26ac7edd1b..3ddbb03243f4 100644
--- a/components/camel-salesforce/test-salesforce-login.sample.properties
+++ b/components/camel-salesforce/test-salesforce-login.sample.properties
@@ -18,14 +18,10 @@
 # account. You can get a Salesforce Developer account by visiting 
 # https://developer.salesforce.com and sign up for one.
 #
-# The connected application can be created for you by running the
-# migrations from Maven, run:
+# The recommended setup does not need this file, see it/resources/README.md.
 #
-#     $ mvn -Pintegration antrun:run@setup-salesforce-instance
-#
-# from camel-salesforce-component directory, or you can setup your own
-# connected application by going to your Salesforce Developer account 
-# and under Apps in Build and Create sections click New in Connected
+# To use your own connected application, go to your Salesforce Developer
+# account and under Apps in Build and Create sections click New in Connected
 # Apps section. Fill in the required fields and in the API (Enable OAuth
 # Settings) section thick Enable OAuth Settings and move all scopes from
 # Available OAuth Scopes to Selected OAuth Scopes.
@@ -44,17 +40,9 @@
 # salesforce.auth.type = USERNAME_PASSWORD
 
 # This is the Consumer Key of the connected application
-# This `salesforce.client.id` is setup by the migration run at the start of 
-# integration tests (when run from Maven):
-# salesforce.client.id = 
3MVG9HxRZv05HarQ5D2to.ylPaUg7uaFqGqE2wN6_RRaHM9PTa3SWT8UwKJzXAyCujHrfObkUy7oZqiBUyfGl
-#
 salesforce.client.id = <Your Consumer Key>
 
 # This is Consumer Secret of the connected application
-# If you use the above clientId (3MV...Gl) get the Consumer Secret from
-# your Salesforce instance after migration run, access your Salesforce
-# instance and get the Consumer Secret from there for 
-# CamelSalesforceIntegrationTests connected application
 salesforce.client.secret = <Your Consumer Secret>
 
 # This is the username for the Salesforce account, you can use your own

Reply via email to