@Test
  public void templateQueryTest() throws SQLException {
    try (Connection adminCon = EnvFactory.getEnv().getConnection();
        Statement adminStmt = adminCon.createStatement()) {
      adminStmt.execute("CREATE USER tempuser 'temppw'");
      try (Connection userCon = EnvFactory.getEnv().getConnection("tempuser", "temppw");
          Statement userStmt = userCon.createStatement()) {
        adminStmt.execute(
            "GRANT READ_DATA ON root.sg.aligned_template.temperature TO USER tempuser");
        adminStmt.execute("CREATE DATABASE root.sg");
        adminStmt.execute(
            "create device template t1 aligned (temperature FLOAT encoding=Gorilla, status BOOLEAN encoding=PLAIN);");
        adminStmt.execute("set device template t1 to root.sg.aligned_template;");
        adminStmt.execute("create timeseries using device template on root.sg.aligned_template;");
        adminStmt.execute(
            "insert into root.sg.aligned_template(time,temperature,status) values(1,20,false),(2,22.1,true),(3,18,false);");

        ResultSet set1 = adminStmt.executeQuery("SELECT * from root.sg.aligned_template");
        assertEquals(3, set1.getMetaData().getColumnCount());
        assertEquals("root.sg.aligned_template.temperature", set1.getMetaData().getColumnName(2));
        assertEquals("root.sg.aligned_template.status", set1.getMetaData().getColumnName(3));

        ResultSet set2 = userStmt.executeQuery("SELECT * from root.sg.aligned_template");
        assertEquals(2, set2.getMetaData().getColumnCount());
        assertEquals("root.sg.aligned_template.temperature", set2.getMetaData().getColumnName(2));
      }
    }
  }
This is an example for integration test.
integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBAuthIT.java