You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "michael-o (via GitHub)" <gi...@apache.org> on 2023/04/23 14:49:17 UTC

[GitHub] [httpcomponents-client] michael-o commented on a diff in pull request #436: Update NTCredentials to Determine Workstation Name at Runtime

michael-o commented on code in PR #436:
URL: https://github.com/apache/httpcomponents-client/pull/436#discussion_r1174594598


##########
httpclient5/src/main/java/org/apache/hc/client5/http/auth/NTCredentials.java:
##########
@@ -192,15 +217,27 @@ private static String stripDotSuffix(final String value) {
         return value;
     }
 
-    /** Convert host to standard form */
-    private static String convertHost(final String host) {
-        return stripDotSuffix(host);
-    }
-
     /** Convert domain to standard form */
     private static String convertDomain(final String domain) {
         final String returnString = stripDotSuffix(domain);
         return returnString == null ? returnString : returnString.toUpperCase(Locale.ROOT);
     }
 
+
+    /**
+     * Retrieves the workstation name of the computer originating the request.
+     * This method attempts to get the local host name using the InetAddress class.
+     * If it fails to retrieve the host name due to an UnknownHostException, it returns "localhost" as a fallback.
+     *
+     * @return The workstation name as a String.
+     */
+    private static String getWorkstationName() {
+        try {
+            final InetAddress addr = InetAddress.getLocalHost();
+            return addr.getHostName();

Review Comment:
   Is this guaranteed to return the local part only w/o the domain name? I.e., unqualified name?



##########
httpclient5/src/main/java/org/apache/hc/client5/http/auth/NTCredentials.java:
##########
@@ -85,25 +89,46 @@ public NTCredentials(
      * Essentially, the computer name for this machine.
      * @param domain The domain to authenticate within.
      * @param netbiosDomain The netbios version of the domain name.
+     @deprecated (5.3) Use {@link #NTCredentials(char[], String, String, String)}
      */
+    @Deprecated
     public NTCredentials(
             final String userName,
             final char[] password,
             final String workstation,
             final String domain,
             final String netbiosDomain) {
+        this(password, userName,  domain, netbiosDomain);
+    }
+
+    /**
+     * Constructor to create an instance of NTCredentials.
+     *
+     * @param password      The password to use for authentication. Must not be null.
+     * @param userName      The user name for authentication. This should not include the domain to authenticate with.
+     *                      For example: "user" is correct whereas "DOMAIN&#x5c;user" is not. Must not be null.
+     * @param domain        The domain to authenticate within. Can be null.
+     * @param netbiosDomain The netbios version of the domain name. Can be null.

Review Comment:
   I am confused about this description. Is it now the NetBIOS version or the domain?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org