From 137f0d324ad6de40fdf34d50a44c79402043a509 Mon Sep 17 00:00:00 2001 From: Arpit Agarwal Date: Tue, 27 Feb 2018 08:48:13 -0800 Subject: [PATCH] HADOOP-14959. DelegationTokenAuthenticator.authenticate() to wrap network exceptions. Contributed by Ajay Kumar. --- .../web/DelegationTokenAuthenticator.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java index a1c600340e..617773b34d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/web/DelegationTokenAuthenticator.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.client.AuthenticatedURL; @@ -138,11 +139,17 @@ public abstract class DelegationTokenAuthenticator implements Authenticator { public void authenticate(URL url, AuthenticatedURL.Token token) throws IOException, AuthenticationException { if (!hasDelegationToken(url, token)) { - // check and renew TGT to handle potential expiration - UserGroupInformation.getCurrentUser().checkTGTAndReloginFromKeytab(); - LOG.debug("No delegation token found for url={}, token={}, authenticating" - + " with {}", url, token, authenticator.getClass()); - authenticator.authenticate(url, token); + try { + // check and renew TGT to handle potential expiration + UserGroupInformation.getCurrentUser().checkTGTAndReloginFromKeytab(); + LOG.debug("No delegation token found for url={}, token={}, " + + "authenticating with {}", url, token, authenticator.getClass()); + authenticator.authenticate(url, token); + } catch (IOException ex) { + throw NetUtils.wrapException(url.getHost(), url.getPort(), + null, 0, ex); + } + } else { LOG.debug("Authenticated from delegation token. url={}, token={}", url, token);