Browse Source

HDFS-17679 Use saslClient#hasInitialResponse() instead of heuristics in SaslParticipant#createFirstMessage() (#7201)

Istvan Toth 5 months ago
parent
commit
86d8fa6d51

+ 7 - 2
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/datatransfer/sasl/SaslParticipant.java

@@ -127,8 +127,13 @@ class SaslParticipant {
   }
 
   byte[] createFirstMessage() throws SaslException {
-    return SaslMechanismFactory.isDefaultMechanism(MECHANISM_ARRAY[0]) ? EMPTY_BYTE_ARRAY
-        : evaluateChallengeOrResponse(EMPTY_BYTE_ARRAY);
+    if (saslClient != null) {
+      return saslClient.hasInitialResponse()
+          ? saslClient.evaluateChallenge(EMPTY_BYTE_ARRAY)
+          : EMPTY_BYTE_ARRAY;
+    }
+    throw new IllegalStateException(
+        "createFirstMessage must only be called for clients");
   }
 
   /**