|
@@ -787,25 +787,44 @@ public class KMSClientProvider extends KeyProvider implements CryptoExtension,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Token<?>[] addDelegationTokens(String renewer,
|
|
|
+ public Token<?>[] addDelegationTokens(final String renewer,
|
|
|
Credentials credentials) throws IOException {
|
|
|
Token<?>[] tokens = null;
|
|
|
Text dtService = getDelegationTokenService();
|
|
|
Token<?> token = credentials.getToken(dtService);
|
|
|
if (token == null) {
|
|
|
- URL url = createURL(null, null, null, null);
|
|
|
- DelegationTokenAuthenticatedURL authUrl =
|
|
|
+ final URL url = createURL(null, null, null, null);
|
|
|
+ final DelegationTokenAuthenticatedURL authUrl =
|
|
|
new DelegationTokenAuthenticatedURL(configurator);
|
|
|
try {
|
|
|
- token = authUrl.getDelegationToken(url, authToken, renewer);
|
|
|
+ // 'actualUGI' is the UGI of the user creating the client
|
|
|
+ // It is possible that the creator of the KMSClientProvier
|
|
|
+ // calls this method on behalf of a proxyUser (the doAsUser).
|
|
|
+ // In which case this call has to be made as the proxy user.
|
|
|
+ UserGroupInformation currentUgi = UserGroupInformation.getCurrentUser();
|
|
|
+ final String doAsUser = (currentUgi.getAuthenticationMethod() ==
|
|
|
+ UserGroupInformation.AuthenticationMethod.PROXY)
|
|
|
+ ? currentUgi.getShortUserName() : null;
|
|
|
+
|
|
|
+ token = actualUgi.doAs(new PrivilegedExceptionAction<Token<?>>() {
|
|
|
+ @Override
|
|
|
+ public Token<?> run() throws Exception {
|
|
|
+ // Not using the cached token here.. Creating a new token here
|
|
|
+ // everytime.
|
|
|
+ return authUrl.getDelegationToken(url,
|
|
|
+ new DelegationTokenAuthenticatedURL.Token(), renewer, doAsUser);
|
|
|
+ }
|
|
|
+ });
|
|
|
if (token != null) {
|
|
|
credentials.addToken(token.getService(), token);
|
|
|
tokens = new Token<?>[] { token };
|
|
|
} else {
|
|
|
throw new IOException("Got NULL as delegation token");
|
|
|
}
|
|
|
- } catch (AuthenticationException ex) {
|
|
|
- throw new IOException(ex);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IOException(e);
|
|
|
}
|
|
|
}
|
|
|
return tokens;
|