|
@@ -57,7 +57,6 @@ import org.apache.hadoop.net.NetUtils;
|
|
|
import org.apache.hadoop.security.Credentials;
|
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
-import org.apache.hadoop.security.authentication.client.AuthenticationException;
|
|
|
import org.apache.hadoop.security.token.Token;
|
|
|
import org.apache.hadoop.security.token.TokenIdentifier;
|
|
|
import org.apache.hadoop.util.Progressable;
|
|
@@ -234,17 +233,23 @@ public class HftpFileSystem extends FileSystem
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public synchronized Token<?> getDelegationToken(final String renewer
|
|
|
- ) throws IOException {
|
|
|
+ public synchronized Token<?> getDelegationToken(final String renewer)
|
|
|
+ throws IOException {
|
|
|
try {
|
|
|
- //Renew TGT if needed
|
|
|
- ugi.checkTGTAndReloginFromKeytab();
|
|
|
- return ugi.doAs(new PrivilegedExceptionAction<Token<?>>() {
|
|
|
+ // Renew TGT if needed
|
|
|
+ UserGroupInformation connectUgi = ugi.getRealUser();
|
|
|
+ final String proxyUser = connectUgi == null ? null : ugi
|
|
|
+ .getShortUserName();
|
|
|
+ if (connectUgi == null) {
|
|
|
+ connectUgi = ugi;
|
|
|
+ }
|
|
|
+ return connectUgi.doAs(new PrivilegedExceptionAction<Token<?>>() {
|
|
|
@Override
|
|
|
public Token<?> run() throws IOException {
|
|
|
Credentials c;
|
|
|
try {
|
|
|
- c = DelegationTokenFetcher.getDTfromRemote(connectionFactory, nnUri, renewer);
|
|
|
+ c = DelegationTokenFetcher.getDTfromRemote(connectionFactory,
|
|
|
+ nnUri, renewer, proxyUser);
|
|
|
} catch (IOException e) {
|
|
|
if (e.getCause() instanceof ConnectException) {
|
|
|
LOG.warn("Couldn't connect to " + nnUri +
|
|
@@ -299,13 +304,13 @@ public class HftpFileSystem extends FileSystem
|
|
|
* @return user_shortname,group1,group2...
|
|
|
*/
|
|
|
private String getEncodedUgiParameter() {
|
|
|
- StringBuilder ugiParamenter = new StringBuilder(
|
|
|
+ StringBuilder ugiParameter = new StringBuilder(
|
|
|
ServletUtil.encodeQueryValue(ugi.getShortUserName()));
|
|
|
for(String g: ugi.getGroupNames()) {
|
|
|
- ugiParamenter.append(",");
|
|
|
- ugiParamenter.append(ServletUtil.encodeQueryValue(g));
|
|
|
+ ugiParameter.append(",");
|
|
|
+ ugiParameter.append(ServletUtil.encodeQueryValue(g));
|
|
|
}
|
|
|
- return ugiParamenter.toString();
|
|
|
+ return ugiParameter.toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -675,30 +680,48 @@ public class HftpFileSystem extends FileSystem
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
- public long renewDelegationToken(Token<?> token) throws IOException {
|
|
|
+ public long renewDelegationToken(final Token<?> token) throws IOException {
|
|
|
// update the kerberos credentials, if they are coming from a keytab
|
|
|
- UserGroupInformation.getLoginUser().checkTGTAndReloginFromKeytab();
|
|
|
- InetSocketAddress serviceAddr = SecurityUtil.getTokenServiceAddr(token);
|
|
|
+ UserGroupInformation connectUgi = ugi.getRealUser();
|
|
|
+ if (connectUgi == null) {
|
|
|
+ connectUgi = ugi;
|
|
|
+ }
|
|
|
try {
|
|
|
- return DelegationTokenFetcher.renewDelegationToken(connectionFactory,
|
|
|
- DFSUtil.createUri(getUnderlyingProtocol(), serviceAddr),
|
|
|
- (Token<DelegationTokenIdentifier>) token);
|
|
|
- } catch (AuthenticationException e) {
|
|
|
+ return connectUgi.doAs(new PrivilegedExceptionAction<Long>() {
|
|
|
+ @Override
|
|
|
+ public Long run() throws Exception {
|
|
|
+ InetSocketAddress serviceAddr = SecurityUtil
|
|
|
+ .getTokenServiceAddr(token);
|
|
|
+ return DelegationTokenFetcher.renewDelegationToken(connectionFactory,
|
|
|
+ DFSUtil.createUri(getUnderlyingProtocol(), serviceAddr),
|
|
|
+ (Token<DelegationTokenIdentifier>) token);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (InterruptedException e) {
|
|
|
throw new IOException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
- public void cancelDelegationToken(Token<?> token) throws IOException {
|
|
|
- // update the kerberos credentials, if they are coming from a keytab
|
|
|
- UserGroupInformation.getLoginUser().checkTGTAndReloginFromKeytab();
|
|
|
- InetSocketAddress serviceAddr = SecurityUtil.getTokenServiceAddr(token);
|
|
|
+ public void cancelDelegationToken(final Token<?> token) throws IOException {
|
|
|
+ UserGroupInformation connectUgi = ugi.getRealUser();
|
|
|
+ if (connectUgi == null) {
|
|
|
+ connectUgi = ugi;
|
|
|
+ }
|
|
|
try {
|
|
|
- DelegationTokenFetcher.cancelDelegationToken(connectionFactory, DFSUtil
|
|
|
- .createUri(getUnderlyingProtocol(), serviceAddr),
|
|
|
- (Token<DelegationTokenIdentifier>) token);
|
|
|
- } catch (AuthenticationException e) {
|
|
|
+ connectUgi.doAs(new PrivilegedExceptionAction<Void>() {
|
|
|
+ @Override
|
|
|
+ public Void run() throws Exception {
|
|
|
+ InetSocketAddress serviceAddr = SecurityUtil
|
|
|
+ .getTokenServiceAddr(token);
|
|
|
+ DelegationTokenFetcher.cancelDelegationToken(connectionFactory,
|
|
|
+ DFSUtil.createUri(getUnderlyingProtocol(), serviceAddr),
|
|
|
+ (Token<DelegationTokenIdentifier>) token);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (InterruptedException e) {
|
|
|
throw new IOException(e);
|
|
|
}
|
|
|
}
|