HBASE-17469 Properly handle empty TableName in TablePermission#readFields and #write (Manjunath Anand)
This commit is contained in:
parent
9b38c1a33c
commit
faa9f735ca
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user