public static List<UserPermission> getUserPermissions(Connection connection, String tableRegex,
    String userName) throws Throwable {
    List<UserPermission> permList = new ArrayList<>();
    try (Admin admin = connection.getAdmin()) {
      if (tableRegex == null || tableRegex.isEmpty()) {
        permList = admin.getUserPermissions(
          GetUserPermissionsRequest.newBuilder().withUserName(userName).build());
      } else if (tableRegex.charAt(0) == '@') { // Namespaces
        String namespaceRegex = tableRegex.substring(1);
        for (NamespaceDescriptor nsds : admin.listNamespaceDescriptors()) { // Read out all
                                                                            // namespaces
          String namespace = nsds.getName();
          if (namespace.matches(namespaceRegex)) { // Match the given namespace regex?
            permList.addAll(admin.getUserPermissions(
              GetUserPermissionsRequest.newBuilder(namespace).withUserName(userName).build()));
          }
        }
      } else { // Tables
        List<TableDescriptor> htds = admin.listTableDescriptors(Pattern.compile(tableRegex), true);
        for (TableDescriptor htd : htds) {
          permList.addAll(admin.getUserPermissions(GetUserPermissionsRequest
            .newBuilder(htd.getTableName()).withUserName(userName).build()));
        }
      }
    }
    return permList;
  }
List all the userPermissions matching the given table pattern and user name.
@param connection Connection
@param tableRegex The regular expression string to match against
@param userName   User name, if empty then all user permissions will be retrieved.
@return List of UserPermissions
@throws Throwable on failure
hbase-client/src/main/java/org/apache/hadoop/hbase/security/access/AccessControlClient.java