Skip to content

Commit 4ebfe9e

Browse files
Append user index field for User (#16432)
1 parent 0e2f911 commit 4ebfe9e

File tree

37 files changed

+555
-118
lines changed

37 files changed

+555
-118
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ public void listUser(CloseableHttpClient httpClient) {
13991399
List<Object> columnNames =
14001400
new ArrayList<Object>() {
14011401
{
1402+
add(ColumnHeaderConstant.USER_ID);
14021403
add(ColumnHeaderConstant.USER);
14031404
}
14041405
};
@@ -1409,7 +1410,7 @@ public void listUser(CloseableHttpClient httpClient) {
14091410
}
14101411
};
14111412
Assert.assertEquals(columnNames, columnNamesResult);
1412-
Assert.assertEquals(values1, valuesResult.get(0));
1413+
Assert.assertEquals(values1, valuesResult.get(1));
14131414
}
14141415

14151416
public void selectCount(CloseableHttpClient httpClient) {
@@ -2062,6 +2063,7 @@ public void listUserV2(CloseableHttpClient httpClient) {
20622063
List<Object> columnNames =
20632064
new ArrayList<Object>() {
20642065
{
2066+
add(ColumnHeaderConstant.USER_ID);
20652067
add(ColumnHeaderConstant.USER);
20662068
}
20672069
};
@@ -2072,7 +2074,7 @@ public void listUserV2(CloseableHttpClient httpClient) {
20722074
}
20732075
};
20742076
Assert.assertEquals(columnNames, columnNamesResult);
2075-
Assert.assertEquals(values1, valuesResult.get(0));
2077+
Assert.assertEquals(values1, valuesResult.get(1));
20762078
}
20772079

