jerqi commented on code in PR #9252: URL: https://github.com/apache/gravitino/pull/9252#discussion_r2566978684
########## core/src/main/java/org/apache/gravitino/hook/PolicyHookDispatcher.java: ########## @@ -0,0 +1,130 @@ +/* + * 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.gravitino.hook; + +import org.apache.gravitino.Entity; +import org.apache.gravitino.GravitinoEnv; +import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.authorization.AuthorizationUtils; +import org.apache.gravitino.authorization.Owner; +import org.apache.gravitino.authorization.OwnerDispatcher; +import org.apache.gravitino.exceptions.NoSuchPolicyException; +import org.apache.gravitino.exceptions.PolicyAlreadyExistsException; +import org.apache.gravitino.meta.PolicyEntity; +import org.apache.gravitino.policy.Policy; +import org.apache.gravitino.policy.PolicyChange; +import org.apache.gravitino.policy.PolicyContent; +import org.apache.gravitino.policy.PolicyDispatcher; +import org.apache.gravitino.utils.NameIdentifierUtil; +import org.apache.gravitino.utils.PrincipalUtils; + +public class PolicyHookDispatcher implements PolicyDispatcher { + + private final PolicyDispatcher dispatcher; + + public PolicyHookDispatcher(PolicyDispatcher dispatcher) { + this.dispatcher = dispatcher; + } + + @Override + public String[] listPolicies(String metalake) { + return dispatcher.listPolicies(metalake); + } + + @Override + public PolicyEntity[] listPolicyInfos(String metalake) { + return dispatcher.listPolicyInfos(metalake); + } + + @Override + public PolicyEntity getPolicy(String metalake, String policyName) throws NoSuchPolicyException { + return dispatcher.getPolicy(metalake, policyName); + } + + @Override + public PolicyEntity createPolicy( + String metalake, + String name, + Policy.BuiltInType type, + String comment, + boolean enabled, + PolicyContent content) + throws PolicyAlreadyExistsException { + AuthorizationUtils.checkCurrentUser(metalake, PrincipalUtils.getCurrentUserName()); Review Comment: We don't need to check current user, because we will check this in the intercept service. https://github.com/apache/gravitino/pull/9268 ########## server-common/src/main/java/org/apache/gravitino/server/authorization/MetadataIdConverter.java: ########## @@ -93,6 +85,20 @@ public class MetadataIdConverter { private MetadataIdConverter() {} + static { + METADATA_TO_ENTITY_TYPE_MAPPING.put(MetadataObject.Type.METALAKE, Entity.EntityType.METALAKE); Review Comment: We already have similar methods in the class of NameIdentifierUtil.Could you reuse them? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
