Author: cnauroth
Date: Wed Jan  8 22:47:57 2014
New Revision: 1556663

URL: http://svn.apache.org/r1556663
Log:
HDFS-5739. ACL RPC must allow null name or unspecified permissions in ACL 
entries. Contributed by Chris Nauroth.

Modified:
    
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt
    
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java
    
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/acl.proto
    
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java

Modified: 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt?rev=1556663&r1=1556662&r2=1556663&view=diff
==============================================================================
--- 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt
 (original)
+++ 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/CHANGES-HDFS-4685.txt
 Wed Jan  8 22:47:57 2014
@@ -34,3 +34,6 @@ HDFS-4685 (Unreleased)
 
     HDFS-5737. Replacing only the default ACL can fail to copy unspecified base
     entries from the access ACL. (cnauroth)
+
+    HDFS-5739. ACL RPC must allow null name or unspecified permissions in ACL
+    entries. (cnauroth)

Modified: 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java?rev=1556663&r1=1556662&r2=1556663&view=diff
==============================================================================
--- 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java
 (original)
+++ 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java
 Wed Jan  8 22:47:57 2014
@@ -1928,7 +1928,7 @@ public class PBHelper {
   }
 
   private static FsActionProto convert(FsAction v) {
-    return FsActionProto.valueOf(v.ordinal());
+    return FsActionProto.valueOf(v != null ? v.ordinal() : 0);
   }
 
   private static FsAction convert(FsActionProto v) {
@@ -1939,9 +1939,14 @@ public class PBHelper {
       List<AclEntry> aclSpec) {
     ArrayList<AclEntryProto> r = 
Lists.newArrayListWithCapacity(aclSpec.size());
     for (AclEntry e : aclSpec) {
-      r.add(AclEntryProto.newBuilder().setType(convert(e.getType()))
-          .setName(e.getName()).setPermissions(convert(e.getPermission()))
-          .setScope(convert(e.getScope())).build());
+      AclEntryProto.Builder builder = AclEntryProto.newBuilder();
+      builder.setType(convert(e.getType()));
+      builder.setScope(convert(e.getScope()));
+      builder.setPermissions(convert(e.getPermission()));
+      if (e.getName() != null) {
+        builder.setName(e.getName());
+      }
+      r.add(builder.build());
     }
     return r;
   }
@@ -1949,9 +1954,14 @@ public class PBHelper {
   public static List<AclEntry> convertAclEntry(List<AclEntryProto> aclSpec) {
     ArrayList<AclEntry> r = Lists.newArrayListWithCapacity(aclSpec.size());
     for (AclEntryProto e : aclSpec) {
-      r.add(new AclEntry.Builder().setType(convert(e.getType()))
-          .setName(e.getName()).setPermission(convert(e.getPermissions()))
-          .setScope(convert(e.getScope())).build());
+      AclEntry.Builder builder = new AclEntry.Builder();
+      builder.setType(convert(e.getType()));
+      builder.setScope(convert(e.getScope()));
+      builder.setPermission(convert(e.getPermissions()));
+      if (e.hasName()) {
+        builder.setName(e.getName());
+      }
+      r.add(builder.build());
     }
     return r;
   }

Modified: 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/acl.proto
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/acl.proto?rev=1556663&r1=1556662&r2=1556663&view=diff
==============================================================================
--- 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/acl.proto
 (original)
+++ 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/main/proto/acl.proto
 Wed Jan  8 22:47:57 2014
@@ -50,7 +50,7 @@ message AclEntryProto {
   required AclEntryTypeProto type    = 1;
   required AclEntryScopeProto scope  = 2;
   required FsActionProto permissions = 3;
-  required string name               = 4;
+  optional string name               = 4;
 }
 
 message AclStatusProto {

Modified: 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java
URL: 
http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java?rev=1556663&r1=1556662&r2=1556663&view=diff
==============================================================================
--- 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java
 (original)
+++ 
hadoop/common/branches/HDFS-4685/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java
 Wed Jan  8 22:47:57 2014
@@ -589,16 +589,27 @@ public class TestPBHelper {
 
   @Test
   public void testAclEntryProto() {
-    AclEntry e = new AclEntry.Builder().setName("test")
+    // All fields populated.
+    AclEntry e1 = new AclEntry.Builder().setName("test")
         .setPermission(FsAction.READ_EXECUTE).setScope(AclEntryScope.DEFAULT)
         .setType(AclEntryType.OTHER).build();
-    AclEntry[] lists = new AclEntry[] { e };
-
-    Assert.assertArrayEquals(
-        lists,
-        Lists.newArrayList(
-            PBHelper.convertAclEntry(PBHelper.convertAclEntryProto(Lists
-                .newArrayList(e)))).toArray());
+    // No name.
+    AclEntry e2 = new AclEntry.Builder().setScope(AclEntryScope.ACCESS)
+        .setType(AclEntryType.USER).setPermission(FsAction.ALL).build();
+    // No permission, which will default to the 0'th enum element.
+    AclEntry e3 = new AclEntry.Builder().setScope(AclEntryScope.ACCESS)
+        .setType(AclEntryType.USER).setName("test").build();
+    AclEntry[] expected = new AclEntry[] { e1, e2,
+        new AclEntry.Builder()
+            .setScope(e3.getScope())
+            .setType(e3.getType())
+            .setName(e3.getName())
+            .setPermission(FsAction.NONE)
+            .build() };
+    AclEntry[] actual = Lists.newArrayList(
+        PBHelper.convertAclEntry(PBHelper.convertAclEntryProto(Lists
+            .newArrayList(e1, e2, e3)))).toArray(new AclEntry[0]);
+    Assert.assertArrayEquals(expected, actual);
   }
 
   @Test


Reply via email to