Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6353] fix(authz): Fix the failure of chained plugin to load JDBC authz plugin #6372

Merged
merged 5 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,16 +54,6 @@ private void initPlugins(String catalogProvider, Map<String, String> properties)
ChainedAuthorizationProperties chainedAuthzProperties =
new ChainedAuthorizationProperties(properties);
chainedAuthzProperties.validate();
// Validate the properties for each plugin
chainedAuthzProperties
.plugins()
.forEach(
pluginName -> {
Map<String, String> pluginProperties =
chainedAuthzProperties.fetchAuthPluginProperties(pluginName);
String authzProvider = chainedAuthzProperties.getPluginProvider(pluginName);
AuthorizationProperties.validate(authzProvider, pluginProperties);
});
// Create the plugins
chainedAuthzProperties
.plugins()
Expand All @@ -83,8 +72,13 @@ private void initPlugins(String catalogProvider, Map<String, String> 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);
Expand Down
1 change: 1 addition & 0 deletions authorizations/authorization-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,4 @@ public AuthorizationProperties(Map<String, String> properties) {
public abstract String getPropertiesPrefix();

public abstract void validate();

public static void validate(String type, Map<String, String> properties) {
jerqi marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public JdbcAuthorizationPlugin(Map<String, String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public class TestJdbcAuthorizationPlugin {
private static final Map<String, String> 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) {
Expand Down
Loading