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

davsclaus 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 7d7702344413 CAMEL-27342: camel-jbang - CVE audit connects to OSV.dev 
through the proxy of the Maven settings or HTTPS_PROXY, with proxy 
authentication (#30556)
7d7702344413 is described below

commit 7d770234441311ea25aae36ef40bf6572e81462c
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 18:58:20 2026 +0100

    CAMEL-27342: camel-jbang - CVE audit connects to OSV.dev through the proxy 
of the Maven settings or HTTPS_PROXY, with proxy authentication (#30556)
    
    camel dependency audit and the CVE Audit screen of the TUI reach OSV.dev 
through the active proxy of the Maven settings (with its login and 
nonProxyHosts), then HTTPS_PROXY / HTTP_PROXY and NO_PROXY, then the JVM proxy 
settings. Every HTTP client that logs in to a proxy allows Basic for the HTTPS 
tunnel before it is built, as the JDK disables it by default.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 catalog/camel-catalog-cve/pom.xml                  |  14 ++
 .../org/apache/camel/catalog/cve/HttpProxy.java    | 214 +++++++++++++++++++++
 .../org/apache/camel/catalog/cve/OsvClient.java    |  65 +++++--
 .../apache/camel/catalog/cve/HttpProxyTest.java    |  96 +++++++++
 .../camel/catalog/cve/OsvClientProxyTest.java      | 104 ++++++++++
 .../modules/ROOT/pages/camel-jbang-projects.adoc   |  13 ++
 .../ROOT/pages/camel-jbang-tui-settings.adoc       |   6 +-
 .../dsl/jbang/core/commands/DependencyAudit.java   |  14 +-
 .../camel/dsl/jbang/core/common/OsvProxy.java      |  64 ++++++
 .../camel/dsl/jbang/core/common/OsvProxyTest.java  |  75 ++++++++
 .../dsl/jbang/core/commands/tui/CveAuditTab.java   |   7 +-
 .../dsl/jbang/core/commands/tui/DocHelper.java     |  12 +-
 .../dsl/jbang/core/commands/tui/TuiSettings.java   |  26 ++-
 .../camel/tooling/maven/MavenDownloaderImpl.java   |  45 +++++
 .../org/apache/camel/tooling/maven/MavenProxy.java |  37 ++++
 .../tooling/maven/MavenDownloaderProxyTest.java    |  84 ++++++++
 16 files changed, 845 insertions(+), 31 deletions(-)

diff --git a/catalog/camel-catalog-cve/pom.xml 
b/catalog/camel-catalog-cve/pom.xml
index e31306b714c1..a04c8610a6aa 100644
--- a/catalog/camel-catalog-cve/pom.xml
+++ b/catalog/camel-catalog-cve/pom.xml
@@ -65,4 +65,18 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <!-- the JDK reads jdk.http.auth.tunneling.disabledSchemes 
once, when the first HTTP client of
+                         the JVM is used: OsvClientProxyTest needs a JVM whose 
HTTP clients did not run yet -->
+                    <reuseForks>false</reuseForks>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>
diff --git 
a/catalog/camel-catalog-cve/src/main/java/org/apache/camel/catalog/cve/HttpProxy.java
 
b/catalog/camel-catalog-cve/src/main/java/org/apache/camel/catalog/cve/HttpProxy.java
new file mode 100644
index 000000000000..e46b83a1d2c9
--- /dev/null
+++ 
b/catalog/camel-catalog-cve/src/main/java/org/apache/camel/catalog/cve/HttpProxy.java
@@ -0,0 +1,214 @@
+/*
+ * 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.cve;
+
+import java.io.IOException;
+import java.net.Authenticator;
+import java.net.InetSocketAddress;
+import java.net.PasswordAuthentication;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * The HTTP proxy to reach OSV.dev through, such as the proxy of the Maven 
settings or of the {@code HTTPS_PROXY}
+ * environment variable, with the optional username and password of the proxy 
and the hosts to reach without it.
+ *
+ * @param host          the host of the proxy
+ * @param port          the port of the proxy
+ * @param username      the username to log in to the proxy, or null
+ * @param password      the password to log in to the proxy, or null
+ * @param nonProxyHosts the hosts to connect to directly: {@code *} for all, 
{@code *.corp.com} or {@code .corp.com} for
+ *                      the hosts of a domain, and {@code corp.com} for that 
host and the hosts of its domain
+ */
+public record HttpProxy(String host, int port, String username, String 
password, List<String> nonProxyHosts) {
+
+    /** The property of the JDK that lists the schemes it does not use to log 
in to a proxy for HTTPS. */
+    public static final String TUNNELING_DISABLED_SCHEMES = 
"jdk.http.auth.tunneling.disabledSchemes";
+
+    public HttpProxy {
+        nonProxyHosts = nonProxyHosts != null ? List.copyOf(nonProxyHosts) : 
List.of();
+    }
+
+    public HttpProxy(String host, int port) {
+        this(host, port, null, null, List.of());
+    }
+
+    /**
+     * The proxy of the {@code HTTPS_PROXY} environment variable (else {@code 
https_proxy}, {@code HTTP_PROXY} or
+     * {@code http_proxy}), with the hosts of {@code NO_PROXY} (or {@code 
no_proxy}), as CI runners set them. Null when
+     * none is set.
+     */
+    public static HttpProxy fromEnvironment(Map<String, String> env) {
+        String url = firstOf(env, "HTTPS_PROXY", "https_proxy", "HTTP_PROXY", 
"http_proxy");
+        return parse(url, firstOf(env, "NO_PROXY", "no_proxy"));
+    }
+
+    /**
+     * A proxy given as a URL, such as {@code http://proxy.corp.com:3128} or 
{@code http://user:secret@proxy:8080} (port
+     * 80 by default, and the username and password URL encoded), and the 
hosts to reach without it, separated by commas
+     * or {@code |}. Null when the URL is blank or has no host.
+     */
+    public static HttpProxy parse(String url, String nonProxyHosts) {
+        if (url == null || url.isBlank()) {
+            return null;
+        }
+        String text = url.trim();
+        if (!text.contains("://")) {
+            text = "http://"; + text;
+        }
+        URI uri;
+        try {
+            uri = URI.create(text);
+        } catch (IllegalArgumentException e) {
+            return null;
+        }
+        if (uri.getHost() == null) {
+            return null;
+        }
+        String username = null;
+        String password = null;
+        String userInfo = uri.getRawUserInfo();
+        if (userInfo != null && !userInfo.isEmpty()) {
+            int colon = userInfo.indexOf(':');
+            username = decode(colon < 0 ? userInfo : userInfo.substring(0, 
colon));
+            password = colon < 0 ? null : decode(userInfo.substring(colon + 
1));
+        }
+        int port = uri.getPort() > 0 ? uri.getPort() : 80;
+        return new HttpProxy(uri.getHost(), port, username, password, 
splitHosts(nonProxyHosts));
+    }
+
+    /** The hosts of a list separated by commas or {@code |}, as NO_PROXY and 
the Maven settings write them. */
+    public static List<String> splitHosts(String hosts) {
+        List<String> answer = new ArrayList<>();
+        if (hosts != null) {
+            for (String h : hosts.split("[,|]")) {
+                String host = h.trim();
+                if (!host.isEmpty()) {
+                    answer.add(host.toLowerCase(Locale.ROOT));
+                }
+            }
+        }
+        return answer;
+    }
+
+    /** Whether the host is reached directly, without the proxy. */
+    public boolean bypasses(String targetHost) {
+        if (targetHost == null) {
+            return false;
+        }
+        String target = targetHost.toLowerCase(Locale.ROOT);
+        for (String h : nonProxyHosts) {
+            if ("*".equals(h)) {
+                return true;
+            }
+            if (h.startsWith("*.") || h.startsWith(".")) {
+                String domain = h.substring(h.indexOf('.'));
+                if (target.endsWith(domain) || 
target.equals(domain.substring(1))) {
+                    return true;
+                }
+            } else if (target.equals(h) || target.endsWith("." + h)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /** Whether the proxy needs a login. */
+    public boolean hasCredentials() {
+        return username != null && !username.isEmpty();
+    }
+
+    /** The proxy selector for an HTTP client: this proxy, except for the 
hosts to reach directly. */
+    public ProxySelector selector() {
+        Proxy proxy = new Proxy(Proxy.Type.HTTP, 
InetSocketAddress.createUnresolved(host, port));
+        return new ProxySelector() {
+            @Override
+            public List<Proxy> select(URI uri) {
+                return List.of(bypasses(uri.getHost()) ? Proxy.NO_PROXY : 
proxy);
+            }
+
+            @Override
+            public void connectFailed(URI uri, SocketAddress sa, IOException 
ioe) {
+                // nothing to remember: the proxy is the only route
+            }
+        };
+    }
+
+    /**
+     * The authenticator for an HTTP client that logs in to this proxy, and 
answers no server; null when the proxy needs
+     * no login. Calls {@link #allowBasicTunneling()}, so an HTTP client built 
with it can log in with Basic
+     * authentication when it tunnels HTTPS: get the authenticator before the 
client is built.
+     */
+    public Authenticator authenticator() {
+        if (!hasCredentials()) {
+            return null;
+        }
+        allowBasicTunneling();
+        char[] secret = password != null ? password.toCharArray() : new 
char[0];
+        return new Authenticator() {
+            @Override
+            protected PasswordAuthentication getPasswordAuthentication() {
+                if (getRequestorType() == RequestorType.PROXY && 
host.equalsIgnoreCase(getRequestingHost())
+                        && port == getRequestingPort()) {
+                    return new PasswordAuthentication(username, 
secret.clone());
+                }
+                return null;
+            }
+        };
+    }
+
+    /**
+     * Lets the HTTP client of the JDK log in to a proxy with Basic 
authentication when it tunnels HTTPS through it,
+     * which the JDK disables by default ({@value 
#TUNNELING_DISABLED_SCHEMES}{@code =Basic}). The JDK reads the
+     * property once, when the first HTTP client is used, so this must be 
called before that; a value set by the user is
+     * kept.
+     */
+    public static synchronized void allowBasicTunneling() {
+        if (System.getProperty(TUNNELING_DISABLED_SCHEMES) == null) {
+            System.setProperty(TUNNELING_DISABLED_SCHEMES, "");
+        }
+    }
+
+    /** The proxy as {@code host:port}, without the password. */
+    @Override
+    public String toString() {
+        return (hasCredentials() ? username + "@" : "") + host + ":" + port;
+    }
+
+    private static String firstOf(Map<String, String> env, String... names) {
+        for (String name : names) {
+            String value = env.get(name);
+            if (value != null && !value.isBlank()) {
+                return value;
+            }
+        }
+        return null;
+    }
+
+    private static String decode(String text) {
+        // percent-decoding only: a + in the user info is a +
+        return URLDecoder.decode(text.replace("+", "%2B"), 
StandardCharsets.UTF_8);
+    }
+}
diff --git 
a/catalog/camel-catalog-cve/src/main/java/org/apache/camel/catalog/cve/OsvClient.java
 
b/catalog/camel-catalog-cve/src/main/java/org/apache/camel/catalog/cve/OsvClient.java
index f8f37a4d6cf7..1dfea6ae9aa4 100644
--- 
a/catalog/camel-catalog-cve/src/main/java/org/apache/camel/catalog/cve/OsvClient.java
+++ 
b/catalog/camel-catalog-cve/src/main/java/org/apache/camel/catalog/cve/OsvClient.java
@@ -41,23 +41,37 @@ import 
org.apache.maven.artifact.versioning.ComparableVersion;
  */
 public class OsvClient {
 
-    private static final String BATCH_URL = 
"https://api.osv.dev/v1/querybatch";;
-    private static final String VULN_URL = "https://api.osv.dev/v1/vulns/";;
+    /** The OSV.dev API, to look up the proxy to reach it through. */
+    public static final String API_URL = "https://api.osv.dev/";;
+    private static final String BATCH_URL = API_URL + "v1/querybatch";
+    private static final String VULN_URL = API_URL + "v1/vulns/";
     private static final ConcurrentHashMap<String, List<Vulnerability>> CACHE 
= new ConcurrentHashMap<>();
     private static final ConcurrentHashMap<String, Vulnerability> 
VULN_DETAIL_CACHE = new ConcurrentHashMap<>();
 
-    private final ProxySelector proxySelector;
+    private final HttpProxy proxy;
     // why the last query got no answer from OSV.dev; null when it got one
     private volatile String lastError;
 
     /** A client with the proxy settings of the JVM. */
     public OsvClient() {
-        this(ProxySelector.getDefault());
+        this(null);
     }
 
-    /** A client that connects through the given proxies, such as those of the 
settings of the TUI. */
-    public OsvClient(ProxySelector proxySelector) {
-        this.proxySelector = proxySelector != null ? proxySelector : 
ProxySelector.getDefault();
+    /**
+     * A client that connects through the given proxy, such as the proxy of 
the Maven settings, logging in to it when it
+     * has a username; with the proxy settings of the JVM when null.
+     */
+    public OsvClient(HttpProxy proxy) {
+        this.proxy = proxy;
+        if (proxy != null && proxy.hasCredentials()) {
+            // before the first HTTP client of the JVM, which reads it once
+            HttpProxy.allowBasicTunneling();
+        }
+    }
+
+    /** The proxy this client connects through; null for the proxy settings of 
the JVM. */
+    public HttpProxy proxy() {
+        return proxy;
     }
 
     /**
@@ -156,10 +170,7 @@ public class OsvClient {
 
         boolean success = false;
         try {
-            HttpClient client = HttpClient.newBuilder()
-                    .connectTimeout(Duration.ofSeconds(5))
-                    .proxy(proxySelector)
-                    .build();
+            HttpClient client = newHttpClient();
             HttpRequest request = HttpRequest.newBuilder()
                     .uri(URI.create(BATCH_URL))
                     .timeout(Duration.ofSeconds(30))
@@ -169,7 +180,9 @@ public class OsvClient {
             HttpResponse<String> response = client.send(request, 
HttpResponse.BodyHandlers.ofString());
 
             if (response.statusCode() != 200) {
-                lastError = "OSV.dev answered with HTTP status " + 
response.statusCode();
+                lastError = response.statusCode() == 407
+                        ? proxyLoginError()
+                        : "OSV.dev answered with HTTP status " + 
response.statusCode();
             } else {
                 success = true;
                 JsonObject body = (JsonObject) 
Jsoner.deserialize(response.body());
@@ -219,7 +232,7 @@ public class OsvClient {
             lastError = "The query to OSV.dev was interrupted";
         } catch (Exception e) {
             // network errors: return whatever we have from cache; leave 
entries uncached for retry
-            lastError = "OSV.dev could not be reached: "
+            lastError = "OSV.dev could not be reached" + (proxy != null ? " 
through the proxy " + proxy : "") + ": "
                         + (e.getMessage() != null ? e.getMessage() : 
e.getClass().getSimpleName());
         }
 
@@ -235,6 +248,28 @@ public class OsvClient {
         return result;
     }
 
+    // the proxy answered 407 Proxy Authentication Required
+    private String proxyLoginError() {
+        if (proxy != null && proxy.hasCredentials()) {
+            // the JDK reads jdk.http.auth.tunneling.disabledSchemes once: an 
HTTP client used earlier in the JVM
+            // keeps Basic disabled
+            return "The proxy " + proxy + " refused the login (HTTP status 
407). For a proxy with Basic authentication, "
+                   + "start the JVM with -D" + 
HttpProxy.TUNNELING_DISABLED_SCHEMES + "= (an empty value)";
+        }
+        return "The proxy " + (proxy != null ? proxy + " " : "") + "needs a 
username and password (HTTP status 407): "
+               + "set them on the proxy of the Maven settings (settings.xml), 
or in HTTPS_PROXY";
+    }
+
+    private HttpClient newHttpClient() {
+        HttpClient.Builder builder = HttpClient.newBuilder()
+                .connectTimeout(Duration.ofSeconds(5))
+                .proxy(proxy != null ? proxy.selector() : 
ProxySelector.getDefault());
+        if (proxy != null && proxy.authenticator() != null) {
+            builder.authenticator(proxy.authenticator());
+        }
+        return builder.build();
+    }
+
     private void fetchVulnDetails(HttpClient client, Map<String, List<String>> 
gavToVulnIds) {
         // collect unique IDs not already in detail cache
         List<String> toFetch = gavToVulnIds.values().stream()
@@ -272,12 +307,12 @@ public class OsvClient {
         return lastError;
     }
 
-    public void clearCache() {
+    public static void clearCache() {
         CACHE.clear();
         VULN_DETAIL_CACHE.clear();
     }
 
-    public void clearCache(List<Dependency> entries) {
+    public static void clearCache(List<Dependency> entries) {
         for (Dependency entry : entries) {
             if (entry.groupId() != null) {
                 CACHE.remove(entry.gav());
diff --git 
a/catalog/camel-catalog-cve/src/test/java/org/apache/camel/catalog/cve/HttpProxyTest.java
 
b/catalog/camel-catalog-cve/src/test/java/org/apache/camel/catalog/cve/HttpProxyTest.java
new file mode 100644
index 000000000000..21d5e0e933e7
--- /dev/null
+++ 
b/catalog/camel-catalog-cve/src/test/java/org/apache/camel/catalog/cve/HttpProxyTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.cve;
+
+import java.net.Proxy;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-27342: the proxy of the CVE audit, from the environment variables of 
a CI runner or the Maven settings.
+ */
+class HttpProxyTest {
+
+    @Test
+    void parsesTheProxyUrl() {
+        HttpProxy proxy = HttpProxy.parse("http://proxy.corp.com:3128";, null);
+        assertThat(proxy.host()).isEqualTo("proxy.corp.com");
+        assertThat(proxy.port()).isEqualTo(3128);
+        assertThat(proxy.hasCredentials()).isFalse();
+        assertThat(proxy.authenticator()).isNull();
+
+        // no scheme, and port 80 by default
+        assertThat(HttpProxy.parse("proxy.corp.com", 
null).port()).isEqualTo(80);
+        assertThat(HttpProxy.parse("  ", null)).isNull();
+        assertThat(HttpProxy.parse(null, null)).isNull();
+    }
+
+    @Test
+    void parsesTheUsernameAndPassword() {
+        // URL encoded: the password is p@ss+w:rd
+        HttpProxy proxy = 
HttpProxy.parse("http://scott:p%40ss+w%3Ard@proxy:8080";, null);
+        assertThat(proxy.username()).isEqualTo("scott");
+        assertThat(proxy.password()).isEqualTo("p@ss+w:rd");
+        assertThat(proxy.hasCredentials()).isTrue();
+        assertThat(proxy.authenticator()).isNotNull();
+        // the authenticator lets the JDK log in with Basic when it tunnels 
HTTPS (this test runs in its own JVM)
+        
assertThat(System.getProperty(HttpProxy.TUNNELING_DISABLED_SCHEMES)).isEmpty();
+        // the password is never printed
+        assertThat(proxy).hasToString("scott@proxy:8080");
+    }
+
+    @Test
+    void readsTheEnvironmentOfCiRunners() {
+        HttpProxy proxy = HttpProxy.fromEnvironment(Map.of(
+                "https_proxy", "http://secure:8443";,
+                "HTTP_PROXY", "http://plain:8080";,
+                "no_proxy", "localhost, .corp.com"));
+        assertThat(proxy.host()).isEqualTo("secure");
+        assertThat(proxy.nonProxyHosts()).containsExactly("localhost", 
".corp.com");
+
+        assertThat(HttpProxy.fromEnvironment(Map.of("HTTP_PROXY", 
"http://plain:8080";)).host()).isEqualTo("plain");
+        assertThat(HttpProxy.fromEnvironment(Map.of())).isNull();
+    }
+
+    @Test
+    void bypassesTheNonProxyHosts() {
+        // as NO_PROXY and the Maven settings write them
+        HttpProxy proxy
+                = new HttpProxy("proxy", 8080, null, null, 
HttpProxy.splitHosts("localhost|*.corp.com,.intra,nexus.lan"));
+        assertThat(proxy.bypasses("localhost")).isTrue();
+        assertThat(proxy.bypasses("repo.corp.com")).isTrue();
+        assertThat(proxy.bypasses("corp.com")).isTrue();
+        assertThat(proxy.bypasses("a.b.intra")).isTrue();
+        assertThat(proxy.bypasses("nexus.lan")).isTrue();
+        assertThat(proxy.bypasses("eu.nexus.lan")).isTrue();
+        assertThat(proxy.bypasses("api.osv.dev")).isFalse();
+        assertThat(proxy.bypasses("notcorp.com")).isFalse();
+
+        
assertThat(proxy.selector().select(URI.create("https://api.osv.dev/v1/querybatch";)))
+                
.singleElement().extracting(Proxy::type).isEqualTo(Proxy.Type.HTTP);
+        
assertThat(proxy.selector().select(URI.create("https://nexus.lan/osv/all.zip";)))
+                .containsExactly(Proxy.NO_PROXY);
+
+        HttpProxy all = new HttpProxy("proxy", 8080, null, null, List.of("*"));
+        assertThat(all.bypasses("api.osv.dev")).isTrue();
+    }
+}
diff --git 
a/catalog/camel-catalog-cve/src/test/java/org/apache/camel/catalog/cve/OsvClientProxyTest.java
 
b/catalog/camel-catalog-cve/src/test/java/org/apache/camel/catalog/cve/OsvClientProxyTest.java
new file mode 100644
index 000000000000..6d1ed603e9e7
--- /dev/null
+++ 
b/catalog/camel-catalog-cve/src/test/java/org/apache/camel/catalog/cve/OsvClientProxyTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.cve;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-27342: the OSV.dev client logs in to a proxy with Basic 
authentication when it tunnels HTTPS through it, which
+ * the JDK disables by default. A fake proxy asks for the login, records the 
CONNECT requests and then refuses the
+ * tunnel, so no request leaves the machine.
+ */
+class OsvClientProxyTest {
+
+    private ServerSocket server;
+    private final List<String> connects = new CopyOnWriteArrayList<>();
+    private final List<String> logins = new CopyOnWriteArrayList<>();
+
+    @BeforeEach
+    void startProxy() throws IOException {
+        server = new ServerSocket(0, 10, InetAddress.getLoopbackAddress());
+        Thread t = new Thread(this::serve, "fake-proxy");
+        t.setDaemon(true);
+        t.start();
+    }
+
+    @AfterEach
+    void stopProxy() throws IOException {
+        server.close();
+    }
+
+    private void serve() {
+        while (!server.isClosed()) {
+            try (Socket s = server.accept()) {
+                s.setSoTimeout(5000);
+                BufferedReader in = new BufferedReader(new 
InputStreamReader(s.getInputStream(), StandardCharsets.ISO_8859_1));
+                String requestLine = in.readLine();
+                String login = null;
+                for (String line = in.readLine(); line != null && 
!line.isEmpty(); line = in.readLine()) {
+                    if (line.regionMatches(true, 0, "Proxy-Authorization:", 0, 
20)) {
+                        login = line.substring(20).trim();
+                    }
+                }
+                connects.add(requestLine);
+                OutputStream out = s.getOutputStream();
+                if (login == null) {
+                    out.write(("HTTP/1.1 407 Proxy Authentication Required\r\n"
+                               + "Proxy-Authenticate: Basic realm=\"corp\"\r\n"
+                               + "Content-Length: 0\r\n\r\n")
+                            .getBytes(StandardCharsets.ISO_8859_1));
+                } else {
+                    logins.add(login);
+                    out.write("HTTP/1.1 403 Forbidden\r\nContent-Length: 
0\r\nConnection: close\r\n\r\n"
+                            .getBytes(StandardCharsets.ISO_8859_1));
+                }
+                out.flush();
+            } catch (IOException e) {
+                // the server is closed, or the client went away
+            }
+        }
+    }
+
+    @Test
+    void logsInToTheProxyOfTheHttpsTunnel() {
+        HttpProxy proxy = new HttpProxy("127.0.0.1", server.getLocalPort(), 
"scott", "tiger", List.of());
+        OsvClient osv = new OsvClient(proxy);
+
+        osv.queryBatch(List.of(new Dependency("org.yaml", "snakeyaml", 
"1.33")));
+
+        assertThat(connects).isNotEmpty().allMatch(r -> r.startsWith("CONNECT 
api.osv.dev:443 "));
+        assertThat(logins)
+                .contains("Basic " + 
Base64.getEncoder().encodeToString("scott:tiger".getBytes(StandardCharsets.UTF_8)));
+        assertThat(osv.lastError()).contains("through the proxy 
[email protected]:" + server.getLocalPort());
+    }
+}
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
index ffd11c5ca330..98f4b2690c46 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
@@ -269,6 +269,19 @@ The command exits with 1 when it finds a vulnerability of 
the `--fail-on` severi
 CI job fails; `--fail-on=none` always exits with 0. The CVE Audit screen of 
the xref:camel-jbang-tui.adoc[Camel TUI]
 shows the same for a running integration, and explains a vulnerability with AI.
 
+The command reaches OSV.dev through a proxy, which is taken from, in order:
+
+. the active proxy of the Maven settings: `~/.m2/settings.xml`, or the file of 
`--maven-settings`, with its username,
+  its password (encrypted with `settings-security.xml` or not) and its 
`nonProxyHosts`;
+. the `HTTPS_PROXY` (or `HTTP_PROXY`) and `NO_PROXY` environment variables, as 
CI runners set them, such as
+  `HTTPS_PROXY=http://user:[email protected]:3128`;
+. the proxy settings of the JVM, such as 
`JAVA_OPTS="-Dhttps.proxyHost=proxy.corp.com -Dhttps.proxyPort=3128"`.
+
+The JDK does not send a username and password to a proxy with Basic 
authentication when it tunnels HTTPS through it
+(`jdk.http.auth.tunneling.disabledSchemes=Basic`); the command allows it when 
the proxy has a username, unless the
+property is set already. When OSV.dev cannot be reached, the command checks 
the Apache Camel security advisories only,
+and says why.
+
 === Copying dependency JARs
 
 Copy required JARs to a folder (defaults to `lib/`). The dependencies are 
resolved together, as one dependency graph,
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-settings.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-settings.adoc
index 54078016fff7..7659e6910d3b 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-settings.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-tui-settings.adoc
@@ -219,8 +219,10 @@ what you change lasts for that session only, so your own 
settings are left as th
 
 | Proxy Host | `camel.tui.proxyHost`
 | HTTP proxy for the TUI's own lookups, such as the
-  xref:camel-jbang-tui-observe.adoc#_cve_audit[CVE Audit] queries to OSV.dev. 
When empty, the JVM
-  default proxy settings are used.
+  xref:camel-jbang-tui-observe.adoc#_cve_audit[CVE Audit] queries to OSV.dev. 
When empty, the active proxy of the
+  Maven settings (`~/.m2/settings.xml`) is used, with its username and 
password, else the `HTTPS_PROXY` and
+  `NO_PROXY` environment variables, else the JVM default proxy settings. A 
proxy that needs a login is set in the Maven
+  settings or in `HTTPS_PROXY`, not here, so no password is kept in the TUI 
settings.
 |
 
 | Proxy Port | `camel.tui.proxyPort`
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyAudit.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyAudit.java
index 2e2b7eac38ce..2e3131103903 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyAudit.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyAudit.java
@@ -41,12 +41,14 @@ import org.apache.camel.catalog.cve.CveFinding;
 import org.apache.camel.catalog.cve.CveScan;
 import org.apache.camel.catalog.cve.CvssScore;
 import org.apache.camel.catalog.cve.Dependency;
+import org.apache.camel.catalog.cve.HttpProxy;
 import org.apache.camel.catalog.cve.OsvClient;
 import org.apache.camel.dsl.jbang.core.commands.ai.RouteComponents;
 import org.apache.camel.dsl.jbang.core.common.ActionClient;
 import org.apache.camel.dsl.jbang.core.common.CliException;
 import org.apache.camel.dsl.jbang.core.common.CliExitCode;
 import org.apache.camel.dsl.jbang.core.common.JsonOutput;
+import org.apache.camel.dsl.jbang.core.common.OsvProxy;
 import org.apache.camel.dsl.jbang.core.common.ProcessFinder;
 import org.apache.camel.tooling.maven.MavenArtifact;
 import org.apache.camel.tooling.maven.MavenDownloaderImpl;
@@ -141,10 +143,14 @@ public class DependencyAudit extends DependencyList {
         }
         List<Dependency> deps = new ArrayList<>();
         Map<String, Path> jars = new HashMap<>();
+        HttpProxy proxy = null;
         if (!gavs.isEmpty()) {
             boolean snapshot = gavs.stream().anyMatch(g -> 
g.contains("SNAPSHOT"));
             try (MavenDownloaderImpl downloader = new MavenDownloaderImpl()) {
+                downloader.setMavenSettingsLocation(mavenSettings);
+                
downloader.setMavenSettingsSecurityLocation(mavenSettingsSecurity);
                 downloader.build();
+                proxy = offline ? null : OsvProxy.resolve(downloader, 
System.getenv());
                 for (MavenArtifact ma : downloader.resolveArtifacts(gavs, 
Set.of(), true, snapshot)) {
                     MavenGav g = ma.getGav();
                     if (g.getVersion() == null || skipArtifact(g.getGroupId(), 
g.getArtifactId(), g.getVersion())) {
@@ -157,9 +163,12 @@ public class DependencyAudit extends DependencyList {
                 }
             }
         }
+        if (proxy == null && !offline) {
+            proxy = OsvProxy.resolve(mavenSettings, mavenSettingsSecurity, 
System.getenv());
+        }
         CamelCatalog catalog = new DefaultCamelCatalog();
         return report("project", deps, CveAudit.audit(deps, jars, declared, 
Map.of(), routeComponents(catalog),
-                catalog, offline ? null : new OsvClient()));
+                catalog, offline ? null : new OsvClient(proxy)));
     }
 
     /** The classpath of a running integration, and the components of its 
endpoints. */
@@ -187,7 +196,8 @@ public class DependencyAudit extends DependencyList {
         String name = process.name() != null && !process.name().contains(" ")
                 ? process.name() + " (" + process.pid() + ")" : 
String.valueOf(process.pid());
         return report("integration " + name, deps, CveAudit.audit(deps, jars, 
declaredDependencies(process.status()),
-                Map.of(), endpointComponents(process.status()), catalog, 
offline ? null : new OsvClient()));
+                Map.of(), endpointComponents(process.status()), catalog,
+                offline ? null : new OsvClient(OsvProxy.resolve(mavenSettings, 
mavenSettingsSecurity, System.getenv()))));
     }
 
     /** The components the routes of the project files use; null when there 
are no route files. */
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/OsvProxy.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/OsvProxy.java
new file mode 100644
index 000000000000..2cd5a9ee8e4c
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/OsvProxy.java
@@ -0,0 +1,64 @@
+/*
+ * 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.dsl.jbang.core.common;
+
+import java.util.Map;
+
+import org.apache.camel.catalog.cve.HttpProxy;
+import org.apache.camel.catalog.cve.OsvClient;
+import org.apache.camel.tooling.maven.MavenDownloaderImpl;
+import org.apache.camel.tooling.maven.MavenProxy;
+
+/**
+ * The proxy the CVE audit reaches OSV.dev through (CAMEL-27342): the active 
proxy of the Maven settings
+ * ({@code ~/.m2/settings.xml} or {@code --maven-settings}, with its username, 
its password decrypted with the
+ * settings-security.xml and its nonProxyHosts), else the {@code HTTPS_PROXY} 
/ {@code NO_PROXY} environment variables
+ * of a CI runner, else null for the proxy settings of the JVM ({@code 
-Dhttps.proxyHost}).
+ */
+public final class OsvProxy {
+
+    private OsvProxy() {
+    }
+
+    /** The proxy, from the Maven settings of a built downloader, else from 
the environment. */
+    public static HttpProxy resolve(MavenDownloaderImpl downloader, 
Map<String, String> env) {
+        MavenProxy maven = downloader != null ? 
downloader.proxyFor(OsvClient.API_URL) : null;
+        if (maven != null) {
+            // with the nonProxyHosts: the TUI fetches other URLs (the 
documentation) through the same proxy
+            return new HttpProxy(
+                    maven.host(), maven.port(), maven.username(), 
maven.password(),
+                    HttpProxy.splitHosts(maven.nonProxyHosts()));
+        }
+        return HttpProxy.fromEnvironment(env);
+    }
+
+    /**
+     * The proxy, from the given Maven settings (null for {@code 
~/.m2/settings.xml}, {@code false} for none), else from
+     * the environment. Only the settings are read: nothing is downloaded.
+     */
+    public static HttpProxy resolve(String mavenSettings, String 
mavenSettingsSecurity, Map<String, String> env) {
+        try (MavenDownloaderImpl downloader = new MavenDownloaderImpl()) {
+            downloader.setMavenSettingsLocation(mavenSettings);
+            downloader.setMavenSettingsSecurityLocation(mavenSettingsSecurity);
+            downloader.build();
+            return resolve(downloader, env);
+        } catch (Exception e) {
+            // unreadable settings: as without them
+            return HttpProxy.fromEnvironment(env);
+        }
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/OsvProxyTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/OsvProxyTest.java
new file mode 100644
index 000000000000..d77f9582386e
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/common/OsvProxyTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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.dsl.jbang.core.common;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.catalog.cve.HttpProxy;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-27342: the proxy of the CVE audit is the one of the Maven settings, 
else the one of HTTPS_PROXY.
+ */
+class OsvProxyTest {
+
+    @TempDir
+    Path dir;
+
+    @Test
+    void theMavenSettingsComeFirst() throws Exception {
+        Path settings = dir.resolve("settings.xml");
+        Files.writeString(settings, """
+                <settings>
+                  <localRepository>%s</localRepository>
+                  <proxies>
+                    <proxy>
+                      <id>corp</id>
+                      <active>true</active>
+                      <protocol>http</protocol>
+                      <host>proxy.corp.com</host>
+                      <port>3128</port>
+                      <username>scott</username>
+                      <password>tiger</password>
+                      <nonProxyHosts>localhost|*.corp.com</nonProxyHosts>
+                    </proxy>
+                  </proxies>
+                </settings>
+                """.formatted(dir.resolve("repo")));
+
+        HttpProxy proxy = OsvProxy.resolve(settings.toString(), null, 
Map.of("HTTPS_PROXY", "http://ci:8080";));
+
+        assertThat(proxy).isEqualTo(
+                new HttpProxy("proxy.corp.com", 3128, "scott", "tiger", 
List.of("localhost", "*.corp.com")));
+        // a URL other than OSV.dev, such as the documentation of the TUI, 
keeps the nonProxyHosts of the settings
+        assertThat(proxy.bypasses("nexus.corp.com")).isTrue();
+        assertThat(proxy.bypasses("camel.apache.org")).isFalse();
+    }
+
+    @Test
+    void elseTheEnvironment() {
+        HttpProxy proxy = OsvProxy.resolve("false", null, 
Map.of("HTTPS_PROXY", "http://ci:8080";, "NO_PROXY", "localhost"));
+
+        assertThat(proxy).isEqualTo(new HttpProxy("ci", 8080, null, null, 
List.of("localhost")));
+        assertThat(OsvProxy.resolve("false", null, Map.of())).isNull();
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CveAuditTab.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CveAuditTab.java
index 7a0fe8bdef04..053bb12db682 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CveAuditTab.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/CveAuditTab.java
@@ -66,7 +66,6 @@ import static 
org.apache.camel.dsl.jbang.core.commands.tui.TuiHelper.*;
  */
 class CveAuditTab extends AbstractTableTab {
 
-    private final OsvClient osvClient = new 
OsvClient(TuiSettings.proxySelector());
     private final AtomicBoolean loading = new AtomicBoolean(false);
     private final FilterField filter = new FilterField(this::filterChanged);
 
@@ -542,7 +541,7 @@ class CveAuditTab extends AbstractTableTab {
         if (loading.get()) {
             return;
         }
-        osvClient.clearCache(depEntries);
+        OsvClient.clearCache(depEntries);
         allGroups = Collections.emptyList();
         allRows = Collections.emptyList();
         dataLoaded = false;
@@ -597,7 +596,9 @@ class CveAuditTab extends AbstractTableTab {
         List<Dependency> deps = allDeps.stream()
                 .map(d -> new Dependency(d.groupId(), d.artifactId(), 
d.version())).toList();
         CveAudit.Result result = CveAudit.audit(deps, jars, 
declaredDependencies(info), fallbackVia,
-                endpointComponents(current != null ? current : info), 
ProjectOverviewAssist.catalog(), osvClient);
+                endpointComponents(current != null ? current : info), 
ProjectOverviewAssist.catalog(),
+                // the proxy is looked up for each scan, so a change in the 
settings applies without a restart
+                new OsvClient(TuiSettings.httpProxy()));
         applyResult(deps, result.findings(), null, result.osvError());
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DocHelper.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DocHelper.java
index 73a1425c6888..3d43454699ce 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DocHelper.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/DocHelper.java
@@ -18,6 +18,7 @@ package org.apache.camel.dsl.jbang.core.commands.tui;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.ProxySelector;
 import java.net.URI;
 import java.net.http.HttpClient;
 import java.net.http.HttpRequest;
@@ -27,6 +28,7 @@ import java.time.Duration;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.camel.catalog.cve.HttpProxy;
 import org.apache.camel.dsl.jbang.core.common.ExampleHelper;
 
 final class DocHelper {
@@ -86,10 +88,14 @@ final class DocHelper {
 
     static String downloadContent(String url) {
         try {
-            HttpClient client = HttpClient.newBuilder()
+            HttpProxy proxy = TuiSettings.httpProxy();
+            HttpClient.Builder builder = HttpClient.newBuilder()
                     .connectTimeout(Duration.ofSeconds(5))
-                    .proxy(TuiSettings.proxySelector())
-                    .build();
+                    .proxy(proxy != null ? proxy.selector() : 
ProxySelector.getDefault());
+            if (proxy != null && proxy.authenticator() != null) {
+                builder.authenticator(proxy.authenticator());
+            }
+            HttpClient client = builder.build();
             HttpRequest request = HttpRequest.newBuilder()
                     .uri(URI.create(url))
                     .timeout(Duration.ofSeconds(10))
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiSettings.java
 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiSettings.java
index a95d1975a69a..976602d5e6a8 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiSettings.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/TuiSettings.java
@@ -16,8 +16,8 @@
  */
 package org.apache.camel.dsl.jbang.core.commands.tui;
 
-import java.net.InetSocketAddress;
-import java.net.ProxySelector;
+import org.apache.camel.catalog.cve.HttpProxy;
+import org.apache.camel.dsl.jbang.core.common.OsvProxy;
 
 /**
  * User-facing preferences for the Camel TUI, persisted under {@code 
camel.tui.*} keys in the CLI user configuration
@@ -363,10 +363,16 @@ final class TuiSettings {
         }
     }
 
+    // the proxy of the Maven settings or of HTTPS_PROXY, looked up once: 
reading the settings builds a resolver session
+    private static HttpProxy fallbackProxy;
+    private static boolean fallbackResolved;
+
     /**
-     * Returns a {@link ProxySelector} based on the configured proxy settings, 
falling back to the JVM default.
+     * The proxy to reach the internet through (OSV.dev of the CVE Audit 
screen, the documentation): the Proxy Host and
+     * Proxy Port of the settings, else the active proxy of the Maven settings 
({@code ~/.m2/settings.xml}, with its
+     * username and password), else {@code HTTPS_PROXY}; null for the proxy 
settings of the JVM.
      */
-    static ProxySelector proxySelector() {
+    static HttpProxy httpProxy() {
         TuiSettings s = load();
         String host = s.getProxyHost();
         if (host != null && !host.isEmpty()) {
@@ -379,9 +385,17 @@ final class TuiSettings {
                     // use default port
                 }
             }
-            return ProxySelector.of(new InetSocketAddress(host, port));
+            return new HttpProxy(host, port);
+        }
+        return fallbackProxy();
+    }
+
+    private static synchronized HttpProxy fallbackProxy() {
+        if (!fallbackResolved) {
+            fallbackProxy = OsvProxy.resolve(null, null, System.getenv());
+            fallbackResolved = true;
         }
-        return ProxySelector.getDefault();
+        return fallbackProxy;
     }
 
     private static String trimToNull(String value) {
diff --git 
a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java
 
b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java
index 30a3d5bda2e3..e183f242e201 100644
--- 
a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java
+++ 
b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenDownloaderImpl.java
@@ -73,8 +73,10 @@ import org.eclipse.aether.collection.DependencySelector;
 import org.eclipse.aether.graph.Dependency;
 import org.eclipse.aether.graph.DependencyFilter;
 import org.eclipse.aether.metadata.DefaultMetadata;
+import org.eclipse.aether.repository.AuthenticationContext;
 import org.eclipse.aether.repository.LocalRepository;
 import org.eclipse.aether.repository.LocalRepositoryManager;
+import org.eclipse.aether.repository.Proxy;
 import org.eclipse.aether.repository.RemoteRepository;
 import org.eclipse.aether.repository.RepositoryPolicy;
 import org.eclipse.aether.resolution.ArtifactDescriptorException;
@@ -1168,6 +1170,49 @@ public class MavenDownloaderImpl extends ServiceSupport 
implements MavenDownload
         }
     }
 
+    /**
+     * The proxy of the Maven settings ({@code settings.xml}, or the session 
of the Maven build in embedded mode) to
+     * reach the given URL through, such as {@code https://api.osv.dev/}, with 
its username and password; null when the
+     * URL is reached directly (no active proxy, or the host is one of its 
{@code nonProxyHosts}). The answer carries
+     * the {@code nonProxyHosts} too, for a client that reaches other URLs 
through the same proxy. Call after
+     * {@link #build()}.
+     */
+    public MavenProxy proxyFor(String url) {
+        if (repositorySystemSession == null || 
repositorySystemSession.getProxySelector() == null) {
+            return null;
+        }
+        RemoteRepository repository = new 
RemoteRepository.Builder("proxy-lookup", "default", url).build();
+        Proxy proxy = 
repositorySystemSession.getProxySelector().getProxy(repository);
+        if (proxy == null) {
+            return null;
+        }
+        String username = null;
+        String password = null;
+        if (proxy.getAuthentication() != null) {
+            RemoteRepository proxied = new 
RemoteRepository.Builder(repository).setProxy(proxy).build();
+            try (AuthenticationContext context = 
AuthenticationContext.forProxy(repositorySystemSession, proxied)) {
+                if (context != null) {
+                    username = context.get(AuthenticationContext.USERNAME);
+                    password = context.get(AuthenticationContext.PASSWORD);
+                }
+            }
+        }
+        return new MavenProxy(proxy.getHost(), proxy.getPort(), username, 
password, nonProxyHosts(proxy));
+    }
+
+    // the nonProxyHosts of the active proxy of the settings: the proxy of the 
session does not expose them
+    private String nonProxyHosts(Proxy proxy) {
+        if (mimaContext != null && mimaContext.httpProxy() != null
+                && 
proxy.getHost().equalsIgnoreCase(mimaContext.httpProxy().getHost())) {
+            return mimaContext.httpProxy().getNonProxyHosts();
+        }
+        if (settings != null && settings.getActiveProxy() != null
+                && 
proxy.getHost().equalsIgnoreCase(settings.getActiveProxy().getHost())) {
+            return settings.getActiveProxy().getNonProxyHosts();
+        }
+        return null;
+    }
+
     // ========== Configuration Methods ==========
 
     @Override
diff --git 
a/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenProxy.java
 
b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenProxy.java
new file mode 100644
index 000000000000..28dbc401d75a
--- /dev/null
+++ 
b/tooling/camel-tooling-maven/src/main/java/org/apache/camel/tooling/maven/MavenProxy.java
@@ -0,0 +1,37 @@
+/*
+ * 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.tooling.maven;
+
+/**
+ * The proxy of the Maven settings to reach a URL through, with the username 
and password of the proxy (decrypted with
+ * the settings-security.xml), or null ones when it needs no login, and the 
hosts to reach without it.
+ *
+ * @param host          the host of the proxy
+ * @param port          the port of the proxy
+ * @param username      the username, or null
+ * @param password      the password, or null
+ * @param nonProxyHosts the {@code nonProxyHosts} of the proxy as the settings 
write them
+ *                      ({@code localhost|*.corp.com}), or null
+ */
+public record MavenProxy(String host, int port, String username, String 
password, String nonProxyHosts) {
+
+    /** The proxy as {@code host:port}, without the password. */
+    @Override
+    public String toString() {
+        return (username != null ? username + "@" : "") + host + ":" + port;
+    }
+}
diff --git 
a/tooling/camel-tooling-maven/src/test/java/org/apache/camel/tooling/maven/MavenDownloaderProxyTest.java
 
b/tooling/camel-tooling-maven/src/test/java/org/apache/camel/tooling/maven/MavenDownloaderProxyTest.java
new file mode 100644
index 000000000000..06857529addd
--- /dev/null
+++ 
b/tooling/camel-tooling-maven/src/test/java/org/apache/camel/tooling/maven/MavenDownloaderProxyTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.tooling.maven;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * CAMEL-27342: the proxy of the Maven settings for a URL, such as OSV.dev of 
the CVE audit.
+ */
+public class MavenDownloaderProxyTest {
+
+    @TempDir
+    Path dir;
+
+    @Test
+    void proxyOfTheSettings() throws Exception {
+        Path settings = dir.resolve("settings.xml");
+        Files.writeString(settings, """
+                <settings>
+                  <localRepository>%s</localRepository>
+                  <proxies>
+                    <proxy>
+                      <id>corp</id>
+                      <active>true</active>
+                      <protocol>http</protocol>
+                      <host>proxy.corp.com</host>
+                      <port>3128</port>
+                      <username>scott</username>
+                      <password>tiger</password>
+                      <nonProxyHosts>localhost|*.corp.com</nonProxyHosts>
+                    </proxy>
+                  </proxies>
+                </settings>
+                """.formatted(dir.resolve("repo")));
+        try (MavenDownloaderImpl downloader = new MavenDownloaderImpl()) {
+            downloader.setMavenSettingsLocation(settings.toString());
+            downloader.setOffline(true);
+            downloader.build();
+
+            MavenProxy proxy = downloader.proxyFor("https://api.osv.dev/";);
+            assertEquals("proxy.corp.com", proxy.host());
+            assertEquals(3128, proxy.port());
+            assertEquals("scott", proxy.username());
+            assertEquals("tiger", proxy.password());
+            assertEquals("[email protected]:3128", proxy.toString());
+            assertEquals("localhost|*.corp.com", proxy.nonProxyHosts());
+
+            // the hosts of nonProxyHosts are reached directly
+            
assertNull(downloader.proxyFor("https://nexus.corp.com/repository/osv/";));
+        }
+    }
+
+    @Test
+    void noProxyWithoutSettings() throws Exception {
+        try (MavenDownloaderImpl downloader = new MavenDownloaderImpl()) {
+            downloader.setMavenSettingsLocation("false");
+            downloader.setOffline(true);
+            downloader.build();
+
+            assertNull(downloader.proxyFor("https://api.osv.dev/";));
+        }
+    }
+}

Reply via email to