Skip to content

Commit d65fa92

Browse files
authored
Fix author type conversion (#16560)
1 parent ea7e2a6 commit d65fa92

4 files changed

Lines changed: 33 additions & 102 deletions

File tree

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/auth/AuthorInfo.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,22 @@ public AuthorInfo() {
6767
}
6868

6969
public static ConfigPhysicalPlanType getConfigPhysicalPlanTypeFromAuthorType(int authorType) {
70+
if (authorType < 0) {
71+
throw new IndexOutOfBoundsException("Invalid Author Type ordinal");
72+
}
7073
ConfigPhysicalPlanType configPhysicalPlanType;
71-
if (authorType == AuthorType.RENAME_USER.ordinal()) {
72-
configPhysicalPlanType = ConfigPhysicalPlanType.RenameUser;
74+
if (authorType >= AuthorType.RENAME_USER.ordinal()) {
75+
AuthorType type = AuthorType.values()[authorType];
76+
switch (type) {
77+
case RENAME_USER:
78+
return ConfigPhysicalPlanType.RenameUser;
79+
case UPDATE_USER_MAX_SESSION:
80+
return ConfigPhysicalPlanType.UpdateUserMaxSession;
81+
case UPDATE_USER_MIN_SESSION:
82+
return ConfigPhysicalPlanType.UpdateUserMinSession;
83+
default:
84+
throw new IndexOutOfBoundsException("Invalid Author Type ordinal");
85+
}
7386
} else {
7487
configPhysicalPlanType =
7588
ConfigPhysicalPlanType.values()[authorType + ConfigPhysicalPlanType.CreateUser.ordinal()];

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/service/thrift/ConfigNodeRPCServiceProcessor.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@
234234
import org.apache.iotdb.confignode.service.ConfigNode;
235235
import org.apache.iotdb.consensus.exception.ConsensusException;
236236
import org.apache.iotdb.db.queryengine.plan.relational.type.AuthorRType;
237-
import org.apache.iotdb.db.queryengine.plan.statement.AuthorType;
238237
import org.apache.iotdb.rpc.RpcUtils;
239238
import org.apache.iotdb.rpc.TSStatusCode;
240239

@@ -633,9 +632,6 @@ public TDataPartitionTableResp getOrCreateDataPartitionTable(TDataPartitionReq r
633632

634633
@Override
635634
public TSStatus operatePermission(final TAuthorizerReq req) {
636-
if (req.getAuthorType() < 0 || req.getAuthorType() >= AuthorType.values().length) {
637-
throw new IndexOutOfBoundsException("Invalid Author Type ordinal");
638-
}
639635
ConfigPhysicalPlanType configPhysicalPlanType =
640636
AuthorInfo.getConfigPhysicalPlanTypeFromAuthorType(req.getAuthorType());
641637
return configManager.operatePermission(
@@ -654,9 +650,6 @@ public TSStatus operatePermission(final TAuthorizerReq req) {
654650

655651
@Override
656652
public TAuthorizerResp queryPermission(final TAuthorizerReq req) {
657-
if (req.getAuthorType() < 0 || req.getAuthorType() >= AuthorType.values().length) {
658-
throw new IndexOutOfBoundsException("Invalid Author Type ordinal");
659-
}
660653
final PermissionInfoResp dataSet =
661654
(PermissionInfoResp)
662655
configManager.queryPermission(

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/type/AuthorRType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package org.apache.iotdb.db.queryengine.plan.relational.type;
2020

21+
// When adding new types that need to be converted to ConfigPhysicalPlanType, you can refer to this
22+
// document:
23+
// https://docs.google.com/document/d/1WvAyuLn1y988svLl8rGUEcesMkAyH6UTT597KQAVm1A/edit?usp=sharing
2124
public enum AuthorRType {
2225
CREATE_USER,
2326
CREATE_ROLE,
@@ -50,6 +53,8 @@ public enum AuthorRType {
5053
LIST_ROLE,
5154
LIST_USER_PRIV,
5255
LIST_ROLE_PRIV,
56+
UPDATE_MAX_USER_SESSION,
57+
UPDATE_MIN_USER_SESSION,
5358
// Remind to renew the convert codes in ConfigNodeRPCServiceProcessor
5459
RENAME_USER,
5560
ACCOUNT_UNLOCK

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/AuthorType.java

Lines changed: 13 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919

2020
package org.apache.iotdb.db.queryengine.plan.statement;
2121

22+
// If you need to add a new type, you need to add it to the end because the ordinal will be used as
23+
// offset to calculate ConfigPhysicalPlanType
24+
// When adding new types that need to be converted to ConfigPhysicalPlanType, you can refer to this
25+
// document:
26+
// https://docs.google.com/document/d/1WvAyuLn1y988svLl8rGUEcesMkAyH6UTT597KQAVm1A/edit?usp=sharing
2227
public enum AuthorType {
28+
// The ConfigPhysicalPlanType in this part can be automatically converted according to the offset
29+
// in this class
2330
CREATE_USER,
2431
CREATE_ROLE,
2532
DROP_USER,
@@ -35,101 +42,14 @@ public enum AuthorType {
3542
LIST_ROLE,
3643
LIST_USER_PRIVILEGE,
3744
LIST_ROLE_PRIVILEGE,
45+
3846
ACCOUNT_UNLOCK,
47+
3948
// Remind to renew the convert codes in ConfigNodeRPCServiceProcessor
49+
// If the config node plan is involved, the type defined in following lines needs to manually add
50+
// conversion logic
4051
RENAME_USER,
52+
UPDATE_USER_MAX_SESSION,
53+
UPDATE_USER_MIN_SESSION,
4154
;
42-
43-
/**
44-
* deserialize short number.
45-
*
46-
* @param i short number
47-
* @return NamespaceType
48-
*/
49-
public static AuthorType deserialize(short i) {
50-
switch (i) {
51-
case 0:
52-
return CREATE_USER;
53-
case 1:
54-
return CREATE_ROLE;
55-
case 2:
56-
return DROP_USER;
57-
case 3:
58-
return DROP_ROLE;
59-
case 4:
60-
return GRANT_ROLE;
61-
case 5:
62-
return GRANT_USER;
63-
case 6:
64-
return GRANT_USER_ROLE;
65-
case 7:
66-
return REVOKE_USER;
67-
case 8:
68-
return REVOKE_ROLE;
69-
case 9:
70-
return REVOKE_USER_ROLE;
71-
case 10:
72-
return UPDATE_USER;
73-
case 11:
74-
return LIST_USER;
75-
case 12:
76-
return LIST_ROLE;
77-
case 13:
78-
return LIST_USER_PRIVILEGE;
79-
case 14:
80-
return LIST_ROLE_PRIVILEGE;
81-
case 15:
82-
return RENAME_USER;
83-
case 16:
84-
return ACCOUNT_UNLOCK;
85-
default:
86-
return null;
87-
}
88-
}
89-
90-
/**
91-
* serialize.
92-
*
93-
* @return short number
94-
*/
95-
public short serialize() {
96-
switch (this) {
97-
case CREATE_USER:
98-
return 0;
99-
case CREATE_ROLE:
100-
return 1;
101-
case DROP_USER:
102-
return 2;
103-
case DROP_ROLE:
104-
return 3;
105-
case GRANT_ROLE:
106-
return 4;
107-
case GRANT_USER:
108-
return 5;
109-
case GRANT_USER_ROLE:
110-
return 6;
111-
case REVOKE_USER:
112-
return 7;
113-
case REVOKE_ROLE:
114-
return 8;
115-
case REVOKE_USER_ROLE:
116-
return 9;
117-
case UPDATE_USER:
118-
return 10;
119-
case LIST_USER:
120-
return 11;
121-
case LIST_ROLE:
122-
return 12;
123-
case LIST_USER_PRIVILEGE:
124-
return 13;
125-
case LIST_ROLE_PRIVILEGE:
126-
return 14;
127-
case RENAME_USER:
128-
return 15;
129-
case ACCOUNT_UNLOCK:
130-
return 16;
131-
default:
132-
return -1;
133-
}
134-
}
13555
}

0 commit comments

Comments
 (0)