This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new f9abaf4444 [#8057] Improvement: Incorrect logic in check in
JdbcAuthorizationProperties.java (#8070)
f9abaf4444 is described below
commit f9abaf444424f3a1454488e3f242d0911c1c99a4
Author: ankamde <[email protected]>
AuthorDate: Fri Aug 15 04:23:19 2025 +0200
[#8057] Improvement: Incorrect logic in check in
JdbcAuthorizationProperties.java (#8070)
### What changes were proposed in this pull request?
Incorrect logic in check in JdbcAuthorizationProperties.java
### Why are the changes needed?
Because JdbcAuthorizationProperties didn't check for missing properties.
Fix: #8057
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
By running unit tests.
---
.../common/AuthorizationProperties.java | 4 +-
.../jdbc/JdbcAuthorizationProperties.java | 2 +-
.../jdbc/TestJdbcAuthorizationProperties.java | 61 ++++++++++++++++++++++
3 files changed, 65 insertions(+), 2 deletions(-)
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 6f41abea25..2d14d84bb7 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
@@ -27,7 +27,9 @@ public abstract class AuthorizationProperties {
protected AuthorizationProperties(Map<String, String> properties) {
this.properties =
properties.entrySet().stream()
- .filter(entry -> entry.getKey().startsWith(getPropertiesPrefix()))
+ .filter(
+ entry ->
+ entry.getKey().startsWith(getPropertiesPrefix()) &&
entry.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
diff --git
a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java
b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java
index 69a1213502..93d139966a 100644
---
a/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java
+++
b/authorizations/authorization-common/src/main/java/org/apache/gravitino/authorization/jdbc/JdbcAuthorizationProperties.java
@@ -34,7 +34,7 @@ public class JdbcAuthorizationProperties extends
AuthorizationProperties {
}
private void check(String key, String errorMsg) {
- if (!properties.containsKey(key) && properties.get(key) != null) {
+ if (!properties.containsKey(key)) {
throw new IllegalArgumentException(String.format(errorMsg, key));
}
}
diff --git
a/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationProperties.java
b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationProperties.java
new file mode 100644
index 0000000000..49e43dbe9d
--- /dev/null
+++
b/authorizations/authorization-common/src/test/java/org/apache/gravitino/authorization/jdbc/TestJdbcAuthorizationProperties.java
@@ -0,0 +1,61 @@
+/*
+ * 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.authorization.jdbc;
+
+import com.google.common.collect.Maps;
+import java.util.Map;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class TestJdbcAuthorizationProperties {
+ @Test
+ void testJdbcProperties() {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(JdbcAuthorizationProperties.JDBC_URL,
"jdbc:test://localhost");
+ properties.put(JdbcAuthorizationProperties.JDBC_USERNAME, "user");
+ properties.put(JdbcAuthorizationProperties.JDBC_PASSWORD, "pwd");
+ properties.put(JdbcAuthorizationProperties.JDBC_DRIVER, "driver");
+
+ JdbcAuthorizationProperties jdbcProps = new
JdbcAuthorizationProperties(properties);
+ Assertions.assertDoesNotThrow(jdbcProps::validate);
+ }
+
+ @Test
+ void testJdbcPropertiesMissingUrl() {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(JdbcAuthorizationProperties.JDBC_USERNAME, "user");
+ properties.put(JdbcAuthorizationProperties.JDBC_PASSWORD, "pwd");
+ properties.put(JdbcAuthorizationProperties.JDBC_DRIVER, "driver");
+
+ JdbcAuthorizationProperties jdbcProps = new
JdbcAuthorizationProperties(properties);
+ Assertions.assertThrows(IllegalArgumentException.class,
jdbcProps::validate);
+ }
+
+ @Test
+ void testJdbcPropertiesNullUsername() {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(JdbcAuthorizationProperties.JDBC_URL,
"jdbc:test://localhost");
+ properties.put(JdbcAuthorizationProperties.JDBC_USERNAME, null);
+ properties.put(JdbcAuthorizationProperties.JDBC_PASSWORD, "pwd");
+ properties.put(JdbcAuthorizationProperties.JDBC_DRIVER, "driver");
+
+ JdbcAuthorizationProperties jdbcProps = new
JdbcAuthorizationProperties(properties);
+ Assertions.assertThrows(IllegalArgumentException.class,
jdbcProps::validate);
+ }
+}