You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/09/03 16:32:48 UTC

(maven-wagon) 02/04: BasicAuthScope: map realm=ANY to AuthScope.ANY_REALM

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

slachiewicz pushed a commit to branch wagon-3.x
in repository https://gitbox.apache.org/repos/asf/maven-wagon.git

commit 627d7d9b43ef6beca966ee8201b13601af489731
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Thu Sep 3 18:27:30 2026 +0200

    BasicAuthScope: map realm=ANY to AuthScope.ANY_REALM
    
    When realm is configured as "ANY", map to AuthScope.ANY_REALM instead of
    the literal string "ANY", consistent with host and port handling.
    
    Fixes #910.
---
 .../org/apache/maven/wagon/shared/http/BasicAuthScope.java | 14 +++++---------
 .../maven/wagon/providers/http/BasicAuthScopeTest.java     | 13 +++++++++++++
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/BasicAuthScope.java b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/BasicAuthScope.java
index b7899957..12d0e02f 100644
--- a/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/BasicAuthScope.java
+++ b/wagon-providers/wagon-http-shared/src/main/java/org/apache/maven/wagon/shared/http/BasicAuthScope.java
@@ -67,15 +67,11 @@ public void setRealm(String realm) {
      * them: {@code basicAuth} for the target host and {@code proxyAuth} for the proxy, settable
      * through {@code setBasicAuthScope} and {@code setProxyBasicAuthScope} respectively.
      * <p>
-     * A non-null {@link #getHost() host} or {@link #getPort() port} replaces the value passed
-     * in; the literal string {@code "ANY"} selects {@link AuthScope#ANY_HOST} or
-     * {@link AuthScope#ANY_PORT}. A passed-in port of {@code -1} also yields
-     * {@link AuthScope#ANY_PORT}. When host, port and realm are all {@code "ANY"},
+     * A non-null {@link #getHost() host}, {@link #getPort() port}, or {@link #getRealm() realm} replaces the value passed
+     * in; the literal string {@code "ANY"} selects {@link AuthScope#ANY_HOST}, {@link AuthScope#ANY_PORT}, or
+     * {@link AuthScope#ANY_REALM}. A passed-in port of {@code -1} also yields {@link AuthScope#ANY_PORT}. Leaving
+     * realm unset yields {@link AuthScope#ANY_REALM}. When host, port and realm are all {@code "ANY"},
      * {@link AuthScope#ANY} is returned.
-     * <p>
-     * {@link #getRealm() realm} does not follow that pattern. Leaving it unset yields
-     * {@link AuthScope#ANY_REALM}; any non-null value is used verbatim as the realm to match,
-     * including {@code "ANY"} itself unless host and port are {@code "ANY"} as well.
      *
      * @param host the host to scope credentials to, before any override is applied
      * @param port the port to scope credentials to, before any override is applied; -1 means
@@ -117,7 +113,7 @@ && getRealm() != null //
             if ("ANY".compareTo(getRealm()) != 0) {
                 scopeRealm = getRealm();
             } else {
-                scopeRealm = getRealm();
+                scopeRealm = AuthScope.ANY_REALM;
             }
         }
 
diff --git a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
index 1512eeb3..6d331d57 100644
--- a/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
+++ b/wagon-providers/wagon-http/src/test/java/org/apache/maven/wagon/providers/http/BasicAuthScopeTest.java
@@ -83,6 +83,19 @@ public void testGetScopeRealmOverridden() {
         assertEquals("override-realm", authScope.getRealm());
     }
 
+    /**
+     * Test AuthScope override with realm="ANY" only, which should result in AuthScope.ANY_REALM.
+     */
+    @Test
+    public void testGetScopeRealmAnyOnly() {
+        BasicAuthScope scope = new BasicAuthScope();
+        scope.setRealm("ANY");
+        AuthScope authScope = scope.getScope("original.host.com", 3456);
+        assertEquals("original.host.com", authScope.getHost());
+        assertEquals(3456, authScope.getPort());
+        assertEquals(AuthScope.ANY_REALM, authScope.getRealm());
+    }
+
     /**
      * Test AuthScope where original port is -1, which should result in ANY
      */