You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by om...@apache.org on 2011/10/18 22:33:16 UTC

svn commit: r1185842 - in /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs: CHANGES.txt src/main/java/org/apache/hadoop/hdfs/HftpFileSystem.java src/test/java/org/apache/hadoop/hdfs/TestHftpDelegationToken.java

Author: omalley
Date: Tue Oct 18 20:33:16 2011
New Revision: 1185842

URL: http://svn.apache.org/viewvc?rev=1185842&view=rev
Log:
HDFS-2467. HftpFileSystem uses incorrect compare for finding delegation
tokens. (omalley)

Added:
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHftpDelegationToken.java
Modified:
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
    hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/HftpFileSystem.java

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1185842&r1=1185841&r2=1185842&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Tue Oct 18 20:33:16 2011
@@ -1160,6 +1160,9 @@ Release 0.23.0 - Unreleased
     HDFS-2422. The NN should tolerate the same number of low-resource volumes
                as failed volumes (atm)
 
+    HDFS-2467. HftpFileSystem uses incorrect compare for finding delegation
+    tokens. (omalley)
+
   BREAKDOWN OF HDFS-1073 SUBTASKS
 
     HDFS-1521. Persist transaction ID on disk between NN restarts.

Modified: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/HftpFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/HftpFileSystem.java?rev=1185842&r1=1185841&r2=1185842&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/HftpFileSystem.java (original)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/HftpFileSystem.java Tue Oct 18 20:33:16 2011
@@ -189,7 +189,7 @@ public class HftpFileSystem extends File
       for (Token<? extends TokenIdentifier> t : ugi.getTokens()) {
         Text kind = t.getKind();
         if (DelegationTokenIdentifier.HDFS_DELEGATION_KIND.equals(kind)) {
-          if (t.getService().toString().equals(hdfsServiceName)) {
+          if (t.getService().equals(hdfsServiceName)) {
             setDelegationToken(t);
             break;
           }

Added: hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHftpDelegationToken.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHftpDelegationToken.java?rev=1185842&view=auto
==============================================================================
--- hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHftpDelegationToken.java (added)
+++ hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestHftpDelegationToken.java Tue Oct 18 20:33:16 2011
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdfs;
+
+import static 
+  org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URISyntaxException;
+import java.net.URI;
+import java.net.URL;
+import java.net.HttpURLConnection;
+import java.security.PrivilegedExceptionAction;
+import java.util.Random;
+
+import org.junit.Test;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import static org.junit.Assert.*;
+
+import org.apache.commons.logging.impl.Log4JLogger;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.DFSConfigKeys;
+import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.security.token.TokenIdentifier;
+
+public class TestHftpDelegationToken {
+
+  @Test
+  public void testHdfsDelegationToken() throws Exception {
+    final Configuration conf = new Configuration();
+    conf.set(HADOOP_SECURITY_AUTHENTICATION, "kerberos");
+    UserGroupInformation.setConfiguration(conf);
+    UserGroupInformation user =  
+      UserGroupInformation.createUserForTesting("oom", 
+                                                new String[]{"memory"});
+    Token<?> token = new Token<TokenIdentifier>
+      (new byte[0], new byte[0], 
+       DelegationTokenIdentifier.HDFS_DELEGATION_KIND,
+       new Text("127.0.0.1:8020"));
+    user.addToken(token);
+    Token<?> token2 = new Token<TokenIdentifier>
+      (null, null, new Text("other token"), new Text("127.0.0.1:8020"));
+    user.addToken(token2);
+    assertEquals("wrong tokens in user", 2, user.getTokens().size());
+    FileSystem fs = 
+      user.doAs(new PrivilegedExceptionAction<FileSystem>() {
+	  public FileSystem run() throws Exception {
+            return FileSystem.get(new URI("hftp://localhost:50470/"), conf);
+	  }
+	});
+    assertSame("wrong kind of file system", HftpFileSystem.class,
+                 fs.getClass());
+    Field renewToken = HftpFileSystem.class.getDeclaredField("renewToken");
+    renewToken.setAccessible(true);
+    assertSame("wrong token", token, renewToken.get(fs));
+  }
+}
\ No newline at end of file