@Test
  public void testCreateWithCorrectOwner() throws Exception {
    // Create a test user
    final User testUser =
      User.createUserForTesting(TEST_UTIL.getConfiguration(), "TestUser", new String[0]);
    // Grant the test user the ability to create tables
    SecureTestUtil.grantGlobal(TEST_UTIL, testUser.getShortName(), Action.CREATE);
    verifyAllowed(new AccessTestAction() {
      @Override
      public Object run() throws Exception {
        TableDescriptor tableDescriptor =
          TableDescriptorBuilder.newBuilder(testTable.getTableName())
            .setColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAMILY)).build();
        try (Connection connection =
          ConnectionFactory.createConnection(TEST_UTIL.getConfiguration(), testUser)) {
          try (Admin admin = connection.getAdmin()) {
            createTable(TEST_UTIL, admin, tableDescriptor);
          }
        }
        return null;
      }
    }, testUser);
    TEST_UTIL.waitTableAvailable(testTable.getTableName());
    // Verify that owner permissions have been granted to the test user on the
    // table just created
    List<UserPermission> perms = PermissionStorage
      .getTablePermissions(conf, testTable.getTableName()).get(testUser.getShortName());
    assertNotNull(perms);
    assertFalse(perms.isEmpty());
    // Should be RWXCA
    assertTrue(perms.get(0).getPermission().implies(Permission.Action.READ));
    assertTrue(perms.get(0).getPermission().implies(Permission.Action.WRITE));
    assertTrue(perms.get(0).getPermission().implies(Permission.Action.EXEC));
    assertTrue(perms.get(0).getPermission().implies(Permission.Action.CREATE));
    assertTrue(perms.get(0).getPermission().implies(Permission.Action.ADMIN));
  }
The systemUserConnection created here is tied to the system user. In case, you are planning to
create AccessTestAction, DON'T use this systemUserConnection as the 'doAs' user gets eclipsed
by the system user.
hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java