You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2022/11/26 22:14:57 UTC

[httpcomponents-client] branch bearer_auth_support updated (dfc491492 -> 448c36022)

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

olegk pushed a change to branch bearer_auth_support
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


 discard dfc491492 Credentials should be different types of user credentials including token based with no password
     new 5633bd9cb Credentials should be different types of user credentials including token based with no password
     new e260e9c8a Removed references in specific RFCs
     new 448c36022 Normalize scheme name in AuthScope

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (dfc491492)
            \
             N -- N -- N   refs/heads/bearer_auth_support (448c36022)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/hc/client5/http/auth/AuthScope.java  | 16 +++++-----------
 .../apache/hc/client5/http/auth/StandardAuthScheme.java  |  6 +++---
 .../client5/http/auth/UsernamePasswordCredentials.java   |  3 +++
 .../apache/hc/client5/http/impl/auth/BasicScheme.java    |  2 +-
 .../apache/hc/client5/http/impl/auth/DigestScheme.java   |  5 ++---
 .../org/apache/hc/client5/http/auth/TestAuthScope.java   |  4 ++--
 .../impl/auth/TestSystemDefaultCredentialsProvider.java  | 16 ++++++++++------
 7 files changed, 26 insertions(+), 26 deletions(-)


[httpcomponents-client] 02/03: Removed references in specific RFCs

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch bearer_auth_support
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit e260e9c8aa531d89f092e908fc59a86010cc85e4
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Nov 26 23:07:30 2022 +0100

    Removed references in specific RFCs
---
 .../java/org/apache/hc/client5/http/auth/StandardAuthScheme.java    | 6 +++---
 .../main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java | 2 +-
 .../java/org/apache/hc/client5/http/impl/auth/DigestScheme.java     | 5 ++---
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/StandardAuthScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/StandardAuthScheme.java
index feb7e6c51..51371cc7b 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/StandardAuthScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/StandardAuthScheme.java
@@ -39,13 +39,13 @@ public final class StandardAuthScheme {
     }
 
     /**
-     * Basic authentication scheme as defined in RFC 2617 (considered inherently
-     * insecure without transport encryption, but most widely supported).
+     * Basic authentication scheme (considered inherently insecure without transport encryption,
+     * but most widely supported).
      */
     public static final String BASIC = "Basic";
 
     /**
-     * Digest authentication scheme as defined in RFC 2617.
+     * Digest authentication scheme.
      */
     public static final String DIGEST = "Digest";
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
index d6d0d027c..03bf73e45 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
@@ -61,7 +61,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Basic authentication scheme as defined in RFC 2617.
+ * Basic authentication scheme.
  *
  * @since 4.0
  */
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
index f73f59055..fb8b97d92 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
@@ -71,7 +71,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Digest authentication scheme as defined in RFC 2617.
+ * Digest authentication scheme.
  * Both MD5 (default) and MD5-sess are supported.
  * Currently only qop=auth or no qop is supported. qop=auth-int
  * is unsupported. If auth and auth-int are provided, auth is
