xunliu commented on code in PR #5786:
URL: https://github.com/apache/gravitino/pull/5786#discussion_r1896580537


##########
authorizations/authorization-chain/src/main/java/org/apache/gravitino/authorization/chain/ChainAuthorizationPlugin.java:
##########
@@ -0,0 +1,283 @@
+/*
+ * 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.authorization.chain;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.Catalog;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.authorization.AuthorizationProperties;
+import org.apache.gravitino.authorization.ChainAuthorizationProperties;
+import org.apache.gravitino.authorization.Group;
+import org.apache.gravitino.authorization.MetadataObjectChange;
+import org.apache.gravitino.authorization.Owner;
+import org.apache.gravitino.authorization.Role;
+import org.apache.gravitino.authorization.RoleChange;
+import org.apache.gravitino.authorization.User;
+import org.apache.gravitino.connector.authorization.AuthorizationPlugin;
+import org.apache.gravitino.connector.authorization.BaseAuthorization;
+import org.apache.gravitino.exceptions.AuthorizationPluginException;
+import org.apache.gravitino.utils.IsolatedClassLoader;
+
+/** Chain authorization operations plugin class. <br> */
+public class ChainAuthorizationPlugin implements AuthorizationPlugin {
+  private List<AuthorizationPlugin> plugins = Lists.newArrayList();
+  private final String metalake;
+
+  public ChainAuthorizationPlugin(
+      String metalake, String catalogProvider, Map<String, String> config) {
+    this.metalake = metalake;
+    initPlugins(catalogProvider, config);
+  }
+
+  private void initPlugins(String catalogProvider, Map<String, String> 
properties) {
+    ChainAuthorizationProperties chainAuthorizationProperties =
+        new ChainAuthorizationProperties(properties);
+    chainAuthorizationProperties.validate();
+    // Validate the properties for each plugin
+    chainAuthorizationProperties
+        .plugins()
+        .forEach(
+            pluginName -> {
+              Map<String, String> pluginProperties =
+                  
chainAuthorizationProperties.fetchAuthPluginProperties(pluginName);
+              String authProvider = 
chainAuthorizationProperties.getPluginProvider(pluginName);
+              AuthorizationProperties.validate(authProvider, pluginProperties);
+            });
+    // Create the plugins
+    chainAuthorizationProperties
+        .plugins()
+        .forEach(
+            pluginName -> {
+              String authProvider = 
chainAuthorizationProperties.getPluginProvider(pluginName);
+              Map<String, String> pluginConfig =
+                  
chainAuthorizationProperties.fetchAuthPluginProperties(pluginName);
+
+              ArrayList<String> libAndResourcesPaths = Lists.newArrayList();
+              BaseAuthorization.buildAuthorizationPkgPath(
+                      ImmutableMap.of(Catalog.AUTHORIZATION_PROVIDER, 
authProvider))
+                  .ifPresent(libAndResourcesPaths::add);
+              IsolatedClassLoader classLoader =
+                  IsolatedClassLoader.buildClassLoader(libAndResourcesPaths);
+              try {
+                BaseAuthorization<?> authorization =
+                    BaseAuthorization.createAuthorization(classLoader, 
authProvider);
+                AuthorizationPlugin authorizationPlugin =
+                    authorization.newPlugin(metalake, catalogProvider, 
pluginConfig);
+                plugins.add(authorizationPlugin);
+              } catch (Exception e) {
+                throw new RuntimeException(e);
+              }
+            });
+  }
+
+  @Override
+  public void close() throws IOException {
+    for (AuthorizationPlugin plugin : plugins) {
+      plugin.close();
+    }
+  }
+
+  @Override
+  public Boolean onMetadataUpdated(MetadataObjectChange... changes)
+      throws AuthorizationPluginException {
+    for (AuthorizationPlugin plugin : plugins) {
+      Boolean result = plugin.onMetadataUpdated(changes);

Review Comment:
   In such a for loop, if the plugin calls the `onMetadataUpdated` function and 
throws an exception, the exception will propagate to the outer method 
`ChainAuthorizaiton::onMetadataUpdated` and will not be caught or handled. This 
means that the outer method also sell AuthorizationPluginException 
abnormalities, and the cycle will be interrupted, will not continue to deal 
with the rest of the plugin.



-- 
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]

Reply via email to