You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by om...@apache.org on 2011/03/04 05:02:52 UTC

svn commit: r1077317 - in /hadoop/common/branches/branch-0.20-security-patches/src: hdfs/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java test/org/apache/hadoop/tools/TestDelegationTokenFetcher.java

Author: omalley
Date: Fri Mar  4 04:02:52 2011
New Revision: 1077317

URL: http://svn.apache.org/viewvc?rev=1077317&view=rev
Log:
commit 31187ae59485ce849ac8cd4c650877596863ebbf
Author: Boris Shkolnik <bo...@yahoo-inc.com>
Date:   Thu Mar 11 23:06:25 2010 -0800

    HDFS:1036 from https://issues.apache.org/jira/secure/attachment/12438585/HDFS-1036-BP20-1.patch
    
    +++ b/YAHOO-CHANGES.txt
    +    HDFS-1036. In DelegationTokenFetch pass Configuration object so getDefaultUri
    +    will work correctly.
    +

Modified:
    hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java
    hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/tools/TestDelegationTokenFetcher.java

Modified: hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java?rev=1077317&r1=1077316&r2=1077317&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/hdfs/org/apache/hadoop/hdfs/tools/DelegationTokenFetcher.java Fri Mar  4 04:02:52 2011
@@ -53,6 +53,7 @@ public class DelegationTokenFetcher {
   private final DistributedFileSystem dfs;
   private final UserGroupInformation ugi;
   private final DataOutputStream out;
+  private final Configuration conf;
 
   /**
    * Command-line interface
@@ -85,7 +86,7 @@ public class DelegationTokenFetcher {
           out = new DataOutputStream(new FileOutputStream(args[0]));
           UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
 
-          new DelegationTokenFetcher(dfs, out, ugi).go();
+          new DelegationTokenFetcher(dfs, out, ugi, conf).go();
           
           out.flush();
           System.out.println("Succesfully wrote token of size " + 
@@ -103,10 +104,11 @@ public class DelegationTokenFetcher {
   }
   
   public DelegationTokenFetcher(DistributedFileSystem dfs, 
-      DataOutputStream out, UserGroupInformation ugi) {
+      DataOutputStream out, UserGroupInformation ugi, Configuration conf) {
     checkNotNull("dfs", dfs); this.dfs = dfs;
     checkNotNull("out", out); this.out = out;
     checkNotNull("ugi", ugi); this.ugi = ugi;
+    checkNotNull("conf",conf); this.conf = conf;
   }
   
   private void checkNotNull(String s, Object o) {
@@ -120,7 +122,7 @@ public class DelegationTokenFetcher {
       dfs.getDelegationToken(new Text(fullName));
     
     // Reconstruct the ip:port of the Namenode
-    URI uri = dfs.getDefaultUri(dfs.getConf());
+    URI uri = FileSystem.getDefaultUri(conf);
     String nnAddress = 
       InetAddress.getByName(uri.getHost()).getHostAddress() + ":" + uri.getPort();
     token.setService(new Text(nnAddress));

Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/tools/TestDelegationTokenFetcher.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/tools/TestDelegationTokenFetcher.java?rev=1077317&r1=1077316&r2=1077317&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/tools/TestDelegationTokenFetcher.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/tools/TestDelegationTokenFetcher.java Fri Mar  4 04:02:52 2011
@@ -28,6 +28,8 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.net.URI;
 
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hdfs.DistributedFileSystem;
 import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
 import org.apache.hadoop.hdfs.tools.DelegationTokenFetcher;
@@ -43,12 +45,14 @@ public class TestDelegationTokenFetcher 
   private DistributedFileSystem dfs;
   private DataOutputStream out;
   private UserGroupInformation ugi;
+  private Configuration conf;
 
   @Before 
   public void init() {
     dfs = mock(DistributedFileSystem.class);
     out = mock(DataOutputStream.class);
     ugi = mock(UserGroupInformation.class);
+    conf = new Configuration();
   }
   
   /**
@@ -60,6 +64,8 @@ public class TestDelegationTokenFetcher 
     final String LONG_NAME = "TheDoctor@TARDIS";
     final String SHORT_NAME = "TheDoctor";
     final String SERVICE_VALUE = "localhost:2005";
+    URI uri = new URI("hdfs://" + SERVICE_VALUE);
+    FileSystem.setDefaultUri(conf, uri);
     
     // Mock out the user's long and short names.
     when(ugi.getUserName()).thenReturn(LONG_NAME);
@@ -69,15 +75,11 @@ public class TestDelegationTokenFetcher 
     // for this particular user.
     Token<DelegationTokenIdentifier> t = new Token<DelegationTokenIdentifier>();
     when(dfs.getDelegationToken(eq(new Text(LONG_NAME)))).thenReturn(t);
-
-    // Mock the NN's URI, which is stored as the service value
-    URI uri = new URI("hdfs://" + SERVICE_VALUE);
-    when(dfs.getUri()).thenReturn(uri);
-    
+ 
     // Now, actually let the TokenFetcher go fetch the token.
     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
     out = new DataOutputStream(baos);
-    new DelegationTokenFetcher(dfs, out, ugi).go();
+    new DelegationTokenFetcher(dfs, out, ugi, conf).go();
     
     // now read the data back in and verify correct values
     Credentials ts = new Credentials();
@@ -94,7 +96,7 @@ public class TestDelegationTokenFetcher 
 
   private void checkWithNullParam(String s) {
     try {
-      new DelegationTokenFetcher(dfs, out, ugi);
+      new DelegationTokenFetcher(dfs, out, ugi, conf);
     } catch (IllegalArgumentException iae) {
       assertEquals("Expected exception message not received", 
           s + " cannot be null.", iae.getMessage());