@@ -443,8 +443,7 @@ public class DigestScheme implements AuthScheme, Serializable {
     }
 
     /**
-     * Encodes the 128 bit (16 bytes) MD5 digest into a 32 characters long
-     * {@code String} according to RFC 2617.
+     * Encodes the 128 bit (16 bytes) MD5 digest into a 32 characters long string.
      *
      * @param binaryData array containing the digest
      * @return encoded MD5, or {@code null} if encoding failed


[httpcomponents-client] 03/03: Normalize scheme name in AuthScope

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch bearer_auth_support
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 448c360226e6f505389889b82e7d2aef30fb87de
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Nov 26 23:12:59 2022 +0100

    Normalize scheme name in AuthScope
---
 .../java/org/apache/hc/client5/http/auth/AuthScope.java  | 16 +++++-----------
 .../org/apache/hc/client5/http/auth/TestAuthScope.java   |  4 ++--
 .../impl/auth/TestSystemDefaultCredentialsProvider.java  | 16 ++++++++++------
 3 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthScope.java b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthScope.java
index 312e5b861..35c309b3c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthScope.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/AuthScope.java
@@ -76,7 +76,7 @@ public class AuthScope {
         this.host = host != null ? host.toLowerCase(Locale.ROOT) : null;
         this.port = port >= 0 ? port: -1;
         this.realm = realm;
-        this.schemeName = schemeName;
+        this.schemeName = schemeName != null ? schemeName.toUpperCase(Locale.ROOT) : null;
     }
 
     /**
@@ -99,7 +99,7 @@ public class AuthScope {
         this.host = origin.getHostName().toLowerCase(Locale.ROOT);
         this.port = origin.getPort() >= 0 ? origin.getPort() : -1;
         this.realm = realm;
-        this.schemeName = schemeName;
+        this.schemeName = schemeName != null ? schemeName.toUpperCase(Locale.ROOT) : null;
     }
 
     /**
@@ -167,8 +167,7 @@ public class AuthScope {
      */
     public int match(final AuthScope that) {
         int factor = 0;
-        if (Objects.equals(toNullSafeLowerCase(this.schemeName),
-                             toNullSafeLowerCase(that.schemeName))) {
+        if (Objects.equals(this.schemeName, that.schemeName)) {
             factor += 1;
         } else {
             if (this.schemeName != null && that.schemeName != null) {
@@ -217,8 +216,7 @@ public class AuthScope {
                     && Objects.equals(this.host, that.host)
                     && this.port == that.port
                     && Objects.equals(this.realm, that.realm)
-                    && Objects.equals(toNullSafeLowerCase(this.schemeName),
-                                        toNullSafeLowerCase(that.schemeName));
+                    && Objects.equals(this.schemeName, that.schemeName);
         }
         return false;
     }
@@ -230,14 +228,10 @@ public class AuthScope {
         hash = LangUtils.hashCode(hash, this.host);
         hash = LangUtils.hashCode(hash, this.port);
         hash = LangUtils.hashCode(hash, this.realm);
-        hash = LangUtils.hashCode(hash, toNullSafeLowerCase(this.schemeName));
+        hash = LangUtils.hashCode(hash, this.schemeName);
         return hash;
     }
 
-    private String toNullSafeLowerCase(final String str) {
-        return str != null ? str.toLowerCase(Locale.ROOT) : null;
-    }
-
     @Override
     public String toString() {
         final StringBuilder buffer = new StringBuilder();
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestAuthScope.java b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestAuthScope.java
index 61a68a8fe..b7b72b7b4 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestAuthScope.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestAuthScope.java
@@ -38,12 +38,12 @@ public class TestAuthScope {
     @Test
     public void testBasics() {
         final AuthScope authscope = new AuthScope("http", "somehost", 80, "somerealm", "SomeScheme");
-        Assertions.assertEquals("SomeScheme", authscope.getSchemeName());
+        Assertions.assertEquals("SOMESCHEME", authscope.getSchemeName());
         Assertions.assertEquals("http", authscope.getProtocol());
         Assertions.assertEquals("somehost", authscope.getHost());
         Assertions.assertEquals(80, authscope.getPort());
         Assertions.assertEquals("somerealm", authscope.getRealm());
-        Assertions.assertEquals("SomeScheme 'somerealm' http://somehost:80", authscope.toString());
+        Assertions.assertEquals("SOMESCHEME 'somerealm' http://somehost:80", authscope.toString());
     }
 
     @Test
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java
index 265b4c980..d1fa6ca98 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java
@@ -31,6 +31,7 @@ import java.net.Authenticator.RequestorType;
 import java.net.InetAddress;
 import java.net.PasswordAuthentication;
 import java.net.URL;
+import java.util.Locale;
 
 import org.apache.hc.client5.http.auth.AuthScope;
 import org.apache.hc.client5.http.auth.Credentials;
@@ -99,9 +100,11 @@ public class TestSystemDefaultCredentialsProvider {
         final Credentials receivedCredentials =
             new SystemDefaultCredentialsProvider().getCredentials(authScope, coreContext);
 
-        Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1,
-                                                                        PROMPT1, StandardAuthScheme.BASIC, httpRequestUrl,
-                                                                        RequestorType.SERVER);
+        Mockito.verify(authenticatorDelegate).getPasswordAuthentication(
+                PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1,
+                PROMPT1, StandardAuthScheme.BASIC.toUpperCase(Locale.ROOT),
+                httpRequestUrl,
+                RequestorType.SERVER);
         Assertions.assertNotNull(receivedCredentials);
         Assertions.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName());
     }
@@ -116,9 +119,10 @@ public class TestSystemDefaultCredentialsProvider {
         final Credentials receivedCredentials =
             new SystemDefaultCredentialsProvider().getCredentials(authScope, null);
 
-        Mockito.verify(authenticatorDelegate).getPasswordAuthentication(PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1,
-                                                                        PROMPT1, StandardAuthScheme.BASIC, null,
-                                                                        RequestorType.SERVER);
+        Mockito.verify(authenticatorDelegate).getPasswordAuthentication(
+                PROXY_HOST1, null, PROXY_PORT1, PROXY_PROTOCOL1,
+                PROMPT1, StandardAuthScheme.BASIC.toUpperCase(Locale.ROOT), null,
+                RequestorType.SERVER);
         Assertions.assertNotNull(receivedCredentials);
         Assertions.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName());
     }


[httpcomponents-client] 01/03: Credentials should be different types of user credentials including token based with no password

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch bearer_auth_support
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit 5633bd9cb568de3d9a56a7980d8e6a50d5930cae
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Nov 26 18:28:36 2022 +0100

    Credentials should be different types of user credentials including token based with no password
---
 .../apache/hc/client5/http/auth/Credentials.java   |  5 ++++
 .../http/auth/UsernamePasswordCredentials.java     | 35 ++++++++++++++++++----
 .../hc/client5/http/impl/auth/BasicScheme.java     | 33 ++++++++------------
 .../hc/client5/http/impl/auth/DigestScheme.java    | 23 +++++++-------
 .../hc/client5/http/auth/TestCredentials.java      |  4 +--
 .../auth/TestSystemDefaultCredentialsProvider.java |  2 --
 6 files changed, 61 insertions(+), 41 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/Credentials.java b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/Credentials.java
index 742ba9e7b..491ee0072 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/Credentials.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/Credentials.java
@@ -39,6 +39,11 @@ public interface Credentials {
 
     Principal getUserPrincipal();
 
+    /**
+     * @deprecated Use specific credentials class that represent a username / password
+     * set of a security token.
+     */
+    @Deprecated
     char[] getPassword();
 
 }
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/UsernamePasswordCredentials.java b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/UsernamePasswordCredentials.java
index 54fd469bc..ecdb2a407 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/auth/UsernamePasswordCredentials.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/auth/UsernamePasswordCredentials.java
@@ -45,22 +45,36 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
 
     private static final long serialVersionUID = 243343858802739403L;
 
-    private final BasicUserPrincipal principal;
+    private final Principal principal;
     private final char[] password;
 
     /**
      * The constructor with the username and password arguments.
      *
-     * @param userName the user name
+     * @param userPrincipal the user principal
      * @param password the password
+     *
+     * @since 5.3
+     *
+     * @see BasicUserPrincipal
+     * @see NTUserPrincipal
      */
-    public UsernamePasswordCredentials(final String userName, final char[] password) {
+    public UsernamePasswordCredentials(final Principal userPrincipal, final char[] password) {
         super();
-        Args.notNull(userName, "Username");
-        this.principal = new BasicUserPrincipal(userName);
+        this.principal = Args.notNull(userPrincipal, "User principal");
         this.password = password;
     }
 
+    /**
+     * The constructor with the username and password arguments.
+     *
+     * @param userName the user name
+     * @param password the password
+     */
+    public UsernamePasswordCredentials(final String userName, final char[] password) {
+        this(new BasicUserPrincipal(userName), password);
+    }
+
     @Override
     public Principal getUserPrincipal() {
         return this.principal;
@@ -70,6 +84,17 @@ public class UsernamePasswordCredentials implements Credentials, Serializable {
         return this.principal.getName();
     }
 
+    /**
+     * @since 5.3
+     */
+    public char[] getUserPassword() {
+        return password;
+    }
+
+    /**
+     * @deprecated Use {@link #getUserPassword()}.
+     */
+    @Deprecated
     @Override
     public char[] getPassword() {
         return password;
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
index 87d11448c..d6d0d027c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/BasicScheme.java
@@ -39,7 +39,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.hc.client5.http.utils.Base64;
 import org.apache.hc.client5.http.auth.AuthChallenge;
 import org.apache.hc.client5.http.auth.AuthScheme;
 import org.apache.hc.client5.http.auth.AuthScope;
@@ -49,7 +48,9 @@ import org.apache.hc.client5.http.auth.Credentials;
 import org.apache.hc.client5.http.auth.CredentialsProvider;
 import org.apache.hc.client5.http.auth.MalformedChallengeException;
 import org.apache.hc.client5.http.auth.StandardAuthScheme;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.client5.http.utils.Base64;
 import org.apache.hc.client5.http.utils.ByteArrayBuilder;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
@@ -77,8 +78,7 @@ public class BasicScheme implements AuthScheme, Serializable {
     private transient Base64 base64codec;
     private boolean complete;
 
-    private String username;
-    private char[] password;
+    private UsernamePasswordCredentials credentials;
 
     /**
      * @since 4.3
@@ -93,21 +93,13 @@ public class BasicScheme implements AuthScheme, Serializable {
         this(StandardCharsets.US_ASCII);
     }
 
-    private void applyCredentials(final Credentials credentials) {
-        this.username = credentials.getUserPrincipal().getName();
-        this.password = credentials.getPassword();
-    }
-
-    private void clearCredentials() {
-        this.username = null;
-        this.password = null;
-    }
-
     public void initPreemptive(final Credentials credentials) {
         if (credentials != null) {
-            applyCredentials(credentials);
+            Args.check(credentials instanceof UsernamePasswordCredentials,
+                    "Unsupported credential type: " + credentials.getClass());
+            this.credentials = (UsernamePasswordCredentials) credentials;
         } else {
-            clearCredentials();
+            this.credentials = null;
         }
     }
 
@@ -157,8 +149,8 @@ public class BasicScheme implements AuthScheme, Serializable {
         final AuthScope authScope = new AuthScope(host, getRealm(), getName());
         final Credentials credentials = credentialsProvider.getCredentials(
                 authScope, context);
-        if (credentials != null) {
-            applyCredentials(credentials);
+        if (credentials instanceof UsernamePasswordCredentials) {
+            this.credentials = (UsernamePasswordCredentials) credentials;
             return true;
         }
 
@@ -167,7 +159,7 @@ public class BasicScheme implements AuthScheme, Serializable {
             final String exchangeId = clientContext.getExchangeId();
             LOG.debug("{} No credentials found for auth scope [{}]", exchangeId, authScope);
         }
-        clearCredentials();
+        this.credentials = null;
         return false;
     }
 
@@ -177,9 +169,10 @@ public class BasicScheme implements AuthScheme, Serializable {
     }
 
     private void validateUsername() throws AuthenticationException {
-        if (username == null) {
+        if (credentials == null) {
             throw new AuthenticationException("User credentials not set");
         }
+        final String username = credentials.getUserName();
         for (int i = 0; i < username.length(); i++) {
             final char ch = username.charAt(i);
             if (Character.isISOControl(ch)) {
@@ -204,7 +197,7 @@ public class BasicScheme implements AuthScheme, Serializable {
         }
         final Charset charset = AuthSchemeSupport.parseCharset(paramMap.get("charset"), defaultCharset);
         this.buffer.charset(charset);
-        this.buffer.append(this.username).append(":").append(this.password);
+        this.buffer.append(this.credentials.getUserName()).append(":").append(this.credentials.getUserPassword());
         if (this.base64codec == null) {
             this.base64codec = new Base64();
         }
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
index ff98ab36a..f73f59055 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/auth/DigestScheme.java
@@ -53,6 +53,7 @@ import org.apache.hc.client5.http.auth.Credentials;
 import org.apache.hc.client5.http.auth.CredentialsProvider;
 import org.apache.hc.client5.http.auth.MalformedChallengeException;
 import org.apache.hc.client5.http.auth.StandardAuthScheme;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
 import org.apache.hc.client5.http.utils.ByteArrayBuilder;
 import org.apache.hc.core5.annotation.Internal;
@@ -118,8 +119,7 @@ public class DigestScheme implements AuthScheme, Serializable {
     private byte[] a1;
     private byte[] a2;
 
-    private String username;
-    private char[] password;
+    private UsernamePasswordCredentials credentials;
 
     public DigestScheme() {
         this(StandardCharsets.ISO_8859_1);
@@ -133,8 +133,9 @@ public class DigestScheme implements AuthScheme, Serializable {
 
     public void initPreemptive(final Credentials credentials, final String cnonce, final String realm) {
         Args.notNull(credentials, "Credentials");
-        this.username = credentials.getUserPrincipal().getName();
-        this.password = credentials.getPassword();
+        Args.check(credentials instanceof UsernamePasswordCredentials,
+                "Unsupported credential type: " + credentials.getClass());
+        this.credentials = (UsernamePasswordCredentials) credentials;
         this.paramMap.put("cnonce", cnonce);
         this.paramMap.put("realm", realm);
     }
@@ -190,9 +191,8 @@ public class DigestScheme implements AuthScheme, Serializable {
         final AuthScope authScope = new AuthScope(host, getRealm(), getName());
         final Credentials credentials = credentialsProvider.getCredentials(
                 authScope, context);
-        if (credentials != null) {
-            this.username = credentials.getUserPrincipal().getName();
-            this.password = credentials.getPassword();
+        if (credentials instanceof UsernamePasswordCredentials) {
+            this.credentials = (UsernamePasswordCredentials) credentials;
             return true;
         }
 
@@ -201,8 +201,7 @@ public class DigestScheme implements AuthScheme, Serializable {
             final String exchangeId = clientContext.getExchangeId();
             LOG.debug("{} No credentials found for auth scope [{}]", exchangeId, authScope);
         }
-        this.username = null;
-        this.password = null;
+        this.credentials = null;
         return false;
     }
 
@@ -323,13 +322,13 @@ public class DigestScheme implements AuthScheme, Serializable {
             //      ":" unq(cnonce-value)
 
             // calculated one per session
-            buffer.append(username).append(":").append(realm).append(":").append(password);
+            buffer.append(credentials.getUserName()).append(":").append(realm).append(":").append(credentials.getUserPassword());
             final String checksum = formatHex(digester.digest(this.buffer.toByteArray()));
             buffer.reset();
             buffer.append(checksum).append(":").append(nonce).append(":").append(cnonce);
         } else {
             // unq(username-value) ":" unq(realm-value) ":" passwd
-            buffer.append(username).append(":").append(realm).append(":").append(password);
+            buffer.append(credentials.getUserName()).append(":").append(realm).append(":").append(credentials.getUserPassword());
         }
         a1 = buffer.toByteArray();
 
@@ -390,7 +389,7 @@ public class DigestScheme implements AuthScheme, Serializable {
         buffer.append(StandardAuthScheme.DIGEST + " ");
 
         final List<BasicNameValuePair> params = new ArrayList<>(20);
-        params.add(new BasicNameValuePair("username", username));
+        params.add(new BasicNameValuePair("username", credentials.getUserName()));
         params.add(new BasicNameValuePair("realm", realm));
         params.add(new BasicNameValuePair("nonce", nonce));
         params.add(new BasicNameValuePair("uri", uri));
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java
index a3b1e7926..de14d7c48 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java
@@ -44,14 +44,14 @@ public class TestCredentials {
         Assertions.assertEquals("name", creds1.getUserName());
         Assertions.assertEquals(new BasicUserPrincipal("name"),
                 creds1.getUserPrincipal());
-        Assertions.assertArrayEquals("pwd".toCharArray(), creds1.getPassword());
+        Assertions.assertArrayEquals("pwd".toCharArray(), creds1.getUserPassword());
         Assertions.assertEquals("[principal: name]", creds1.toString());
         final UsernamePasswordCredentials creds2 = new UsernamePasswordCredentials(
             "name", null);
         Assertions.assertEquals("name", creds2.getUserName());
         Assertions.assertEquals(new BasicUserPrincipal("name"),
                 creds2.getUserPrincipal());
-        Assertions.assertNull(creds2.getPassword());
+        Assertions.assertNull(creds2.getUserPassword());
         Assertions.assertEquals("[principal: name]", creds2.toString());
     }
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java
index 2c452a3f9..265b4c980 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/auth/TestSystemDefaultCredentialsProvider.java
@@ -104,7 +104,6 @@ public class TestSystemDefaultCredentialsProvider {
                                                                         RequestorType.SERVER);
         Assertions.assertNotNull(receivedCredentials);
         Assertions.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName());
-        Assertions.assertEquals(AUTH1.getPassword(), receivedCredentials.getPassword());
     }
 
     @Test
@@ -122,7 +121,6 @@ public class TestSystemDefaultCredentialsProvider {
                                                                         RequestorType.SERVER);
         Assertions.assertNotNull(receivedCredentials);
         Assertions.assertEquals(AUTH1.getUserName(), receivedCredentials.getUserPrincipal().getName());
-        Assertions.assertEquals(AUTH1.getPassword(), receivedCredentials.getPassword());
     }
 
     private AuthenticatorDelegate installAuthenticator(final PasswordAuthentication returedAuthentication) {