Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Caideyipi committed Jan 26, 2025
1 parent bc142e5 commit a3a0334
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,13 @@ public class ConfigRegionListeningFilter {
new PartialPath("auth.role.grant.table"),
Collections.unmodifiableList(
Arrays.asList(
ConfigPhysicalPlanType.RGrantUserAll,
ConfigPhysicalPlanType.RGrantUserAny,
ConfigPhysicalPlanType.RGrantUserDBPriv,
ConfigPhysicalPlanType.RGrantUserTBPriv)));
OPTION_PLAN_MAP.put(
new PartialPath("auth.role.revoke.table"),
Collections.unmodifiableList(
Arrays.asList(
ConfigPhysicalPlanType.RRevokeUserAll,
ConfigPhysicalPlanType.RRevokeUserAny,
ConfigPhysicalPlanType.RRevokeUserDBPriv,
ConfigPhysicalPlanType.RRevokeUserTBPriv)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class IoTDBConfigRegionExtractor extends IoTDBNonDataRegionExtractor {
new PipeConfigPhysicalPlanTablePatternParseVisitor();
public static final PipeConfigPhysicalPlanTreeScopeParseVisitor TREE_SCOPE_PARSE_VISITOR =
new PipeConfigPhysicalPlanTreeScopeParseVisitor();
public static final PipeConfigPhysicalPlanTableScopeParseVisitor TABLE_SCOPE_PARSE_VISITOR =
new PipeConfigPhysicalPlanTableScopeParseVisitor();

private Set<ConfigPhysicalPlanType> listenedTypeSet = new HashSet<>();

Expand Down Expand Up @@ -159,6 +161,15 @@ public static Optional<ConfigPhysicalPlan> parseConfigPlan(
}
if (!treePattern.isTreeModelDataAllowedToBeCaptured() && result.isPresent()) {
result = TREE_SCOPE_PARSE_VISITOR.process(result.get(), null);
if (!result.isPresent()) {
return result;
}
}
if (!tablePattern.isTableModelDataAllowedToBeCaptured() && result.isPresent()) {
result = TABLE_SCOPE_PARSE_VISITOR.process(result.get(), null);
if (!result.isPresent()) {
return result;
}
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.confignode.manager.pipe.extractor;

import org.apache.iotdb.commons.auth.entity.PrivilegeType;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlan;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType;
import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanVisitor;
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorRelationalPlan;
import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorTreePlan;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

public class PipeConfigPhysicalPlanTableScopeParseVisitor
extends ConfigPhysicalPlanVisitor<Optional<ConfigPhysicalPlan>, Void> {
@Override
public Optional<ConfigPhysicalPlan> visitPlan(final ConfigPhysicalPlan plan, final Void context) {
return Optional.of(plan);
}

@Override
public Optional<ConfigPhysicalPlan> visitRGrantUserAll(
final AuthorRelationalPlan plan, final Void context) {
return visitTableAuthorPlan(plan, ConfigPhysicalPlanType.GrantUser);
}

@Override
public Optional<ConfigPhysicalPlan> visitRGrantRoleAll(
final AuthorRelationalPlan plan, final Void context) {
return visitTableAuthorPlan(plan, ConfigPhysicalPlanType.GrantRole);
}

@Override
public Optional<ConfigPhysicalPlan> visitRRevokeUserAll(
final AuthorRelationalPlan plan, final Void context) {
return visitTableAuthorPlan(plan, ConfigPhysicalPlanType.RevokeUser);
}

@Override
public Optional<ConfigPhysicalPlan> visitRRevokeRoleAll(
final AuthorRelationalPlan plan, final Void context) {
return visitTableAuthorPlan(plan, ConfigPhysicalPlanType.RevokeRole);
}

private Optional<ConfigPhysicalPlan> visitTableAuthorPlan(
final AuthorRelationalPlan authorRelationalPlan, final ConfigPhysicalPlanType type) {
final Set<Integer> permissions =
authorRelationalPlan.getPermissions().stream()
.filter(permission -> PrivilegeType.values()[permission].forRelationalSys())
.collect(Collectors.toSet());
return !permissions.isEmpty()
? Optional.of(
new AuthorTreePlan(
type,
authorRelationalPlan.getUserName(),
authorRelationalPlan.getRoleName(),
authorRelationalPlan.getPassword(),
authorRelationalPlan.getNewPassword(),
permissions,
authorRelationalPlan.getGrantOpt(),
Collections.emptyList()))
: Optional.empty();
}
}

0 comments on commit a3a0334

Please sign in to comment.