public List getUserDataPrivilege()

in backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java [1196:1240]


  public List<DataPrivilegeVO> getUserDataPrivilege(Connection connection, String userName)
      throws BaseException {
    if ("root".equalsIgnoreCase(userName)) {
      DataPrivilegeVO dataPrivilegeVO = new DataPrivilegeVO();
      dataPrivilegeVO.setType(0);
      dataPrivilegeVO.setPrivileges(new ArrayList<>(DATA_PRIVILEGES));
      return Arrays.asList(dataPrivilegeVO);
    }
    SessionPool sessionPool = null;
    SessionDataSetWrapper sessionDataSetWrapper = null;
    try {
      List<String> rowInfos = new ArrayList<>();
      sessionPool = getSessionPool(connection);
      String sql = "list user privileges " + userName;
      sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
      while (sessionDataSetWrapper.hasNext()) {
        RowRecord next = sessionDataSetWrapper.next();
        List<org.apache.iotdb.tsfile.read.common.Field> fields = next.getFields();
        for (int i = 0; i < fields.size(); i++) {
          org.apache.iotdb.tsfile.read.common.Field field = fields.get(i);
          if (i == 0) {
            if (!"".equals(field.toString())) {
              break;
            }
          } else {
            rowInfos.add(field.toString());
          }
        }
      }
      // rowInfos form: "path : privilege1 privilege2 privilege3"
      List<DataPrivilegeVO> dataPrivilegeList =
          switchRowInfosToDataPrivileges(rowInfos, sessionPool);
      return dataPrivilegeList;
    } catch (IoTDBConnectionException e) {
      logger.error(e.getMessage());
      throw new BaseException(ErrorCode.GET_SESSION_FAIL, ErrorCode.GET_SESSION_FAIL_MSG);
    } catch (StatementExecutionException e) {
      logger.error(e.getMessage());
      throw new BaseException(
          ErrorCode.GET_USER_PRIVILEGE_FAIL, ErrorCode.GET_USER_PRIVILEGE_FAIL_MSG);
    } finally {
      closeResultSet(sessionDataSetWrapper);
      closeSessionPool(sessionPool);
    }
  }