Skip to content

Commit 13afc03

Browse files
authored
Add IAuthorPlanExecutor
1 parent 0507203 commit 13afc03

File tree

9 files changed

+320
-140
lines changed

9 files changed

+320
-140
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@
123123
import org.apache.iotdb.confignode.manager.schema.ClusterSchemaManager;
124124
import org.apache.iotdb.confignode.manager.schema.ClusterSchemaQuotaStatistics;
125125
import org.apache.iotdb.confignode.manager.subscription.SubscriptionManager;
126-
import org.apache.iotdb.confignode.persistence.AuthorInfo;
127126
import org.apache.iotdb.confignode.persistence.ClusterInfo;
128127
import org.apache.iotdb.confignode.persistence.ModelInfo;
129128
import org.apache.iotdb.confignode.persistence.ProcedureInfo;
130129
import org.apache.iotdb.confignode.persistence.TTLInfo;
131130
import org.apache.iotdb.confignode.persistence.TriggerInfo;
132131
import org.apache.iotdb.confignode.persistence.UDFInfo;
132+
import org.apache.iotdb.confignode.persistence.auth.AuthorInfo;
133133
import org.apache.iotdb.confignode.persistence.cq.CQInfo;
134134
import org.apache.iotdb.confignode.persistence.executor.ConfigPlanExecutor;
135135
import org.apache.iotdb.confignode.persistence.node.NodeInfo;
@@ -368,7 +368,7 @@ public ConfigManager() throws IOException {
368368
NodeInfo nodeInfo = new NodeInfo();
369369
ClusterSchemaInfo clusterSchemaInfo = new ClusterSchemaInfo();
370370
PartitionInfo partitionInfo = new PartitionInfo();
371-
AuthorInfo authorInfo = new AuthorInfo(this);
371+
AuthorInfo authorInfo = new AuthorInfo();
372372
ProcedureInfo procedureInfo = new ProcedureInfo(this);
373373
UDFInfo udfInfo = new UDFInfo();
374374
TriggerInfo triggerInfo = new TriggerInfo();
@@ -1356,7 +1356,7 @@ public TAuthizedPatternTreeResp fetchAuthizedPatternTree(String username, int pe
13561356
TSStatus status = confirmLeader();
13571357
if (status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
13581358
try {
1359-
return permissionManager.fetchAuthizedPTree(username, permission);
1359+
return permissionManager.fetchAuthorizedPTree(username, permission);
13601360
} catch (AuthException e) {
13611361
TAuthizedPatternTreeResp resp = new TAuthizedPatternTreeResp();
13621362
status.setCode(e.getCode().getStatusCode()).setMessage(e.getMessage());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.iotdb.confignode.consensus.request.write.pipe.payload.PipeEnrichedPlan;
2929
import org.apache.iotdb.confignode.consensus.response.auth.PermissionInfoResp;
3030
import org.apache.iotdb.confignode.manager.consensus.ConsensusManager;
31-
import org.apache.iotdb.confignode.persistence.AuthorInfo;
31+
import org.apache.iotdb.confignode.persistence.auth.AuthorInfo;
3232
import org.apache.iotdb.confignode.rpc.thrift.TAuthizedPatternTreeResp;
3333
import org.apache.iotdb.confignode.rpc.thrift.TPermissionInfoResp;
3434
import org.apache.iotdb.consensus.exception.ConsensusException;
@@ -122,7 +122,7 @@ public TPermissionInfoResp checkUserPrivileges(String username, PrivilegeUnion u
122122
return authorInfo.checkUserPrivileges(username, union);
123123
}
124124

125-
public TAuthizedPatternTreeResp fetchAuthizedPTree(String username, int permission)
125+
public TAuthizedPatternTreeResp fetchAuthorizedPTree(String username, int permission)
126126
throws AuthException {
127127
return authorInfo.generateAuthorizedPTree(username, permission);
128128
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.confignode.persistence.auth;
21+
22+
import org.apache.iotdb.common.rpc.thrift.TSStatus;
23+
import org.apache.iotdb.commons.auth.AuthException;
24+
import org.apache.iotdb.commons.auth.authorizer.BasicAuthorizer;
25+
import org.apache.iotdb.commons.auth.authorizer.IAuthorizer;
26+
import org.apache.iotdb.commons.auth.entity.ModelType;
27+
import org.apache.iotdb.commons.auth.entity.PrivilegeUnion;
28+
import org.apache.iotdb.commons.conf.CommonConfig;
29+
import org.apache.iotdb.commons.conf.CommonDescriptor;
30+
import org.apache.iotdb.commons.snapshot.SnapshotProcessor;
31+
import org.apache.iotdb.commons.utils.FileUtils;
32+
import org.apache.iotdb.commons.utils.TestOnly;
33+
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorPlan;
34+
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorRelationalPlan;
35+
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorTreePlan;
36+
import org.apache.iotdb.confignode.consensus.response.auth.PermissionInfoResp;
37+
import org.apache.iotdb.confignode.rpc.thrift.TAuthizedPatternTreeResp;
38+
import org.apache.iotdb.confignode.rpc.thrift.TPermissionInfoResp;
39+
40+
import org.apache.thrift.TException;
41+
import org.slf4j.Logger;
42+
import org.slf4j.LoggerFactory;
43+
44+
import java.io.File;
45+
import java.io.IOException;
46+
47+
public class AuthorInfo implements SnapshotProcessor {
48+
49+
// Works at config node.
50+
private static final Logger LOGGER = LoggerFactory.getLogger(AuthorInfo.class);
51+
public static final CommonConfig COMMON_CONFIG = CommonDescriptor.getInstance().getConfig();
52+
public static final String NO_USER_MSG = "No such user : ";
53+
54+
private IAuthorizer authorizer;
55+
private volatile AuthorPlanExecutor authorPlanExecutor;
56+
57+
public AuthorInfo() {
58+
try {
59+
authorizer = BasicAuthorizer.getInstance();
60+
authorPlanExecutor = new AuthorPlanExecutor(authorizer);
61+
} catch (AuthException e) {
62+
LOGGER.error("get user or role permissionInfo failed because ", e);
63+
}
64+
}
65+
66+
public void setAuthorQueryPlanExecutor(AuthorPlanExecutor authorPlanExecutor) {
67+
this.authorPlanExecutor = authorPlanExecutor;
68+
}
69+
70+
public TPermissionInfoResp login(String username, String password) {
71+
return authorPlanExecutor.login(username, password);
72+
}
73+
74+
public String login4Pipe(final String username, final String password) {
75+
return authorPlanExecutor.login4Pipe(username, password);
76+
}
77+
78+
public TPermissionInfoResp checkUserPrivileges(String username, PrivilegeUnion union) {
79+
return authorPlanExecutor.checkUserPrivileges(username, union);
80+
}
81+
82+
public TSStatus authorNonQuery(AuthorPlan authorPlan) {
83+
if (authorPlan instanceof AuthorTreePlan) {
84+
return authorNonQuery((AuthorTreePlan) authorPlan);
85+
} else {
86+
return authorNonQuery((AuthorRelationalPlan) authorPlan);
87+
}
88+
}
89+
90+
public TSStatus authorNonQuery(AuthorTreePlan authorPlan) {
91+
return authorPlanExecutor.executeAuthorNonQuery(authorPlan);
92+
}
93+
94+
public TSStatus authorNonQuery(AuthorRelationalPlan authorPlan) {
95+
return authorPlanExecutor.executeRelationalAuthorNonQuery(authorPlan);
96+
}
97+
98+
public PermissionInfoResp executeListUsers(final AuthorPlan plan) throws AuthException {
99+
return authorPlanExecutor.executeListUsers(plan);
100+
}
101+
102+
public PermissionInfoResp executeListRoles(final AuthorPlan plan) throws AuthException {
103+
return authorPlanExecutor.executeListRoles(plan);
104+
}
105+
106+
public PermissionInfoResp executeListRolePrivileges(final AuthorPlan plan) throws AuthException {
107+
return authorPlanExecutor.executeListRolePrivileges(plan);
108+
}
109+
110+
public PermissionInfoResp executeListUserPrivileges(final AuthorPlan plan) throws AuthException {
111+
return authorPlanExecutor.executeListUserPrivileges(plan);
112+
}
113+
114+
public TAuthizedPatternTreeResp generateAuthorizedPTree(String username, int permission)
115+
throws AuthException {
116+
return authorPlanExecutor.generateAuthorizedPTree(username, permission);
117+
}
118+
119+
public TPermissionInfoResp checkRoleOfUser(String username, String roleName)
120+
throws AuthException {
121+
return authorPlanExecutor.checkRoleOfUser(username, roleName);
122+
}
123+
124+
public TPermissionInfoResp getUser(String username) throws AuthException {
125+
return authorPlanExecutor.getUser(username);
126+
}
127+
128+
public String getUserName(long userId) throws AuthException {
129+
return authorPlanExecutor.getUserName(userId);
130+
}
131+
132+
@Override
133+
public boolean processTakeSnapshot(File snapshotDir) throws TException, IOException {
134+
return authorizer.processTakeSnapshot(snapshotDir);
135+
}
136+
137+
@Override
138+
public void processLoadSnapshot(File snapshotDir) throws TException, IOException {
139+
authorizer.processLoadSnapshot(snapshotDir);
140+
}
141+
142+
/**
143+
* Save the user's permission information,Bring back the DataNode for caching
144+
*
145+
* @param username The username of the user that needs to be cached
146+
*/
147+
public TPermissionInfoResp getUserPermissionInfo(String username, ModelType type)
148+
throws AuthException {
149+
return authorPlanExecutor.getUserPermissionInfo(username, type);
150+
}
151+
152+
@TestOnly
153+
public void clear() throws AuthException {
154+
File userFolder = new File(COMMON_CONFIG.getUserFolder());
155+
if (userFolder.exists()) {
156+
FileUtils.deleteFileOrDirectory(userFolder);
157+
}
158+
File roleFolder = new File(COMMON_CONFIG.getRoleFolder());
159+
if (roleFolder.exists()) {
160+
FileUtils.deleteFileOrDirectory(roleFolder);
161+
}
162+
authorizer.reset();
163+
}
164+
}

0 commit comments

Comments
 (0)