HDFS-14176. Replace incorrect use of system property user.name. Contributed by Dinesh Chitlangia.

This commit is contained in:
Ajay Kumar 2019-03-20 11:20:45 -07:00
parent b3b0e332e6
commit 399563fec6
2 changed files with 18 additions and 4 deletions

View File

@ -113,7 +113,7 @@ public class RouterClientProtocol implements ClientProtocol {
private final ActiveNamenodeResolver namenodeResolver; private final ActiveNamenodeResolver namenodeResolver;
/** Identifier for the super user. */ /** Identifier for the super user. */
private final String superUser; private String superUser;
/** Identifier for the super group. */ /** Identifier for the super group. */
private final String superGroup; private final String superGroup;
/** Erasure coding calls. */ /** Erasure coding calls. */
@ -126,7 +126,13 @@ public class RouterClientProtocol implements ClientProtocol {
this.namenodeResolver = rpcServer.getNamenodeResolver(); this.namenodeResolver = rpcServer.getNamenodeResolver();
// User and group for reporting // User and group for reporting
try {
this.superUser = UserGroupInformation.getCurrentUser().getShortUserName();
} catch (IOException ex) {
LOG.warn("Unable to get user name. Fall back to system property " +
"user.name", ex);
this.superUser = System.getProperty("user.name"); this.superUser = System.getProperty("user.name");
}
this.superGroup = conf.get( this.superGroup = conf.get(
DFSConfigKeys.DFS_PERMISSIONS_SUPERUSERGROUP_KEY, DFSConfigKeys.DFS_PERMISSIONS_SUPERUSERGROUP_KEY,
DFSConfigKeys.DFS_PERMISSIONS_SUPERUSERGROUP_DEFAULT); DFSConfigKeys.DFS_PERMISSIONS_SUPERUSERGROUP_DEFAULT);

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.fs.swift.snative; package org.apache.hadoop.fs.swift.snative;
import org.apache.hadoop.security.UserGroupInformation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
@ -100,7 +101,7 @@ public String getScheme() {
} }
/** /**
* default class initialization * default class initialization.
* *
* @param fsuri path to Swift * @param fsuri path to Swift
* @param conf Hadoop configuration * @param conf Hadoop configuration
@ -115,7 +116,14 @@ public void initialize(URI fsuri, Configuration conf) throws IOException {
store = new SwiftNativeFileSystemStore(); store = new SwiftNativeFileSystemStore();
} }
this.uri = fsuri; this.uri = fsuri;
String username = System.getProperty("user.name"); String username;
try {
username = UserGroupInformation.getCurrentUser().getShortUserName();
} catch (IOException ex) {
LOG.warn("Unable to get user name. Fall back to system property " +
"user.name", ex);
username = System.getProperty("user.name");
}
this.workingDir = new Path("/user", username) this.workingDir = new Path("/user", username)
.makeQualified(uri, new Path(username)); .makeQualified(uri, new Path(username));
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {