diff --git a/authorizations/authorization-chain/src/main/java/org/apache/gravitino/authorization/chain/ChainedAuthorizationPlugin.java b/authorizations/authorization-chain/src/main/java/org/apache/gravitino/authorization/chain/ChainedAuthorizationPlugin.java index 120c355db06..982ee38cd2e 100644 --- a/authorizations/authorization-chain/src/main/java/org/apache/gravitino/authorization/chain/ChainedAuthorizationPlugin.java +++ b/authorizations/authorization-chain/src/main/java/org/apache/gravitino/authorization/chain/ChainedAuthorizationPlugin.java @@ -33,7 +33,6 @@ import org.apache.gravitino.authorization.Role; import org.apache.gravitino.authorization.RoleChange; import org.apache.gravitino.authorization.User; -import org.apache.gravitino.authorization.common.AuthorizationProperties; import org.apache.gravitino.authorization.common.ChainedAuthorizationProperties; import org.apache.gravitino.connector.authorization.AuthorizationPlugin; import org.apache.gravitino.connector.authorization.BaseAuthorization; @@ -55,16 +54,6 @@ private void initPlugins(String catalogProvider, Map properties) ChainedAuthorizationProperties chainedAuthzProperties = new ChainedAuthorizationProperties(properties); chainedAuthzProperties.validate(); - // Validate the properties for each plugin - chainedAuthzProperties - .plugins() - .forEach( - pluginName -> { - Map pluginProperties = - chainedAuthzProperties.fetchAuthPluginProperties(pluginName); - String authzProvider = chainedAuthzProperties.getPluginProvider(pluginName); - AuthorizationProperties.validate(authzProvider, pluginProperties); - }); // Create the plugins chainedAuthzProperties .plugins() @@ -83,8 +72,13 @@ private void initPlugins(String catalogProvider, Map properties) try { BaseAuthorization authorization = BaseAuthorization.createAuthorization(classLoader, authzProvider); + + // Load the authorization plugin with the class loader of the catalog. + // Because the JDBC authorization plugin may load JDBC driver using the class + // loader. AuthorizationPlugin authorizationPlugin = - authorization.newPlugin(metalake, catalogProvider, pluginConfig); + classLoader.withClassLoader( + cl -> authorization.newPlugin(metalake, catalogProvider, pluginConfig)); plugins.add(authorizationPlugin); } catch (Exception e) { throw new RuntimeException(e); diff --git a/authorizations/authorization-common/build.gradle.kts b/authorizations/authorization-common/build.gradle.kts index 9bab92dac3e..0dfd8d2cc2c 100644 --- a/authorizations/authorization-common/build.gradle.kts +++ b/authorizations/authorization-common/build.gradle.kts @@ -49,6 +49,7 @@ dependencies { testImplementation(libs.junit.jupiter.api) testImplementation(libs.mockito.core) testImplementation(libs.testcontainers) + testImplementation(libs.h2db) testRuntimeOnly(libs.junit.jupiter.engine) } 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 3ece6353d6e..85fe5c72ed4 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 @@ -34,21 +34,4 @@ public AuthorizationProperties(Map properties) { public abstract String getPropertiesPrefix(); public abstract void validate(); - - public static void validate(String type, Map properties) { - switch (type) { - case "ranger": - RangerAuthorizationProperties rangerAuthorizationProperties = - new RangerAuthorizationProperties(properties); - rangerAuthorizationProperties.validate(); - break; - case "chain": - ChainedAuthorizationProperties chainedAuthzProperties = - new ChainedAuthorizationProperties(properties); - chainedAuthzProperties.validate(); - break; - default: - throw new IllegalArgumentException("Unsupported authorization properties type: " + type); - } - } } diff --git a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java index 2d74bd050e3..4c8c3330a29 100644 --- a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java +++ b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationPlugin.java @@ -85,6 +85,13 @@ public JdbcAuthorizationPlugin(Map config) { dataSource.setTestOnReturn(BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN); dataSource.setLifo(BaseObjectPoolConfig.DEFAULT_LIFO); mappingProvider = new JdbcSecurableObjectMappingProvider(); + + try (Connection ignored = getConnection()) { + LOG.info("Load the JDBC driver first"); + } catch (SQLException se) { + LOG.error("Jdbc authorization plugin exception: ", se); + throw toAuthorizationPluginException(se); + } } @Override diff --git a/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java index 8d3788617cd..c229b7a92ff 100644 --- a/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java +++ b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationPlugin.java @@ -52,13 +52,13 @@ public class TestJdbcAuthorizationPlugin { private static final Map properties = ImmutableMap.of( JdbcAuthorizationProperties.JDBC_URL, - "xx", + "jdbc:h2:mem:test", JdbcAuthorizationProperties.JDBC_USERNAME, "xx", JdbcAuthorizationProperties.JDBC_PASSWORD, "xx", JdbcAuthorizationProperties.JDBC_DRIVER, - "xx"); + "org.h2.Driver"); private static final JdbcAuthorizationPlugin plugin = new JdbcAuthorizationPlugin(properties) {