20782080
public void selectCountV2(CloseableHttpClient httpClient) {

integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBAuthIT.java

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public void allPrivilegesTest() throws SQLException {
9999

100100
ResultSet resultSet = userStmt.executeQuery("LIST USER");
101101
Assert.assertTrue(resultSet.next());
102-
Assert.assertEquals("tempuser", resultSet.getString(1));
102+
Assert.assertEquals("10000", resultSet.getString(1));
103+
Assert.assertEquals("tempuser", resultSet.getString(2));
103104
Assert.assertFalse(resultSet.next());
104105

105106
resultSet = userStmt.executeQuery("LIST PRIVILEGES OF USER tempuser");
@@ -469,7 +470,7 @@ public void testListUser() throws SQLException {
469470

470471
try {
471472
ResultSet resultSet = adminStmt.executeQuery("LIST USER");
472-
String ans = "root,\n";
473+
String ans = "0,root,\n";
473474
try {
474475
validateResultSet(resultSet, ans);
475476

@@ -478,17 +479,17 @@ public void testListUser() throws SQLException {
478479
}
479480
resultSet = adminStmt.executeQuery("LIST USER");
480481
ans =
481-
"root,\n"
482-
+ "user0,\n"
483-
+ "user1,\n"
484-
+ "user2,\n"
485-
+ "user3,\n"
486-
+ "user4,\n"
487-
+ "user5,\n"
488-
+ "user6,\n"
489-
+ "user7,\n"
490-
+ "user8,\n"
491-
+ "user9,\n";
482+
"0,root,\n"
483+
+ "10000,user0,\n"
484+
+ "10001,user1,\n"
485+
+ "10002,user2,\n"
486+
+ "10003,user3,\n"
487+
+ "10004,user4,\n"
488+
+ "10005,user5,\n"
489+
+ "10006,user6,\n"
490+
+ "10007,user7,\n"
491+
+ "10008,user8,\n"
492+
+ "10009,user9,\n";
492493
validateResultSet(resultSet, ans);
493494

494495
for (int i = 0; i < 10; i++) {
@@ -497,7 +498,13 @@ public void testListUser() throws SQLException {
497498
}
498499
}
499500
resultSet = adminStmt.executeQuery("LIST USER");
500-
ans = "root,\n" + "user1,\n" + "user3,\n" + "user5,\n" + "user7,\n" + "user9,\n";
501+
ans =
502+
"0,root,\n"
503+
+ "10001,user1,\n"
504+
+ "10003,user3,\n"
505+
+ "10005,user5,\n"
506+
+ "10007,user7,\n"
507+
+ "10009,user9,\n";
501508
validateResultSet(resultSet, ans);
502509
} finally {
503510
resultSet.close();
@@ -581,7 +588,7 @@ public void testListUserRole() throws SQLException {
581588
ans = "role1,\nrole2,\n";
582589
validateResultSet(resultSet, ans);
583590
resultSet = userStmt.executeQuery("LIST USER OF ROLE role1");
584-
ans = "user1,\nuser2,\n";
591+
ans = "10000,user1,\n10001,user2,\n";
585592
validateResultSet(resultSet, ans);
586593
} finally {
587594
userStmt.close();
@@ -764,25 +771,25 @@ public void testListRoleUsers() throws SQLException {
764771

765772
ResultSet resultSet = adminStmt.executeQuery("LIST USER OF ROLE dalao");
766773
String ans =
767-
"DailySecurity,\n"
768-
+ "DoubleLight,\n"
769-
+ "East,\n"
770-
+ "Eastwards,\n"
771-
+ "GoldLuck,\n"
772-
+ "GoodWoods,\n"
773-
+ "HealthHonor,\n"
774-
+ "HighFly,\n"
775-
+ "Moon,\n"
776-
+ "Persistence,\n"
777-
+ "RayBud,\n"
778-
+ "ScentEffusion,\n"
779-
+ "Smart,\n"
780-
+ "SunComparison,\n";
774+
"10011,DailySecurity,\n"
775+
+ "10006,DoubleLight,\n"
776+
+ "10010,East,\n"
777+
+ "10007,Eastwards,\n"
778+
+ "10005,GoldLuck,\n"
779+
+ "10003,GoodWoods,\n"
780+
+ "10004,HealthHonor,\n"
781+
+ "10000,HighFly,\n"
782+
+ "10012,Moon,\n"
783+
+ "10002,Persistence,\n"
784+
+ "10013,RayBud,\n"
785+
+ "10008,ScentEffusion,\n"
786+
+ "10009,Smart,\n"
787+
+ "10001,SunComparison,\n";
781788
try {
782789
validateResultSet(resultSet, ans);
783790

784791
resultSet = adminStmt.executeQuery("LIST USER OF ROLE zhazha");
785-
ans = "RiverSky,\n";
792+
ans = "10014,RiverSky,\n";
786793
validateResultSet(resultSet, ans);
787794

788795
adminStmt.execute("REVOKE ROLE zhazha from RiverSky");
@@ -837,25 +844,25 @@ public void testListUserPrivilege() throws SQLException {
837844
try (Connection userCon = EnvFactory.getEnv().getConnection("tempuser", "temppw123456");
838845
Statement userStmt = userCon.createStatement()) {
839846
try {
840-
String ans = "tempuser,\n";
847+
String ans = "10010,tempuser,\n";
841848
ResultSet resultSet = userStmt.executeQuery("LIST USER");
842849
validateResultSet(resultSet, ans);
843850
// with list user privilege
844851
adminStmt.execute("GRANT SECURITY on root.** TO USER tempuser");
845852
resultSet = userStmt.executeQuery("LIST USER");
846853
ans =
847-
"root,\n"
848-
+ "tempuser,\n"
849-
+ "user0,\n"
850-
+ "user1,\n"
851-
+ "user2,\n"
852-
+ "user3,\n"
853-
+ "user4,\n"
854-
+ "user5,\n"
855-
+ "user6,\n"
856-
+ "user7,\n"
857-
+ "user8,\n"
858-
+ "user9,\n";
854+
"0,root,\n"
855+
+ "10010,tempuser,\n"
856+
+ "10000,user0,\n"
857+
+ "10001,user1,\n"
858+
+ "10002,user2,\n"
859+
+ "10003,user3,\n"
860+
+ "10004,user4,\n"
861+
+ "10005,user5,\n"
862+
+ "10006,user6,\n"
863+
+ "10007,user7,\n"
864+
+ "10008,user8,\n"
865+
+ "10009,user9,\n";
859866
validateResultSet(resultSet, ans);
860867
} finally {
861868
userStmt.close();

integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBRelationalAuthIT.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public void listUserPrivileges() throws SQLException {
7272
Statement userStmt = userCon.createStatement()) {
7373
ResultSet resultSet = userStmt.executeQuery("LIST USER");
7474
Assert.assertTrue(resultSet.next());
75-
Assert.assertEquals("testuser", resultSet.getString(1));
75+
Assert.assertEquals("10000", resultSet.getString(1));
76+
Assert.assertEquals("testuser", resultSet.getString(2));
7677
Assert.assertFalse(resultSet.next());
7778
}
7879
adminStmt.execute("create database testdb");
@@ -136,7 +137,7 @@ public void listUserPrivileges() throws SQLException {
136137
adminStmt.execute("create role testrole");
137138
adminStmt.execute("GRANT ROLE testrole to testuser");
138139
rs = adminStmt.executeQuery("LIST USER OF ROLE testrole");
139-
TestUtils.assertResultSetEqual(rs, "User,", Collections.singleton("testuser,"));
140+
TestUtils.assertResultSetEqual(rs, "UserId,User,", Collections.singleton("10000,testuser,"));
140141
rs = adminStmt.executeQuery("LIST ROLE OF USER testuser");
141142
TestUtils.assertResultSetEqual(rs, "Role,", Collections.singleton("testrole,"));
142143
}
@@ -533,11 +534,11 @@ public void testCreateUserAndRole() throws SQLException {
533534

534535
ResultSet resultSet = adminStmt.executeQuery("List user");
535536
Set<String> resultSetList = new HashSet<>();
536-
resultSetList.add("root,");
537-
resultSetList.add("testuser,");
538-
resultSetList.add("!@#$%^*()_+-=1,");
539-
resultSetList.add("!@#$%^*()_+-=2,");
540-
TestUtils.assertResultSetEqual(resultSet, "User,", resultSetList);
537+
resultSetList.add("0,root,");
538+
resultSetList.add("10000,testuser,");
539+
resultSetList.add("10001,!@#$%^*()_+-=1,");
540+
resultSetList.add("10002,!@#$%^*()_+-=2,");
541+
TestUtils.assertResultSetEqual(resultSet, "UserId,User,", resultSetList);
541542
resultSet = adminStmt.executeQuery("List role");
542543
TestUtils.assertResultSetEqual(resultSet, "Role,", Collections.singleton("!@#$%^*()_+-=3,"));
543544
adminStmt.execute("GRANT role \"!@#$%^*()_+-=3\" to \"!@#$%^*()_+-=1\"");

integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipeMetaHistoricalIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public void testAuthInclusion() throws Exception {
230230
TestUtils.assertDataEventuallyOnEnv(
231231
receiverEnv,
232232
"list user of role `admin`",
233-
ColumnHeaderConstant.USER + ",",
234-
Collections.singleton("thulab,"));
233+
ColumnHeaderConstant.USER_ID + "," + ColumnHeaderConstant.USER + ",",
234+
Collections.singleton("10000,thulab,"));
235235
TestUtils.assertDataEventuallyOnEnv(
236236
receiverEnv,
237237
"list privileges of role `admin`",

integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/manual/IoTDBPipePermissionIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ private void testWithSink(final String sink) throws Exception {
147147
TestUtils.assertDataEventuallyOnEnv(
148148
receiverEnv,
149149
"list user",
150-
"User,",
151-
new HashSet<>(Arrays.asList("root,", "user,", "thulab,")));
150+
"UserId,User,",
151+
new HashSet<>(Arrays.asList("0,root,", "10001,user,", "10000,thulab,")));
152152
final Set<String> expectedResSet = new HashSet<>();
153153
expectedResSet.add(
154154
"root.ln.wf02.wt01.temperature,null,root.ln,INT64,PLAIN,LZ4,null,null,null,null,BASE,");

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/consensus/response/auth/PermissionInfoResp.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.iotdb.confignode.consensus.response.auth;
2121

2222
import org.apache.iotdb.common.rpc.thrift.TSStatus;
23+
import org.apache.iotdb.confignode.rpc.thrift.TListUserInfo;
2324
import org.apache.iotdb.confignode.rpc.thrift.TPermissionInfoResp;
2425
import org.apache.iotdb.consensus.common.DataSet;
2526

@@ -32,6 +33,8 @@ public class PermissionInfoResp implements DataSet {
3233
private String tag;
3334
private List<String> memberList;
3435

36+
private List<TListUserInfo> usersInfo;
37+
3538
private TPermissionInfoResp permissionInfoResp;
3639

3740
public PermissionInfoResp() {}
@@ -62,6 +65,14 @@ public List<String> getMemberList() {
6265
return memberList;
6366
}
6467

68+
public void setUsersInfo(List<TListUserInfo> usersInfo) {
69+
this.usersInfo = usersInfo;
70+
}
71+
72+
public List<TListUserInfo> getUsersInfo() {
73+
return usersInfo;
74+
}
75+
6576
public TPermissionInfoResp getPermissionInfoResp() {
6677
return permissionInfoResp;
6778
}

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,8 @@ public TPermissionInfoResp checkRoleOfUser(String username, String rolename)
141141
public TPermissionInfoResp getUser(String username) throws AuthException {
142142
return authorInfo.getUser(username);
143143
}
144+
145+
public String getUserName(long userId) throws AuthException {
146+
return authorInfo.getUserName(userId);
147+
}
144148
}

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/event/PipeConfigRegionSnapshotEvent.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class PipeConfigRegionSnapshotEvent extends PipeSnapshotEvent
6060
SNAPSHOT_FILE_TYPE_2_CONFIG_PHYSICAL_PLAN_TYPE_MAP = new EnumMap<>(CNSnapshotFileType.class);
6161
private CNSnapshotFileType fileType;
6262

63+
private String authUserName = "";
64+
6365
static {
6466
SNAPSHOT_FILE_TYPE_2_CONFIG_PHYSICAL_PLAN_TYPE_MAP.put(
6567
CNSnapshotFileType.ROLE,
@@ -136,6 +138,14 @@ public PipeConfigRegionSnapshotEvent(
136138
this.fileType = type;
137139
}
138140

141+
public String getAuthUserName() {
142+
return authUserName;
143+
}
144+
145+
public void setAuthUserName(String authUserName) {
146+
this.authUserName = authUserName;
147+
}
148+
139149
public File getSnapshotFile() {
140150
return new File(snapshotPath);
141151
}
@@ -195,17 +205,20 @@ public EnrichedEvent shallowCopySelfAndBindPipeTaskMetaForProgressReport(
195205
final boolean skipIfNoPrivileges,
196206
final long startTime,
197207
final long endTime) {
198-
return new PipeConfigRegionSnapshotEvent(
199-
snapshotPath,
200-
templateFilePath,
201-
fileType,
202-
pipeName,
203-
creationTime,
204-
pipeTaskMeta,
205-
treePattern,
206-
tablePattern,
207-
userName,
208-
skipIfNoPrivileges);
208+
PipeConfigRegionSnapshotEvent pipeConfigRegionSnapshotEvent =
209+
new PipeConfigRegionSnapshotEvent(
210+
snapshotPath,
211+
templateFilePath,
212+
fileType,
213+
pipeName,
214+
creationTime,
215+
pipeTaskMeta,
216+
treePattern,
217+
tablePattern,
218+
userName,
219+
skipIfNoPrivileges);
220+
pipeConfigRegionSnapshotEvent.setAuthUserName(authUserName);
221+
return pipeConfigRegionSnapshotEvent;
209222
}
210223

211224
@Override

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/receiver/protocol/IoTDBConfigNodeReceiver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,8 @@ protected TSStatus loadFileV2(
10331033
Paths.get(fileAbsolutePaths.get(0)),
10341034
fileAbsolutePaths.size() > 1 ? Paths.get(fileAbsolutePaths.get(1)) : null,
10351035
CNSnapshotFileType.deserialize(
1036-
Byte.parseByte(parameters.get(PipeTransferConfigSnapshotSealReq.FILE_TYPE))));
1036+
Byte.parseByte(parameters.get(PipeTransferConfigSnapshotSealReq.FILE_TYPE))),
1037+
parameters.getOrDefault("authUserName", ""));
10371038
if (Objects.isNull(generator)) {
10381039
throw new IOException(
10391040
String.format("The config region snapshots %s cannot be parsed.", fileAbsolutePaths));

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/sink/payload/PipeTransferConfigSnapshotSealReq.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public static PipeTransferConfigSnapshotSealReq toTPipeTransferReq(
5858
final String templateFileName,
5959
final long templateFileLength,
6060
final CNSnapshotFileType fileType,
61-
final String typeString)
61+
final String typeString,
62+
final String authUserName)
6263
throws IOException {
6364
final Map<String, String> parameters = new HashMap<>();
6465
parameters.put(ColumnHeaderConstant.PATH_PATTERN, treePattern);
@@ -72,6 +73,7 @@ public static PipeTransferConfigSnapshotSealReq toTPipeTransferReq(
7273
}
7374
parameters.put(FILE_TYPE, Byte.toString(fileType.getType()));
7475
parameters.put(ColumnHeaderConstant.TYPE, typeString);
76+
parameters.put("authUserName", authUserName);
7577

7678
return (PipeTransferConfigSnapshotSealReq)
7779
new PipeTransferConfigSnapshotSealReq()
@@ -103,7 +105,8 @@ public static byte[] toTPipeTransferBytes(
103105
final String templateFileName,
104106
final long templateFileLength,
105107
final CNSnapshotFileType fileType,
106-
final String typeString)
108+
final String typeString,
109+
final String authUserName)
107110
throws IOException {
108111
final Map<String, String> parameters = new HashMap<>();
109112
parameters.put(ColumnHeaderConstant.PATH_PATTERN, treePattern);
@@ -117,6 +120,7 @@ public static byte[] toTPipeTransferBytes(
117120
}
118121
parameters.put(FILE_TYPE, Byte.toString(fileType.getType()));
119122
parameters.put(ColumnHeaderConstant.TYPE, typeString);
123+
parameters.put("authUserName", authUserName);
120124
return new PipeTransferConfigSnapshotSealReq()
121125
.convertToTPipeTransferSnapshotSealBytes(
122126
Objects.nonNull(templateFileName)

0 commit comments

Comments
 (0)