From 3cdc3921509aed53c5405289ff34e44c508da29a Mon Sep 17 00:00:00 2001 From: Brahma Reddy Battula Date: Thu, 18 Jan 2018 10:54:32 +0530 Subject: [PATCH] HADOOP-15150. in FsShell, UGI params should be overidden through env vars(-D arg). Contributed by Brahma Reddy Battula. (cherry picked from commit 08332e12d055d85472f0c9371fefe9b56bfea1ed) --- .../main/java/org/apache/hadoop/fs/FsShell.java | 2 ++ .../java/org/apache/hadoop/fs/TestFsShellList.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java index eccfbfc6219..0bf72c9c27c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsShell.java @@ -30,6 +30,7 @@ import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.shell.Command; import org.apache.hadoop.fs.shell.CommandFactory; import org.apache.hadoop.fs.shell.FsCommand; +import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.tools.TableListing; import org.apache.hadoop.tracing.TraceUtils; import org.apache.hadoop.util.StringUtils; @@ -92,6 +93,7 @@ public class FsShell extends Configured implements Tool { protected void init() throws IOException { getConf().setQuietMode(true); + UserGroupInformation.setConfiguration(getConf()); if (commandFactory == null) { commandFactory = new CommandFactory(getConf()); commandFactory.addObject(new Help(), "-help"); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellList.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellList.java index 03720d37726..c780f410535 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellList.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellList.java @@ -75,4 +75,18 @@ public class TestFsShellList { lsArgv = new String[]{"-ls", "-q", testRootDir.toString()}; assertThat(shell.run(lsArgv), is(0)); } + + /* + UGI params should take effect when we pass. + */ + @Test(expected = IllegalArgumentException.class) + public void testListWithUGI() throws Exception { + FsShell fsShell = new FsShell(new Configuration()); + //Passing Dummy such that it should through IAE + fsShell.getConf() + .set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, + "DUMMYAUTH"); + String[] lsArgv = new String[] {"-ls", testRootDir.toString()}; + fsShell.run(lsArgv); + } }