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

davsclaus pushed a commit to branch backport/30204-to-camel-4-22-x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b561e9ffbdd8405d5e7cc6cd31024c26ac9b8f9a
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 16 21:03:28 2026 +0100

    CAMEL-27049: camel-main - mask the server and vault options flagged secret 
(#30204)
    
    UpdateSensitizeHelper also collects the camel-main options flagged secret, 
as
    whole keys, into a new generated set SENSITIVE_WHOLE_KEYS in SensitiveUtils
    (and sensitive-whole-keys.json), which containsSensitive checks first. The
    server and management JWT keystore passwords and the Azure, GCP and IBM 
vault
    secrets are now masked in the auto-configuration summary and reported by
    camel.security.secretPolicy. Component and endpoint options with the same 
name
    are not affected. The beans catalog is scanned too. 
SecretOptionsAreSensitiveKeysTest
    fails the build when a secret option is not a sensitive key. Upgrade guide 
4.24
    updated.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    (cherry picked from commit ed0e2476a06175bb1b1211adea06f7db211a3236)
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../camel/catalog/main/sensitive-whole-keys.json   | 30 +++++++
 .../catalog/SecretOptionsAreSensitiveKeysTest.java | 72 +++++++++++++++++
 .../MainAutoConfigurationSummaryMaskingTest.java   | 91 ++++++++++++++++++++++
 .../apache/camel/main/MainSecurityPolicyTest.java  | 55 +++++++++++++
 .../src/test/resources/summary-masking.properties  | 19 +++++
 .../java/org/apache/camel/util/SensitiveUtils.java | 46 ++++++++++-
 .../org/apache/camel/util/SensitiveUtilsTest.java  | 30 +++++++
 .../maven/packaging/UpdateSensitizeHelper.java     | 55 +++++++++----
 8 files changed, 381 insertions(+), 17 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/sensitive-whole-keys.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/sensitive-whole-keys.json
new file mode 100644
index 000000000000..2f82dcff575f
--- /dev/null
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/sensitive-whole-keys.json
@@ -0,0 +1,30 @@
+[
+  "camel.cluster.consul.acltoken",
+  "camel.cluster.consul.password",
+  "camel.cluster.consul.username",
+  "camel.cluster.infinispan.password",
+  "camel.lra.callbacksecret",
+  "camel.management.jwtkeystorepassword",
+  "camel.server.jwtkeystorepassword",
+  "camel.ssl.keystorepassword",
+  "camel.ssl.truststorepassword",
+  "camel.vault.aws.accesskey",
+  "camel.vault.aws.secretkey",
+  "camel.vault.azure.blobaccesskey",
+  "camel.vault.azure.clientid",
+  "camel.vault.azure.clientsecret",
+  "camel.vault.azure.eventhubconnectionstring",
+  "camel.vault.azure.tenantid",
+  "camel.vault.cyberark.apikey",
+  "camel.vault.cyberark.authtoken",
+  "camel.vault.cyberark.password",
+  "camel.vault.cyberark.username",
+  "camel.vault.gcp.serviceaccountkey",
+  "camel.vault.hashicorp.token",
+  "camel.vault.ibm.eventstreampassword",
+  "camel.vault.ibm.eventstreamusername",
+  "camel.vault.ibm.token",
+  "camel.vault.springconfig.password",
+  "camel.vault.springconfig.token",
+  "camel.vault.springconfig.username"
+]
diff --git 
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/SecretOptionsAreSensitiveKeysTest.java
 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/SecretOptionsAreSensitiveKeysTest.java
new file mode 100644
index 000000000000..f59616673af8
--- /dev/null
+++ 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/SecretOptionsAreSensitiveKeysTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+package org.apache.camel.catalog;
+
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.camel.tooling.model.BaseOptionModel;
+import org.apache.camel.util.SensitiveUtils;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Every option flagged secret in the catalog must be a sensitive key, so its 
value is masked wherever Camel masks
+ * sensitive keys (such as the Camel Main auto-configuration summary).
+ */
+class SecretOptionsAreSensitiveKeysTest {
+
+    private static final CamelCatalog CATALOG = new DefaultCamelCatalog();
+
+    @Test
+    void everySecretMainOptionIsASensitiveKey() {
+        Set<String> missing = new TreeSet<>();
+        collectMissing("main", CATALOG.mainModel().getOptions(), missing);
+
+        assertTrue(missing.isEmpty(), "Secret options missing from the 
sensitive keys: " + missing);
+    }
+
+    @Test
+    void everySecretComponentDataFormatLanguageAndBeanOptionIsASensitiveKey() {
+        Set<String> missing = new TreeSet<>();
+        for (String name : CATALOG.findComponentNames()) {
+            collectMissing("component:" + name, 
CATALOG.componentModel(name).getComponentOptions(), missing);
+        }
+        for (String name : CATALOG.findDataFormatNames()) {
+            collectMissing("dataformat:" + name, 
CATALOG.dataFormatModel(name).getOptions(), missing);
+        }
+        for (String name : CATALOG.findLanguageNames()) {
+            collectMissing("language:" + name, 
CATALOG.languageModel(name).getOptions(), missing);
+        }
+        for (String name : CATALOG.findBeansNames()) {
+            collectMissing("bean:" + name, 
CATALOG.pojoBeanModel(name).getOptions(), missing);
+        }
+
+        assertTrue(missing.isEmpty(), "Secret options missing from the 
sensitive keys: " + missing);
+    }
+
+    private static void collectMissing(String owner, List<? extends 
BaseOptionModel> options, Set<String> missing) {
+        for (BaseOptionModel option : options) {
+            boolean secret = option.isSecret() || 
"secret".equals(option.getSecurity());
+            if (secret && !SensitiveUtils.containsSensitive(option.getName())) 
{
+                missing.add(owner + " " + option.getName());
+            }
+        }
+    }
+}
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainAutoConfigurationSummaryMaskingTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainAutoConfigurationSummaryMaskingTest.java
new file mode 100644
index 000000000000..969fd4c30a31
--- /dev/null
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainAutoConfigurationSummaryMaskingTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+package org.apache.camel.main;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.config.Property;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.parallel.Isolated;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@Isolated
+class MainAutoConfigurationSummaryMaskingTest {
+
+    private static final String LOGGER = BaseMainSupport.class.getName();
+
+    private final List<String> messages = new CopyOnWriteArrayList<>();
+    private AbstractAppender appender;
+
+    @BeforeEach
+    void addAppender() {
+        appender = new 
AbstractAppender("MainAutoConfigurationSummaryMaskingTest", null, null, true, 
Property.EMPTY_ARRAY) {
+            @Override
+            public void append(LogEvent event) {
+                messages.add(event.getMessage().getFormattedMessage());
+            }
+        };
+        appender.start();
+        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
+        Configuration config = ctx.getConfiguration();
+        LoggerConfig loggerConfig = new LoggerConfig(LOGGER, Level.INFO, true);
+        loggerConfig.addAppender(appender, Level.INFO, null);
+        config.addLogger(LOGGER, loggerConfig);
+        ctx.updateLoggers();
+    }
+
+    @AfterEach
+    void removeAppender() {
+        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
+        ctx.getConfiguration().removeLogger(LOGGER);
+        ctx.updateLoggers();
+        appender.stop();
+    }
+
+    @Test
+    void serverJwtKeystorePasswordIsMaskedInSummary() {
+        assertMaskedInSummary("camel.server.jwtKeystorePassword", 
"Keyst0reS3cr3t");
+    }
+
+    @Test
+    void vaultEventhubConnectionStringIsMaskedInSummary() {
+        assertMaskedInSummary("camel.vault.azure.eventhubConnectionString", 
"C0nnS3cr3t");
+    }
+
+    private void assertMaskedInSummary(String key, String value) {
+        Main main = new Main();
+        
main.setPropertyPlaceholderLocations("classpath:summary-masking.properties");
+        main.start();
+        try {
+            assertTrue(messages.stream().anyMatch(m -> m.contains(key + " = 
xxxxxx")), messages.toString());
+            assertTrue(messages.stream().noneMatch(m -> m.contains(value)), 
messages.toString());
+        } finally {
+            main.stop();
+        }
+    }
+}
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
index 1bc71551886d..601feab95eef 100644
--- 
a/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainSecurityPolicyTest.java
@@ -22,7 +22,9 @@ import java.util.Map;
 import java.util.Set;
 import java.util.stream.Stream;
 
+import org.apache.camel.Endpoint;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.support.DefaultComponent;
 import org.apache.camel.util.SecurityUtils;
 import org.apache.camel.util.SecurityViolation;
 import org.junit.jupiter.api.Test;
@@ -552,4 +554,57 @@ public class MainSecurityPolicyTest {
             main.stop();
         }
     }
+
+    @Test
+    public void testComponentOptionWithTheNameOfASecretVaultOption() {
+        // serviceAccountKey and tenantId are secret as camel.vault options, 
but not as component options
+        Main main = new Main();
+        main.bind("google-pubsub", new MyCloudComponent());
+        main.bind("azure-storage-datalake", new MyCloudComponent());
+        main.addInitialProperty("camel.main.profile", "prod");
+        
main.addInitialProperty("camel.component.google-pubsub.serviceAccountKey", 
"classpath:sa.json");
+        
main.addInitialProperty("camel.component.azure-storage-datalake.tenantId", 
"mytenant");
+
+        assertDoesNotThrow(() -> {
+            main.start();
+            main.stop();
+        });
+    }
+
+    @Test
+    public void testPlainTextSecretVaultOption() {
+        Main main = new Main();
+        main.addInitialProperty("camel.main.profile", "prod");
+        main.addInitialProperty("camel.vault.azure.tenantId", "mytenant");
+
+        RuntimeCamelException ex = assertThrows(RuntimeCamelException.class, 
main::start);
+        assertTrue(ex.getMessage().contains("camel.vault.azure.tenantId"), 
ex.getMessage());
+    }
+
+    public static class MyCloudComponent extends DefaultComponent {
+
+        private String serviceAccountKey;
+        private String tenantId;
+
+        public String getServiceAccountKey() {
+            return serviceAccountKey;
+        }
+
+        public void setServiceAccountKey(String serviceAccountKey) {
+            this.serviceAccountKey = serviceAccountKey;
+        }
+
+        public String getTenantId() {
+            return tenantId;
+        }
+
+        public void setTenantId(String tenantId) {
+            this.tenantId = tenantId;
+        }
+
+        @Override
+        protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) {
+            throw new UnsupportedOperationException();
+        }
+    }
 }
diff --git a/core/camel-main/src/test/resources/summary-masking.properties 
b/core/camel-main/src/test/resources/summary-masking.properties
new file mode 100644
index 000000000000..0e4ad64be212
--- /dev/null
+++ b/core/camel-main/src/test/resources/summary-masking.properties
@@ -0,0 +1,19 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+camel.server.jwtKeystorePassword=Keyst0reS3cr3t
+camel.vault.azure.eventhubConnectionString=Endpoint=sb://myhub/;Key=C0nnS3cr3t
diff --git 
a/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java 
b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
index 0de887f8ab46..c50023c5ceb9 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java
@@ -136,6 +136,42 @@ public final class SensitiveUtils {
             // SENSITIVE-KEYS: END
             )));
 
+    // the camel-main options flagged secret, matched by their whole key in 
lower case without dashes, as a component can
+    // have an option with the same name that is not secret (such as tenantId)
+    private static final Set<String> SENSITIVE_WHOLE_KEYS = Set.of(
+            // Generated by camel build tools - do NOT edit this list!
+            // SENSITIVE-WHOLE-KEYS: START
+            "camel.cluster.consul.acltoken",
+            "camel.cluster.consul.password",
+            "camel.cluster.consul.username",
+            "camel.cluster.infinispan.password",
+            "camel.lra.callbacksecret",
+            "camel.management.jwtkeystorepassword",
+            "camel.server.jwtkeystorepassword",
+            "camel.ssl.keystorepassword",
+            "camel.ssl.truststorepassword",
+            "camel.vault.aws.accesskey",
+            "camel.vault.aws.secretkey",
+            "camel.vault.azure.blobaccesskey",
+            "camel.vault.azure.clientid",
+            "camel.vault.azure.clientsecret",
+            "camel.vault.azure.eventhubconnectionstring",
+            "camel.vault.azure.tenantid",
+            "camel.vault.cyberark.apikey",
+            "camel.vault.cyberark.authtoken",
+            "camel.vault.cyberark.password",
+            "camel.vault.cyberark.username",
+            "camel.vault.gcp.serviceaccountkey",
+            "camel.vault.hashicorp.token",
+            "camel.vault.ibm.eventstreampassword",
+            "camel.vault.ibm.eventstreamusername",
+            "camel.vault.ibm.token",
+            "camel.vault.springconfig.password",
+            "camel.vault.springconfig.token",
+            "camel.vault.springconfig.username"
+    // SENSITIVE-WHOLE-KEYS: END
+    );
+
     private static final String SENSITIVE_PATTERN = ""
                                                     // Generated by camel 
build tools - do NOT edit this list!
                                                     // SENSITIVE-PATTERN: START
@@ -256,17 +292,23 @@ public final class SensitiveUtils {
 
     /**
      * Whether the given configuration property contains a sensitive key (such 
as password, accesstoken, etc.)
+     * <p>
+     * The camel-main options flagged secret (such as {@code 
camel.vault.azure.tenantId}) are matched by their whole
+     * key. Any other key is matched by its last part (the option name). The 
match ignores case and dashes.
      *
      * @param  text the configuration property
      * @return      true if sensitive, false otherwise
      */
     public static boolean containsSensitive(String text) {
+        text = text.toLowerCase(Locale.ENGLISH);
+        text = text.replace("-", "");
+        if (SENSITIVE_WHOLE_KEYS.contains(text)) {
+            return true;
+        }
         int lastPeriod = text.lastIndexOf('.');
         if (lastPeriod >= 0) {
             text = text.substring(lastPeriod + 1);
         }
-        text = text.toLowerCase(Locale.ENGLISH);
-        text = text.replace("-", "");
         return SENSITIVE_KEYS.contains(text);
     }
 
diff --git 
a/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java 
b/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
index 78a604198124..49a0344b54ee 100644
--- 
a/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
+++ 
b/core/camel-util/src/test/java/org/apache/camel/util/SensitiveUtilsTest.java
@@ -54,6 +54,36 @@ class SensitiveUtilsTest {
         assertThat(SensitiveUtils.containsSensitive("bar")).isFalse();
     }
 
+    @Test
+    void serverAndVaultSecretOptionsAreSensitive() {
+        
assertThat(SensitiveUtils.containsSensitive("camel.server.jwtKeystorePassword")).isTrue();
+        
assertThat(SensitiveUtils.containsSensitive("camel.management.jwtKeystorePassword")).isTrue();
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.azure.eventhubConnectionString")).isTrue();
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.azure.tenantId")).isTrue();
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.gcp.serviceAccountKey")).isTrue();
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.ibm.eventStreamUsername")).isTrue();
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.ibm.eventStreamPassword")).isTrue();
+        // dash case
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.azure.tenant-id")).isTrue();
+        
assertThat(SensitiveUtils.containsSensitive("camel.server.jwt-keystore-password")).isTrue();
+        // as loaded from the environment variable 
CAMEL_VAULT_GCP_SERVICEACCOUNTKEY
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.gcp.serviceaccountkey")).isTrue();
+    }
+
+    @Test
+    void componentOptionsWithTheNameOfASecretMainOptionAreNotSensitive() {
+        // serviceAccountKey and tenantId are secret as camel.vault options 
only, and not as component options
+        
assertThat(SensitiveUtils.containsSensitive("camel.component.google-pubsub.serviceAccountKey")).isFalse();
+        
assertThat(SensitiveUtils.containsSensitive("camel.component.azure-storage-datalake.tenantId")).isFalse();
+        
assertThat(SensitiveUtils.containsSensitive("serviceAccountKey")).isFalse();
+        assertThat(SensitiveUtils.containsSensitive("tenantId")).isFalse();
+        
assertThat(SensitiveUtils.containsSensitive("jwtKeystorePassword")).isFalse();
+        
assertThat(SensitiveUtils.containsSensitive("camel.vault.azure.tenantId.foo")).isFalse();
+        // and an endpoint uri parameter with such a name is not masked
+        
assertThat(URISupport.sanitizeUri("azure-storage-datalake:myaccount?tenantId=mytenant&accountKey=mykey"))
+                
.isEqualTo("azure-storage-datalake:myaccount?tenantId=mytenant&accountKey=xxxxxx");
+    }
+
     @Test
     void maskUserInfoCredentialsMasksPasswordInCommonSchemes() {
         
assertThat(SensitiveUtils.maskUserInfoCredentials("mongodb://user:pass@host:27017/db",
 "xxxxx"))
diff --git 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
index b1a751086c03..b0af401abbc6 100644
--- 
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
+++ 
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateSensitizeHelper.java
@@ -35,6 +35,8 @@ import org.apache.camel.tooling.model.ComponentModel;
 import org.apache.camel.tooling.model.DataFormatModel;
 import org.apache.camel.tooling.model.JsonMapper;
 import org.apache.camel.tooling.model.LanguageModel;
+import org.apache.camel.tooling.model.MainModel;
+import org.apache.camel.tooling.model.PojoBeanModel;
 import org.apache.camel.tooling.util.PackageHelper;
 import org.apache.camel.tooling.util.Strings;
 import org.apache.camel.util.json.JsonArray;
@@ -56,6 +58,8 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
 
     private static final String KEYS_START_TOKEN = "// SENSITIVE-KEYS: START";
     private static final String KEYS_END_TOKEN = "// SENSITIVE-KEYS: END";
+    private static final String WHOLE_KEYS_START_TOKEN = "// 
SENSITIVE-WHOLE-KEYS: START";
+    private static final String WHOLE_KEYS_END_TOKEN = "// 
SENSITIVE-WHOLE-KEYS: END";
     private static final String PATTERN_START_TOKEN = "// SENSITIVE-PATTERN: 
START";
     private static final String PATTERN_END_TOKEN = "// SENSITIVE-PATTERN: 
END";
     private static final String SECURITY_START_TOKEN = "// SECURITY-OPTIONS: 
START";
@@ -87,6 +91,10 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
                     "callbacksecret",
                     SECRET, "keystorePassword" };
 
+    // the camel-main configuration options (camel.server, camel.vault and 
others), whose secret options are matched by
+    // their whole key, as a component can have an option with the same name 
that is not secret (such as tenantId)
+    private static final String MAIN_METADATA = 
"camel-main-configuration-metadata.json";
+
     // extra security options from camel-main properties that are not in 
component JSON files
     // each entry: option name (lowercase, no dashes), security category, 
insecure value
     private static final String[][] EXTRA_SECURITY_OPTIONS = {
@@ -124,6 +132,8 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
             jsonFiles = stream.toList();
         }
         Set<String> secrets = new TreeSet<>();
+        // the whole keys of the camel-main options flagged secret (such as 
camel.vault.azure.tenantid)
+        Set<String> wholeKeys = new TreeSet<>();
         // key -> [category, insecureValue]
         Map<String, String[]> securityOptions = new TreeMap<>();
 
