From 061f24bcae2e1ff265b032eb04e57682884ee5a9 Mon Sep 17 00:00:00 2001 From: roryqi Date: Thu, 26 Dec 2024 15:50:06 +0800 Subject: [PATCH] [#5993] refactor: Move the JdbcAuthorizationPlugin to authorization-common module (#5994) ### What changes were proposed in this pull request? Move the JdbcAuthorizationPlugin to authorization-common module ### Why are the changes needed? Fix: #5993 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Just refactor. --- .../authorization-common/build.gradle.kts | 1 + .../common/AuthorizationProperties.java | 4 +- .../jdbc/JdbcAuthorizationPlugin.java | 3 +- .../JdbcAuthorizationProperties.java | 5 +- .../jdbc/JdbcAuthorizationSQL.java | 2 +- .../jdbc/JdbcMetadataObject.java | 0 .../authorization/jdbc/JdbcPrivilege.java | 0 .../jdbc/JdbcSecurableObject.java | 0 .../JdbcSecurableObjectMappingProvider.java | 0 .../jdbc/TestJdbcAuthorizationPlugin.java} | 3 +- .../authorization-jdbc/build.gradle.kts | 96 ------------------- settings.gradle.kts | 2 +- 12 files changed, 10 insertions(+), 106 deletions(-) rename authorizations/{authorization-jdbc => authorization-common}/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java (98%) rename authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/{common => jdbc}/JdbcAuthorizationProperties.java (92%) rename authorizations/{authorization-jdbc => authorization-common}/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationSQL.java (99%) rename authorizations/{authorization-jdbc => authorization-common}/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcMetadataObject.java (100%) rename authorizations/{authorization-jdbc => authorization-common}/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcPrivilege.java (100%) rename authorizations/{authorization-jdbc => authorization-common}/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObject.java (100%) rename authorizations/{authorization-jdbc => authorization-common}/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObjectMappingProvider.java (100%) rename authorizations/{authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java => authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java} (98%) delete mode 100644 authorizations/authorization-jdbc/build.gradle.kts diff --git a/authorizations/authorization-common/build.gradle.kts b/authorizations/authorization-common/build.gradle.kts index ba64510f2ce..9bab92dac3e 100644 --- a/authorizations/authorization-common/build.gradle.kts +++ b/authorizations/authorization-common/build.gradle.kts @@ -36,6 +36,7 @@ dependencies { } implementation(libs.bundles.log4j) implementation(libs.commons.lang3) + implementation(libs.commons.dbcp2) implementation(libs.guava) implementation(libs.javax.jaxb.api) { exclude("*") diff --git a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/AuthorizationProperties.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/AuthorizationProperties.java index 3005cc5f3e9..3ece6353d6e 100644 --- a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/AuthorizationProperties.java +++ b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/AuthorizationProperties.java @@ -31,9 +31,9 @@ public AuthorizationProperties(Map properties) { .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } - abstract String getPropertiesPrefix(); + public abstract String getPropertiesPrefix(); - abstract void validate(); + public abstract void validate(); public static void validate(String type, Map properties) { switch (type) { diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java similarity index 98% rename from authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java index d9bc28636c3..cc3190413e1 100644 --- a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java +++ b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java @@ -40,7 +40,6 @@ import org.apache.gravitino.authorization.RoleChange; import org.apache.gravitino.authorization.SecurableObject; import org.apache.gravitino.authorization.User; -import org.apache.gravitino.authorization.common.JdbcAuthorizationProperties; import org.apache.gravitino.connector.authorization.AuthorizationPlugin; import org.apache.gravitino.exceptions.AuthorizationPluginException; import org.apache.gravitino.meta.AuditInfo; @@ -55,7 +54,7 @@ * JDBC-based authorization plugins can inherit this class and implement their own SQL statements. */ @Unstable -abstract class JdbcAuthorizationPlugin implements AuthorizationPlugin, JdbcAuthorizationSQL { +public abstract class JdbcAuthorizationPlugin implements AuthorizationPlugin, JdbcAuthorizationSQL { private static final String GROUP_PREFIX = "GRAVITINO_GROUP_"; private static final Logger LOG = LoggerFactory.getLogger(JdbcAuthorizationPlugin.class); diff --git a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/JdbcAuthorizationProperties.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java similarity index 92% rename from authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/JdbcAuthorizationProperties.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java index 9a5e7c6cc97..69a12135023 100644 --- a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/common/JdbcAuthorizationProperties.java +++ b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java @@ -16,9 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.gravitino.authorization.common; +package org.apache.gravitino.authorization.jdbc; import java.util.Map; +import org.apache.gravitino.authorization.common.AuthorizationProperties; /** The properties for JDBC authorization plugin. */ public class JdbcAuthorizationProperties extends AuthorizationProperties { @@ -39,7 +40,7 @@ private void check(String key, String errorMsg) { } @Override - String getPropertiesPrefix() { + public String getPropertiesPrefix() { return CONFIG_PREFIX; } diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationSQL.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationSQL.java similarity index 99% rename from authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationSQL.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationSQL.java index f7171ff354a..de031f70e78 100644 --- a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationSQL.java +++ b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationSQL.java @@ -25,7 +25,7 @@ /** Interface for SQL operations of the underlying access control system. */ @Unstable -interface JdbcAuthorizationSQL { +public interface JdbcAuthorizationSQL { /** * Get SQL statements for creating a user. diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcMetadataObject.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcMetadataObject.java similarity index 100% rename from authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcMetadataObject.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcMetadataObject.java diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcPrivilege.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcPrivilege.java similarity index 100% rename from authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcPrivilege.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcPrivilege.java diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObject.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObject.java similarity index 100% rename from authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObject.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObject.java diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObjectMappingProvider.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObjectMappingProvider.java similarity index 100% rename from authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObjectMappingProvider.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcSecurableObjectMappingProvider.java diff --git a/authorizations/authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java similarity index 98% rename from authorizations/authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java rename to authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java index e261fad78d2..ab91ba81e93 100644 --- a/authorizations/authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java +++ b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java @@ -34,7 +34,6 @@ import org.apache.gravitino.authorization.SecurableObject; import org.apache.gravitino.authorization.SecurableObjects; import org.apache.gravitino.authorization.User; -import org.apache.gravitino.authorization.common.JdbcAuthorizationProperties; import org.apache.gravitino.meta.AuditInfo; import org.apache.gravitino.meta.GroupEntity; import org.apache.gravitino.meta.RoleEntity; @@ -42,7 +41,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class JdbcAuthorizationPluginTest { +public class TestJdbcAuthorizationPlugin { private static List expectSQLs = Lists.newArrayList(); private static List expectTypes = Lists.newArrayList(); private static List expectObjectNames = Lists.newArrayList(); diff --git a/authorizations/authorization-jdbc/build.gradle.kts b/authorizations/authorization-jdbc/build.gradle.kts deleted file mode 100644 index 1a61f7c0cf9..00000000000 --- a/authorizations/authorization-jdbc/build.gradle.kts +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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. - */ -description = "authorization-jdbc" - -plugins { - `maven-publish` - id("java") - id("idea") -} - -dependencies { - implementation(project(":api")) { - exclude(group = "*") - } - implementation(project(":core")) { - exclude(group = "*") - } - implementation(project(":authorizations:authorization-common")) { - exclude(group = "*") - } - implementation(libs.bundles.log4j) - implementation(libs.commons.lang3) - implementation(libs.guava) - implementation(libs.javax.jaxb.api) { - exclude("*") - } - implementation(libs.javax.ws.rs.api) - implementation(libs.jettison) - compileOnly(libs.lombok) - implementation(libs.mail) - implementation(libs.rome) - implementation(libs.commons.dbcp2) - - testImplementation(project(":common")) - testImplementation(project(":clients:client-java")) - testImplementation(project(":server")) - testImplementation(project(":catalogs:catalog-common")) - testImplementation(project(":integration-test-common", "testArtifacts")) - testImplementation(libs.junit.jupiter.api) - testImplementation(libs.mockito.core) - testImplementation(libs.testcontainers) - testRuntimeOnly(libs.junit.jupiter.engine) -} - -tasks { - val runtimeJars by registering(Copy::class) { - from(configurations.runtimeClasspath) - into("build/libs") - } - - val copyAuthorizationLibs by registering(Copy::class) { - dependsOn("jar", runtimeJars) - from("build/libs") { - exclude("guava-*.jar") - exclude("log4j-*.jar") - exclude("slf4j-*.jar") - } - into("$rootDir/distribution/package/authorizations/ranger/libs") - } - - register("copyLibAndConfig", Copy::class) { - dependsOn(copyAuthorizationLibs) - } - - jar { - dependsOn(runtimeJars) - } -} - -tasks.test { - dependsOn(":catalogs:catalog-hive:jar", ":catalogs:catalog-hive:runtimeJars") - - val skipITs = project.hasProperty("skipITs") - if (skipITs) { - // Exclude integration tests - exclude("**/integration/test/**") - } else { - dependsOn(tasks.jar) - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index f38443db206..562614764b3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -57,7 +57,7 @@ if (gradle.startParameter.projectProperties["enableFuse"]?.toBoolean() == true) } include("iceberg:iceberg-common") include("iceberg:iceberg-rest-server") -include("authorizations:authorization-ranger", "authorizations:authorization-jdbc", "authorizations:authorization-common", "authorizations:authorization-chain") +include("authorizations:authorization-ranger", "authorizations:authorization-common", "authorizations:authorization-chain") include("trino-connector:trino-connector", "trino-connector:integration-test") include("spark-connector:spark-common") // kyuubi hive connector doesn't support 2.13 for Spark3.3