diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/JdbcAuthorizationProperties.java similarity index 73% rename from authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java rename to authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/JdbcAuthorizationProperties.java index b13504fd2fd..023bf68d1a6 100644 --- a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java +++ b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/JdbcAuthorizationProperties.java @@ -16,29 +16,39 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.gravitino.authorization.jdbc; +package org.apache.gravitino.authorization; import java.util.Map; /** The properties for JDBC authorization plugin. */ -public class JdbcAuthorizationProperties { +public class JdbcAuthorizationProperties extends AuthorizationProperties { 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 properties) { - String errorMsg = "%s is required"; - check(properties, JDBC_URL, errorMsg); - check(properties, JDBC_USERNAME, errorMsg); - check(properties, JDBC_PASSWORD, errorMsg); - check(properties, JDBC_DRIVER, errorMsg); + public JdbcAuthorizationProperties(Map properties) { + super(properties); } - private static void check(Map properties, String key, String errorMsg) { + private void check(String key, String errorMsg) { if (!properties.containsKey(key) && properties.get(key) != null) { throw new IllegalArgumentException(String.format(errorMsg, key)); } } + + @Override + String getPropertiesPrefix() { + return CONFIG_PREFIX; + } + + @Override + public void validate() { + String errorMsg = "%s is required"; + check(JDBC_URL, errorMsg); + check(JDBC_USERNAME, errorMsg); + check(JDBC_PASSWORD, errorMsg); + check(JDBC_DRIVER, errorMsg); + } } diff --git a/authorizations/authorization-jdbc/build.gradle.kts b/authorizations/authorization-jdbc/build.gradle.kts index 8b105908c26..1a61f7c0cf9 100644 --- a/authorizations/authorization-jdbc/build.gradle.kts +++ b/authorizations/authorization-jdbc/build.gradle.kts @@ -31,7 +31,9 @@ dependencies { implementation(project(":core")) { exclude(group = "*") } - + implementation(project(":authorizations:authorization-common")) { + exclude(group = "*") + } implementation(libs.bundles.log4j) implementation(libs.commons.lang3) implementation(libs.guava) diff --git a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java b/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java index f889cee2240..8f9551cfe4f 100644 --- a/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java +++ b/authorizations/authorization-jdbc/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java @@ -34,6 +34,7 @@ import org.apache.gravitino.authorization.AuthorizationPrivilege; import org.apache.gravitino.authorization.AuthorizationSecurableObject; import org.apache.gravitino.authorization.Group; +import org.apache.gravitino.authorization.JdbcAuthorizationProperties; import org.apache.gravitino.authorization.MetadataObjectChange; import org.apache.gravitino.authorization.Owner; import org.apache.gravitino.authorization.Role; @@ -65,7 +66,8 @@ abstract class JdbcAuthorizationPlugin implements AuthorizationPlugin, JdbcAutho public JdbcAuthorizationPlugin(Map config) { // Initialize the data source dataSource = new BasicDataSource(); - JdbcAuthorizationProperties.validate(config); + JdbcAuthorizationProperties jdbcAuthProperties = new JdbcAuthorizationProperties(config); + jdbcAuthProperties.validate(); String jdbcUrl = config.get(JdbcAuthorizationProperties.JDBC_URL); dataSource.setUrl(jdbcUrl); diff --git a/authorizations/authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java b/authorizations/authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java index b72392a6cd8..be3c95dc404 100644 --- a/authorizations/authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java +++ b/authorizations/authorization-jdbc/src/test/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPluginTest.java @@ -27,6 +27,7 @@ import org.apache.gravitino.MetadataObject; import org.apache.gravitino.MetadataObjects; import org.apache.gravitino.authorization.Group; +import org.apache.gravitino.authorization.JdbcAuthorizationProperties; import org.apache.gravitino.authorization.Owner; import org.apache.gravitino.authorization.Privileges; import org.apache.gravitino.authorization.Role;