HBASE-15465 userPermission returned by getUserPermission() for the selected namespace does not have namespace set (li xiang)

This commit is contained in:
Jerry He 2016-05-19 20:35:58 -07:00
parent 696a51d344
commit d038b762a5
2 changed files with 19 additions and 7 deletions

View File

@ -496,11 +496,19 @@ public class AccessControlLists {
List<UserPermission> perms = new ArrayList<UserPermission>();
for (Map.Entry<String, TablePermission> entry : allPerms.entries()) {
UserPermission up = new UserPermission(Bytes.toBytes(entry.getKey()),
entry.getValue().getTableName(), entry.getValue().getFamily(),
entry.getValue().getQualifier(), entry.getValue().getActions());
perms.add(up);
if(isNamespaceEntry(entryName)) { // Namespace
for (Map.Entry<String, TablePermission> entry : allPerms.entries()) {
UserPermission up = new UserPermission(Bytes.toBytes(entry.getKey()),
entry.getValue().getNamespace(), entry.getValue().getActions());
perms.add(up);
}
} else { // Table
for (Map.Entry<String, TablePermission> entry : allPerms.entries()) {
UserPermission up = new UserPermission(Bytes.toBytes(entry.getKey()),
entry.getValue().getTableName(), entry.getValue().getFamily(),
entry.getValue().getQualifier(), entry.getValue().getActions());
perms.add(up);
}
}
return perms;
}
@ -619,11 +627,11 @@ public class AccessControlLists {
}
public static boolean isNamespaceEntry(String entryName) {
return entryName.charAt(0) == NAMESPACE_PREFIX;
return entryName != null && entryName.charAt(0) == NAMESPACE_PREFIX;
}
public static boolean isNamespaceEntry(byte[] entryName) {
return entryName[0] == NAMESPACE_PREFIX;
return entryName != null && entryName.length !=0 && entryName[0] == NAMESPACE_PREFIX;
}
public static String toNamespaceEntry(String namespace) {

View File

@ -2599,6 +2599,10 @@ public class TestAccessController extends SecureTestUtil {
systemUserConnection, AccessControlLists.toNamespaceEntry(namespace));
assertTrue(namespacePermissions != null);
assertTrue(namespacePermissions.size() == 1);
for (UserPermission namespacePermission : namespacePermissions) {
assertFalse(namespacePermission.isGlobal()); // Verify it is not a global user permission
assertEquals(namespace, namespacePermission.getNamespace()); // Verify namespace is set
}
} catch (Throwable thw) {
throw new HBaseException(thw);
}