Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#12642] fix(authz): add missing supportsScheme to JdbcCredentialProvider (#12644)

Valverde47c617cd6fcf
diff --git a/core/src/main/java/org/apache/gravitino/credential/JdbcCredentialProvider.java b/core/src/main/java/org/apache/gravitino/credential/JdbcCredentialProvider.java
index 0eeee58cfb..2a7ff7437e 100644
--- a/core/src/main/java/org/apache/gravitino/credential/JdbcCredentialProvider.java
+++ b/core/src/main/java/org/apache/gravitino/credential/JdbcCredentialProvider.java
@@ -50,6 +50,11 @@ public class JdbcCredentialProvider implements CredentialProvider {
return JdbcCredential.JDBC_CREDENTIAL_TYPE;
}
+ @Override
+ public boolean supportsScheme(String scheme) {
+ return "jdbc".equalsIgnoreCase(scheme);
+ }
+
@Nullable
@Override
public Credential getCredential(CredentialContext context) {
diff --git a/core/src/test/java/org/apache/gravitino/credential/TestCatalogCredentialManager.java b/core/src/test/java/org/apache/gravitino/credential/TestCatalogCredentialManager.java
new file mode 100644
index 0000000000..88f4bc6404
--- /dev/null
+++ b/core/src/test/java/org/apache/gravitino/credential/TestCatalogCredentialManager.java
@@ -0,0 +1,58 @@
+/*
+ * 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.credential;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Map;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestCatalogCredentialManager {
+
+ @Test
+ void testSelectsStorageCredentialWhenJdbcProviderIsAlsoConfigured() {
+ String s3Path = "s3://bucket/warehouse/table";
+ Map<String, String> catalogProperties =
+ ImmutableMap.of(
+ CredentialConstants.CREDENTIAL_PROVIDERS,
+ String.join(
+ ",", DummyCredentialProvider.CREDENTIAL_TYPE, JdbcCredential.JDBC_CREDENTIAL_TYPE),
+ JdbcCredential.GRAVITINO_JDBC_USER,
+ "test-user",
+ JdbcCredential.GRAVITINO_JDBC_PASSWORD,
+ "test-password");
+
+ try (CatalogCredentialManager credentialManager =
+ new CatalogCredentialManager("test-catalog", catalogProperties)) {
+ PathBasedCredentialContext context =
+ new PathBasedCredentialContext("test-user", ImmutableSet.of(), ImmutableSet.of(s3Path));
+
+ Credential credential =
+ credentialManager
+ .getCredentialByPath(s3Path, context)
+ .orElseThrow(() -> new AssertionError("Expected a storage credential"));
+
+ Assertions.assertInstanceOf(DummyCredentialProvider.DummyCredential.class, credential);
+ Assertions.assertTrue(
+ credentialManager.getCredentialProvider(JdbcCredential.JDBC_CREDENTIAL_TYPE).isPresent());
+ }
+ }
+}