@@ -143,13 +153,22 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
                 boolean isComponent = obj.getMap("component") != null;
                 boolean isDataFormat = !isComponent && 
obj.getMap("dataformat") != null;
                 boolean isLanguage = !isComponent && !isDataFormat && 
obj.getMap("language") != null;
+                boolean isBean = !isComponent && !isDataFormat && !isLanguage 
&& obj.getMap("bean") != null;
+                boolean isMain = 
MAIN_METADATA.equals(file.getFileName().toString());
 
                 // only check these kind
-                if (!isComponent && !isDataFormat && !isLanguage) {
+                if (!isComponent && !isDataFormat && !isLanguage && !isBean && 
!isMain) {
                     continue;
                 }
 
-                if (isComponent) {
+                if (isMain) {
+                    // the option names are whole keys (such as 
camel.server.jwtKeystorePassword)
+                    MainModel mm = JsonMapper.generateMainModel(obj);
+                    mm.getOptions().forEach(o -> collectSecretOption(o, 
wholeKeys));
+                } else if (isBean) {
+                    PojoBeanModel pm = JsonMapper.generatePojoBeanModel(obj);
+                    pm.getOptions().forEach(o -> collectSecretOption(o, 
secrets));
+                } else if (isComponent) {
                     ComponentModel cm = 
JsonMapper.generateComponentModel(json);
                     cm.getComponentOptions().forEach(o -> {
                         collectSecretOption(o, secrets);
@@ -178,10 +197,14 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
         secrets.addAll(Arrays.asList(EXTRA_KEYS));
 
         getLog().info("There are " + secrets.size()
-                      + " distinct secret options across all the Camel 
components/dataformats/languages");
+                      + " distinct secret options across all the Camel 
components/dataformats/languages/beans, and "
+                      + wholeKeys.size() + " secret camel-main options");
 
         try {
-            boolean updated = updateSensitiveHelperKeys(camelDir, secrets);
+            boolean updated = updateSensitiveHelperKeys(camelDir, 
KEYS_START_TOKEN, KEYS_END_TOKEN, secrets,
+                    "                    ");
+            updated |= updateSensitiveHelperKeys(camelDir, 
WHOLE_KEYS_START_TOKEN, WHOLE_KEYS_END_TOKEN, wholeKeys,
+                    "            ");
             updated |= updateSensitiveHelperPatterns(camelDir, secrets);
             if (updated) {
                 getLog().info("Updated 
camel-util/src/main/java/org/apache/camel/util/SensitiveUtils.java file");
@@ -193,9 +216,10 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
         }
 
         try {
-            updateSensitiveJsonSchema(baseDir, secrets);
+            updateSensitiveJsonSchema(baseDir, "sensitive-keys.json", secrets);
+            updateSensitiveJsonSchema(baseDir, "sensitive-whole-keys.json", 
wholeKeys);
         } catch (Exception e) {
-            throw new MojoExecutionException("Error updating 
sensitive-keys.json", e);
+            throw new MojoExecutionException("Error updating 
sensitive-keys.json or sensitive-whole-keys.json", e);
         }
 
         // add extra security options from camel-main properties
@@ -220,20 +244,21 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
         }
     }
 
-    private boolean updateSensitiveHelperKeys(File camelDir, Set<String> 
secrets) throws Exception {
+    private boolean updateSensitiveHelperKeys(
+            File camelDir, String startToken, String endToken, Set<String> 
secrets, String indent)
+            throws Exception {
         // load source code and update
         File java = new File(camelDir, 
"src/main/java/org/apache/camel/util/SensitiveUtils.java");
         String text = PackageHelper.loadText(java);
-        String spaces20 = "                    ";
         String spaces12 = "            ";
 
         StringJoiner sb = new StringJoiner(",\n");
         for (String name : secrets) {
-            sb.add(spaces20 + "\"" + name + "\"");
+            sb.add(indent + "\"" + name + "\"");
         }
         String changed = sb.toString();
 
-        String existing = Strings.between(text, KEYS_START_TOKEN, 
KEYS_END_TOKEN);
+        String existing = Strings.between(text, startToken, endToken);
         if (existing != null) {
             // remove leading line breaks etc
             existing = existing.trim();
@@ -241,9 +266,9 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
             if (existing.equals(changed)) {
                 return false;
             } else {
-                String before = Strings.before(text, KEYS_START_TOKEN);
-                String after = Strings.after(text, KEYS_END_TOKEN);
-                text = before + KEYS_START_TOKEN + "\n" + spaces20 + changed + 
"\n" + spaces12 + KEYS_END_TOKEN + after;
+                String before = Strings.before(text, startToken);
+                String after = Strings.after(text, endToken);
+                text = before + startToken + "\n" + indent + changed + "\n" + 
spaces12 + endToken + after;
                 PackageHelper.writeText(java, text);
                 return true;
             }
@@ -294,8 +319,8 @@ public class UpdateSensitizeHelper extends 
AbstractGeneratorMojo {
         return false;
     }
 
-    private void updateSensitiveJsonSchema(File camelDir, Set<String> secrets) 
throws Exception {
-        File target = new File(camelDir, 
"src/generated/resources/org/apache/camel/catalog/main/sensitive-keys.json");
+    private void updateSensitiveJsonSchema(File camelDir, String fileName, 
Set<String> secrets) throws Exception {
+        File target = new File(camelDir, 
"src/generated/resources/org/apache/camel/catalog/main/" + fileName);
         JsonArray arr = new JsonArray();
         arr.addAll(secrets);
         String json = JsonMapper.serialize(arr);

Reply via email to