• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9905

23 Aug 2023 06:20AM UTC coverage: 47.785% (-0.1%) from 47.922%
#9905

push

travis_ci

web-flow
[To rel/1.2][Metric] Fix flush point statistics (#10934)

23 of 23 new or added lines in 1 file covered. (100.0%)

79851 of 167106 relevant lines covered (47.78%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/PermissionManager.java
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.manager;
21

22
import org.apache.iotdb.common.rpc.thrift.TDataNodeConfiguration;
23
import org.apache.iotdb.common.rpc.thrift.TSStatus;
24
import org.apache.iotdb.commons.path.PartialPath;
25
import org.apache.iotdb.confignode.client.DataNodeRequestType;
26
import org.apache.iotdb.confignode.client.sync.SyncDataNodeClientPool;
27
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
28
import org.apache.iotdb.confignode.consensus.request.auth.AuthorPlan;
29
import org.apache.iotdb.confignode.consensus.response.auth.PermissionInfoResp;
30
import org.apache.iotdb.confignode.manager.consensus.ConsensusManager;
31
import org.apache.iotdb.confignode.persistence.AuthorInfo;
32
import org.apache.iotdb.confignode.rpc.thrift.TPermissionInfoResp;
33
import org.apache.iotdb.consensus.exception.ConsensusException;
34
import org.apache.iotdb.mpp.rpc.thrift.TInvalidatePermissionCacheReq;
35
import org.apache.iotdb.rpc.RpcUtils;
36
import org.apache.iotdb.rpc.TSStatusCode;
37

38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

41
import java.util.Collections;
42
import java.util.List;
43

44
/** Manager permission read and operation. */
45
public class PermissionManager {
46

47
  private static final Logger LOGGER = LoggerFactory.getLogger(PermissionManager.class);
×
48

49
  private final ConfigManager configManager;
50
  private final AuthorInfo authorInfo;
51

52
  public PermissionManager(ConfigManager configManager, AuthorInfo authorInfo) {
×
53
    this.configManager = configManager;
×
54
    this.authorInfo = authorInfo;
×
55
  }
×
56

57
  /**
58
   * Write permission.
59
   *
60
   * @param authorPlan AuthorReq
61
   * @return TSStatus
62
   */
63
  public TSStatus operatePermission(AuthorPlan authorPlan) {
64
    TSStatus tsStatus;
65
    // If the permissions change, clear the cache content affected by the operation
66
    try {
67
      if (authorPlan.getAuthorType() == ConfigPhysicalPlanType.CreateUser
×
68
          || authorPlan.getAuthorType() == ConfigPhysicalPlanType.CreateRole) {
×
69
        tsStatus = getConsensusManager().write(authorPlan);
×
70
      } else {
71
        tsStatus = invalidateCache(authorPlan.getUserName(), authorPlan.getRoleName());
×
72
        if (tsStatus.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
×
73
          tsStatus = getConsensusManager().write(authorPlan);
×
74
        }
75
      }
76
      return tsStatus;
×
77
    } catch (ConsensusException e) {
×
78
      LOGGER.warn("Failed in the write API executing the consensus layer due to: ", e);
×
79
      TSStatus res = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
×
80
      res.setMessage(e.getMessage());
×
81
      return res;
×
82
    }
83
  }
84

85
  /**
86
   * Query for permissions.
87
   *
88
   * @param authorPlan AuthorReq
89
   * @return PermissionInfoResp
90
   */
91
  public PermissionInfoResp queryPermission(AuthorPlan authorPlan) {
92
    try {
93
      return (PermissionInfoResp) getConsensusManager().read(authorPlan);
×
94
    } catch (ConsensusException e) {
×
95
      LOGGER.warn("Failed in the read API executing the consensus layer due to: ", e);
×
96
      TSStatus res = new TSStatus(TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode());
×
97
      res.setMessage(e.getMessage());
×
98
      return new PermissionInfoResp(res, Collections.emptyMap());
×
99
    }
100
  }
101

102
  private ConsensusManager getConsensusManager() {
103
    return configManager.getConsensusManager();
×
104
  }
105

106
  public TPermissionInfoResp login(String username, String password) {
107
    return authorInfo.login(username, password);
×
108
  }
109

110
  public TPermissionInfoResp checkUserPrivileges(
111
      String username, List<PartialPath> paths, int permission) {
112
    return authorInfo.checkUserPrivileges(username, paths, permission);
×
113
  }
114

115
  /**
116
   * When the permission information of a user or role is changed will clear all datanode
117
   * permissions related to the user or role.
118
   */
119
  public TSStatus invalidateCache(String username, String roleName) {
120
    List<TDataNodeConfiguration> allDataNodes =
×
121
        configManager.getNodeManager().getRegisteredDataNodes();
×
122
    TInvalidatePermissionCacheReq req = new TInvalidatePermissionCacheReq();
×
123
    TSStatus status;
124
    req.setUsername(username);
×
125
    req.setRoleName(roleName);
×
126
    for (TDataNodeConfiguration dataNodeInfo : allDataNodes) {
×
127
      status =
128
          SyncDataNodeClientPool.getInstance()
×
129
              .sendSyncRequestToDataNodeWithRetry(
×
130
                  dataNodeInfo.getLocation().getInternalEndPoint(),
×
131
                  req,
132
                  DataNodeRequestType.INVALIDATE_PERMISSION_CACHE);
133
      if (status.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
×
134
        return status;
×
135
      }
136
    }
×
137
    return RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS);
×
138
  }
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc