@Test
  public void allPrivilegesTest() 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()) {
        // 1. tempuser doesn't have any privilege
        Assert.assertThrows(SQLException.class, () -> userStmt.execute("CREATE DATABASE root.a"));
        Assert.assertThrows(
            SQLException.class,
            () ->
                userStmt.execute("CREATE TIMESERIES root.a.b WITH DATATYPE=INT32,ENCODING=PLAIN"));
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("INSERT INTO root.a(timestamp, b) VALUES (100, 100)"));
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("GRANT WRITE_SCHEMA ON root.a TO USER tempuser"));

        //  2. admin grant all privileges to user tempuser, So tempuser can do anything.
        adminStmt.execute("GRANT ALL ON root.** TO USER tempuser");

        userStmt.execute("CREATE DATABASE root.a");
        userStmt.execute("CREATE TIMESERIES root.a.b WITH DATATYPE=INT32,ENCODING=PLAIN");
        userStmt.execute("INSERT INTO root.a(timestamp, b) VALUES (100, 100)");
        userStmt.execute("SELECT * from root.a");

        // 3. All privileges granted to tempuser cannot be delegated
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("GRANT WRITE_SCHEMA ON root.a TO USER tempuser"));
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("GRANT WRITE_SCHEMA ON root.b.b TO USER tempuser"));

        // 4. Admin grant write_schema, read_schema on root.** to tempuser.
        adminStmt.execute("GRANT WRITE_SCHEMA ON root.** TO USER tempuser WITH GRANT OPTION");
        adminStmt.execute("GRANT READ_SCHEMA ON root.** TO USER tempuser WITH GRANT OPTION");

        // 5. tempuser can grant or revoke his write_schema and read_schema to others or himself.
        userStmt.execute("GRANT WRITE_SCHEMA ON root.t1 TO USER tempuser");
        userStmt.execute("GRANT READ_SCHEMA ON root.t1.t2 TO USER tempuser WITH GRANT OPTION");
        userStmt.execute("REVOKE WRITE_SCHEMA ON root.t1 FROM USER tempuser");
        // tempuser revoke his write_schema privilege
        userStmt.execute("REVOKE WRITE_SCHEMA ON root.** FROM USER tempuser");

        Assert.assertThrows(
            SQLException.class, () -> userStmt.execute("GRANT READ_DATA root.t1 to USER tempuser"));

        // 6. REVOKE ALL will be ok.
        adminStmt.execute("REVOKE ALL on root.** FROM USER tempuser");
        adminStmt.execute("GRANT ALL ON root.** TO USER tempuser");
        adminStmt.execute("REVOKE ALL ON root.** FROM USER tempuser");

        Assert.assertThrows(SQLException.class, () -> userStmt.execute("CREATE DATABASE root.b"));

        // 7. With "WRITE" privilege, tempuser can read,write schema or data.
        adminStmt.execute("GRANT WRITE, MANAGE_DATABASE on root.** TO USER tempuser");
        userStmt.execute("CREATE DATABASE root.c");
        userStmt.execute("CREATE TIMESERIES root.c.d WITH DATATYPE=INT32,ENCODING=PLAIN");
        userStmt.execute("INSERT INTO root.c(timestamp, d) VALUES (100, 100)");
        ResultSet result = userStmt.executeQuery("SELECT * from root.c");
        String ans = "100,100,\n";
        validateResultSet(result, ans);

        adminStmt.execute("REVOKE WRITE, MANAGE_DATABASE on root.** FROM USER tempuser");
        adminStmt.execute("GRANT READ on root.** TO USER tempuser");

        result = userStmt.executeQuery("SELECT * from root.c");
        ans = "100,100,\n";
        validateResultSet(result, ans);

        adminStmt.execute("REVOKE READ on root.** FROM USER tempuser");

        Assert.assertThrows(SQLException.class, () -> userStmt.execute("CREATE DATABASE root.b"));
        Assert.assertThrows(
            SQLException.class,
            () ->
                userStmt.execute("CREATE TIMESERIES root.b.b WITH DATATYPE=INT32,ENCODING=PLAIN"));
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("INSERT INTO root.b(timestamp, b) VALUES (100, 100)"));
        result = userStmt.executeQuery("SELECT * from root.a");
        validateResultSet(result, "");
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("GRANT USER tempuser PRIVILEGES WRITE_SCHEMA ON root.a"));

        adminStmt.execute("GRANT ALL ON root.** TO USER tempuser WITH GRANT OPTION");
        userStmt.execute("CREATE USER testuser 'password'");
        userStmt.execute("GRANT ALL ON root.** TO USER testuser WITH GRANT OPTION");
        ResultSet dataSet = userStmt.executeQuery("LIST PRIVILEGES OF USER testuser");

        Set<String> ansSet =
            new HashSet<>(
                Arrays.asList(
                    ",,MANAGE_USER,true,",
                    ",,MANAGE_ROLE,true,",
                    ",,USE_TRIGGER,true,",
                    ",,USE_UDF,true,",
                    ",,USE_CQ,true,",
                    ",,USE_PIPE,true,",
                    ",,USE_MODEL,true,",
                    ",,EXTEND_TEMPLATE,true,",
                    ",,MANAGE_DATABASE,true,",
                    ",,MAINTAIN,true,",
                    ",root.**,READ_DATA,true,",
                    ",root.**,WRITE_DATA,true,",
                    ",root.**,READ_SCHEMA,true,",
                    ",root.**,WRITE_SCHEMA,true,"));
        TestUtils.assertResultSetEqual(dataSet, "Role,Scope,Privileges,GrantOption,", ansSet);
      }
    }
  }
This is an example for integration test.
integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBAuthIT.java