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 92f5595e7e
commit af5146ee04
2 changed files with 19 additions and 7 deletions

View File

@ -497,11 +497,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;
}
@ -620,11 +628,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

@ -2601,6 +2601,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);
}