World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8057] Improvement: Incorrect logic in check in JdbcAuthorizationProperties.java (#8070)
ankamdef9abaf444424
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.javaindex 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.javaindex 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.javanew file mode 100644index 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);+ }+}