hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-17469 Properly handle empty TableName in TablePermission#readFields and #write (Manjunath Anand)
Date Tue, 17 Jan 2017 17:36:52 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 9b38c1a33 -> faa9f735c


HBASE-17469 Properly handle empty TableName in TablePermission#readFields and #write (Manjunath
Anand)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/faa9f735
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/faa9f735
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/faa9f735

Branch: refs/heads/master
Commit: faa9f735ca67ee3a2e1a59d93b519421e97e940f
Parents: 9b38c1a
Author: tedyu <yuzhihong@gmail.com>
Authored: Tue Jan 17 09:36:59 2017 -0800
Committer: tedyu <yuzhihong@gmail.com>
Committed: Tue Jan 17 09:36:59 2017 -0800

----------------------------------------------------------------------
 .../hbase/security/access/TablePermission.java  | 20 +++++++++++---------
 .../security/access/TestTablePermissions.java   |  2 ++
 2 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/faa9f735/hbase-client/src/main/java/org/apache/hadoop/hbase/security/access/TablePermission.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/security/access/TablePermission.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/security/access/TablePermission.java
index cf3f071..e9ecea4 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/security/access/TablePermission.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/security/access/TablePermission.java
@@ -189,7 +189,7 @@ public class TablePermission extends Permission {
    *   by this permission, <code>false</code>
    */
   public boolean implies(String namespace, Action action) {
-    if (!this.namespace.equals(namespace)) {
+    if (this.namespace == null || !this.namespace.equals(namespace)) {
       return false;
     }
 
@@ -212,7 +212,7 @@ public class TablePermission extends Permission {
    */
   public boolean implies(TableName table, byte[] family, byte[] qualifier,
       Action action) {
-    if (!this.table.equals(table)) {
+    if (this.table == null || !this.table.equals(table)) {
       return false;
     }
 
@@ -242,7 +242,7 @@ public class TablePermission extends Permission {
    *   by this permission, otherwise <code>false</code>
    */
   public boolean implies(TableName table, KeyValue kv, Action action) {
-    if (!this.table.equals(table)) {
+    if (this.table == null || !this.table.equals(table)) {
       return false;
     }
 
@@ -267,7 +267,7 @@ public class TablePermission extends Permission {
    * return false.
    */
   public boolean matchesFamily(TableName table, byte[] family, Action action) {
-    if (!this.table.equals(table)) {
+    if (this.table == null || !this.table.equals(table)) {
       return false;
     }
 
@@ -356,17 +356,16 @@ public class TablePermission extends Permission {
       str.append("namespace=").append(namespace)
          .append(", ");
     }
-    else if(table != null) {
+    if(table != null) {
        str.append("table=").append(table)
           .append(", family=")
           .append(family == null ? null : Bytes.toString(family))
           .append(", qualifier=")
           .append(qualifier == null ? null : Bytes.toString(qualifier))
           .append(", ");
-    } else {
-      str.append("actions=");
     }
     if (actions != null) {
+      str.append("actions=");
       for (int i=0; i<actions.length; i++) {
         if (i > 0)
           str.append(",");
@@ -385,7 +384,9 @@ public class TablePermission extends Permission {
   public void readFields(DataInput in) throws IOException {
     super.readFields(in);
     byte[] tableBytes = Bytes.readByteArray(in);
-    table = TableName.valueOf(tableBytes);
+    if(tableBytes.length > 0) {
+      table = TableName.valueOf(tableBytes);
+    }
     if (in.readBoolean()) {
       family = Bytes.readByteArray(in);
     }
@@ -400,7 +401,8 @@ public class TablePermission extends Permission {
   @Override
   public void write(DataOutput out) throws IOException {
     super.write(out);
-    Bytes.writeByteArray(out, table.getName());
+    // Explicitly writing null to maintain se/deserialize backward compatibility.
+    Bytes.writeByteArray(out, (table == null) ? null : table.getName());
     out.writeBoolean(family != null);
     if (family != null) {
       Bytes.writeByteArray(out, family);

http://git-wip-us.apache.org/repos/asf/hbase/blob/faa9f735/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
index 1e525e2..b23651f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
@@ -349,6 +349,8 @@ public class TestTablePermissions {
         TablePermission.Action.READ));
     permissions.put("hubert", new TablePermission(TEST_TABLE2, null,
         TablePermission.Action.READ, TablePermission.Action.WRITE));
+    permissions.put("bruce",new TablePermission(TEST_NAMESPACE,
+        TablePermission.Action.READ));
     return permissions;
   }
 


Mime
View raw message