@Test
  public void testGlobalPermission() throws Exception {
    Configuration conf = UTIL.getConfiguration();

    // add some permissions
    try (Connection connection = ConnectionFactory.createConnection(conf)) {
      addUserPermission(conf,
        new UserPermission("user1", Permission.newBuilder()
          .withActions(Permission.Action.READ, Permission.Action.WRITE).build()),
        connection.getTable(PermissionStorage.ACL_TABLE_NAME));
      addUserPermission(conf,
        new UserPermission("user2",
          Permission.newBuilder().withActions(Permission.Action.CREATE).build()),
        connection.getTable(PermissionStorage.ACL_TABLE_NAME));
      addUserPermission(conf,
        new UserPermission("user3",
          Permission.newBuilder()
            .withActions(Permission.Action.ADMIN, Permission.Action.READ, Permission.Action.CREATE)
            .build()),
        connection.getTable(PermissionStorage.ACL_TABLE_NAME));
    }
    ListMultimap<String, UserPermission> perms = PermissionStorage.getTablePermissions(conf, null);
    List<UserPermission> user1Perms = perms.get("user1");
    assertEquals("Should have 1 permission for user1", 1, user1Perms.size());
    assertEquals("user1 should have WRITE permission",
      new Permission.Action[] { Permission.Action.READ, Permission.Action.WRITE },
      user1Perms.get(0).getPermission().getActions());

    List<UserPermission> user2Perms = perms.get("user2");
    assertEquals("Should have 1 permission for user2", 1, user2Perms.size());
    assertEquals("user2 should have CREATE permission",
      new Permission.Action[] { Permission.Action.CREATE },
      user2Perms.get(0).getPermission().getActions());

    List<UserPermission> user3Perms = perms.get("user3");
    assertEquals("Should have 1 permission for user3", 1, user3Perms.size());
    assertEquals(
      "user3 should have ADMIN, READ, CREATE permission", new Permission.Action[] {
        Permission.Action.READ, Permission.Action.CREATE, Permission.Action.ADMIN },
      user3Perms.get(0).getPermission().getActions());
  }
The PermissionStorage.addUserPermission may throw exception before closing the table.
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java