Skip to content

Commit 33c9ecb

Browse files
HADOOP-19249. KMSClientProvider raises NPE with unauthed user (#6984)
KMSClientProvider raises a NullPointerException when an unauthorised user tries to perform the key operation Contributed by Dhaval Shah
1 parent 2fd7cf5 commit 33c9ecb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.crypto.key.kms;
1919

2020
import org.apache.commons.codec.binary.Base64;
21+
import org.apache.commons.lang3.StringUtils;
2122
import org.apache.hadoop.classification.InterfaceAudience;
2223
import org.apache.hadoop.conf.Configuration;
2324
import org.apache.hadoop.crypto.key.KeyProvider;
@@ -561,17 +562,19 @@ private <T> T call(HttpURLConnection conn, Object jsonOutput,
561562
}
562563
throw ex;
563564
}
565+
564566
if ((conn.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN
565-
&& (conn.getResponseMessage().equals(ANONYMOUS_REQUESTS_DISALLOWED) ||
566-
conn.getResponseMessage().contains(INVALID_SIGNATURE)))
567+
&& (!StringUtils.isEmpty(conn.getResponseMessage())
568+
&& (conn.getResponseMessage().equals(ANONYMOUS_REQUESTS_DISALLOWED)
569+
|| conn.getResponseMessage().contains(INVALID_SIGNATURE))))
567570
|| conn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
568571
// Ideally, this should happen only when there is an Authentication
569572
// failure. Unfortunately, the AuthenticationFilter returns 403 when it
570573
// cannot authenticate (Since a 401 requires Server to send
571574
// WWW-Authenticate header as well)..
572575
if (LOG.isDebugEnabled()) {
573-
LOG.debug("Response={}({}), resetting authToken",
574-
conn.getResponseCode(), conn.getResponseMessage());
576+
LOG.debug("Response={}, resetting authToken",
577+
conn.getResponseCode());
575578
}
576579
KMSClientProvider.this.authToken =
577580
new DelegationTokenAuthenticatedURL.Token();
@@ -797,6 +800,7 @@ public EncryptedKeyVersion generateEncryptedKey(
797800
@SuppressWarnings("rawtypes")
798801
@Override
799802
public KeyVersion decryptEncryptedKey(
803+
800804
EncryptedKeyVersion encryptedKeyVersion) throws IOException,
801805
GeneralSecurityException {
802806
checkNotNull(encryptedKeyVersion.getEncryptionKeyVersionName(),

0 commit comments

Comments
 (0)