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


##########
authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcMetadataObject.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.jdbc;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.authorization.AuthorizationMetadataObject;
+
+public class JdbcMetadataObject implements AuthorizationMetadataObject {
+
+  private final String parent;
+  private final String name;
+  private final MetadataObject.Type type;

Review Comment:
   I think we need a definition of a `JdbcMetadataObject.Type` enum in here, 
let me can limit JdbcMetadataObject type only have `database` and `table`, just 
like 
https://github.com/apache/gravitino/blob/main/authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerHadoopSQLMetadataObject.java#L32



##########
authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcMetadataObject.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.jdbc;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.authorization.AuthorizationMetadataObject;
+
+public class JdbcMetadataObject implements AuthorizationMetadataObject {
+
+  private final String parent;
+  private final String name;
+  private final MetadataObject.Type type;
+
+  public JdbcMetadataObject(String parent, String name, MetadataObject.Type 
type) {

Review Comment:
   and limit in this function params and other places.
   ```
   public JdbcMetadataObject(String parent, String name, 
AuthorizationMetadataObject.Type type) {
   ```
   just like 
https://github.com/apache/gravitino/blob/main/authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerHadoopSQLMetadataObject.java#L75



##########
authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.jdbc;
+
+import java.util.Map;
+
+/** The properties for JDBC authorization plugin. */
+public class JdbcAuthorizationProperties {
+  private static final String CONFIG_PREFIX = "authorization.jdbc.";
+  public static final String JDBC_PASSWORD = CONFIG_PREFIX + "password";
+  public static final String JDBC_USERNAME = CONFIG_PREFIX + "username";
+  public static final String JDBC_URL = CONFIG_PREFIX + "url";
+  public static final String JDBC_DRIVER = CONFIG_PREFIX + "driver";
+
+  public static void validate(Map<String, String> properties) {
+    if (!properties.containsKey(JDBC_URL)) {
+      throw new IllegalArgumentException("JDBC URL is required");
+    }
+    if (!properties.containsKey(JDBC_USERNAME)) {
+      throw new IllegalArgumentException("JDBC username is required");
+    }
+    if (!properties.containsKey(JDBC_PASSWORD)) {
+      throw new IllegalArgumentException("JDBC password is required");
+    }
+    if (!properties.containsKey(JDBC_DRIVER)) {
+      throw new IllegalArgumentException("JDBC driver is required");
+    }

Review Comment:
   I think better to change 
   ```
       Preconditions.checkArgument(
           properties.containsKey(JDBC_URL) && properties.get(JDBC_URL) != null,
           String.format("%s is required", JDBC_URL));
   ......
   ```



##########
authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java:
##########
@@ -0,0 +1,461 @@
+/*
+ * 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.jdbc;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.commons.pool2.impl.BaseObjectPoolConfig;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.Unstable;
+import org.apache.gravitino.authorization.AuthorizationPrivilege;
+import org.apache.gravitino.authorization.AuthorizationSecurableObject;
+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.SecurableObject;
+import org.apache.gravitino.authorization.User;
+import org.apache.gravitino.connector.authorization.AuthorizationPlugin;
+import org.apache.gravitino.exceptions.AuthorizationPluginException;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.meta.GroupEntity;
+import org.apache.gravitino.meta.UserEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * JdbcSQLBasedAuthorizationPlugin is the base class for all JDBC-based 
authorization plugins. For
+ * example, JdbcHiveAuthorizationPlugin is the JDBC-based authorization plugin 
for Hive. Different
+ * JDBC-based authorization plugins can inherit this class and implement their 
own SQL statements.
+ */
+@Unstable
+abstract class JdbcAuthorizationPlugin implements AuthorizationPlugin, 
JdbcAuthorizationSQL {
+
+  private static final String GROUP_PREFIX = "GRAVITINO_GROUP_";
+  private static final Logger LOG = 
LoggerFactory.getLogger(JdbcAuthorizationPlugin.class);
+
+  protected BasicDataSource dataSource;
+  protected JdbcSecurableObjectMappingProvider mappingProvider;

Review Comment:
   I am confused, We use a member variable to implement an interface 
`AuthorizationPrivilegesMappingProvider`, and add a new class 
`JdbcSecurableObjectMappingProvider`, Why do we not directly implements 
`AuthorizationPrivilegesMappingProvider` in the `JdbcAuthorizationPlugin`?



-- 
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: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to