mchades commented on code in PR #5791: URL: https://github.com/apache/gravitino/pull/5791#discussion_r1886083415
########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationProperties.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.ranger; + +import com.google.common.base.Preconditions; +import java.util.Map; + +public class RangerAuthorizationProperties implements AuthorizationProperties { + /** Ranger admin web URIs */ + public static final String RANGER_ADMIN_URL = "authorization.ranger.admin.url"; + + /** Ranger service name */ + public static final String RANGER_SERVICE_NAME = "authorization.ranger.service.name"; + + /** Ranger authentication type kerberos or simple */ + public static final String RANGER_AUTH_TYPE = "authorization.ranger.auth.type"; + + /** + * Ranger admin web login username(auth_type=simple), or kerberos principal(auth_type=kerberos) + */ + public static final String RANGER_USERNAME = "authorization.ranger.username"; + + /** + * Ranger admin web login user password(auth_type=simple), or path of the keytab + * file(auth_type=kerberos) + */ + public static final String RANGER_PASSWORD = "authorization.ranger.password"; + + @Override + public void validateProperties(Map<String, String> properties) { + Preconditions.checkArgument( + properties.containsKey(RANGER_ADMIN_URL), + String.format("%s is required", RANGER_ADMIN_URL)); + Preconditions.checkArgument( + properties.containsKey(RANGER_SERVICE_NAME), + String.format("%s is required", RANGER_SERVICE_NAME)); + Preconditions.checkArgument( + properties.containsKey(RANGER_AUTH_TYPE), + String.format("%s is required", RANGER_AUTH_TYPE)); + Preconditions.checkArgument( + properties.containsKey(RANGER_USERNAME), String.format("%s is required", RANGER_USERNAME)); + Preconditions.checkArgument( + properties.containsKey(RANGER_PASSWORD), String.format("%s is required", RANGER_PASSWORD)); + Preconditions.checkArgument( + properties.get(RANGER_ADMIN_URL) != null, Review Comment: Why are some properties validated using `properties.get(key) != null` while others are using `properties.containsKey(key)`? What is the difference? ########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/ChainAuthorizationProperties.java: ########## @@ -0,0 +1,165 @@ +/* + * 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.ranger; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +/** + * ChainAuthorizationProperties is a class that implements {@link AuthorizationProperties} + * interface. <br> + * <br> + * Configuration Example: <br> + * "authorization.chain.plugins" = "hive1,hdfs1" <br> + * "authorization.chain.hive1.provider" = "ranger"; <br> + * "authorization.chain.hive1.catalog-provider" = "hive"; <br> + * "authorization.chain.hive1.ranger.auth.type" = "simple"; <br> + * "authorization.chain.hive1.ranger.admin.url" = "http://localhost:6080"; <br> + * "authorization.chain.hive1.ranger.username" = "admin"; <br> + * "authorization.chain.hive1.ranger.password" = "admin"; <br> + * "authorization.chain.hive1.ranger.service.name" = "hiveDev"; <br> + * "authorization.chain.hdfs1.provider" = "ranger"; <br> + * "authorization.chain.hdfs1.catalog-provider" = "hadoop"; <br> + * "authorization.chain.hdfs1.ranger.auth.type" = "simple"; <br> + * "authorization.chain.hdfs1.ranger.admin.url" = "http://localhost:6080"; <br> + * "authorization.chain.hdfs1.ranger.username" = "admin"; <br> + * "authorization.chain.hdfs1.ranger.password" = "admin"; <br> + * "authorization.chain.hdfs1.ranger.service.name" = "hdfsDev"; <br> + */ +public class ChainAuthorizationProperties implements AuthorizationProperties { + public static final String PLUGINS_SPLITTER = ","; + /** Chain authorization plugin names */ + public static final String CHAIN_PLUGINS_PROPERTIES_KEY = "authorization.chain.plugins"; + + /** Chain authorization plugin provider */ + public static final String CHAIN_CATALOG_PROVIDER = "authorization.chain.*.catalog-provider"; + + /** Chain authorization plugin provider */ + public static final String CHAIN_PROVIDER = "authorization.chain.*.provider"; + + static Map<String, String> fetchAuthPluginProperties( + String pluginName, Map<String, String> properties) { Review Comment: I don't see the usage of `pluginName` in this function ########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationProperties.java: ########## @@ -0,0 +1,38 @@ +/* + * 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.ranger; + +import java.util.Map; + +public interface AuthorizationProperties { + /** The `Prefix.Wildcard` properties segment name */ + void validateProperties(Map<String, String> properties); + + static void validate( + Class<? extends AuthorizationProperties> authPropertiesClass, + Map<String, String> properties) { + try { + AuthorizationProperties authorizationProperties = + authPropertiesClass.getDeclaredConstructor().newInstance(); + authorizationProperties.validateProperties(properties); + } catch (ReflectiveOperationException e) { + throw new IllegalArgumentException("Failed to instantiate AuthorizationProperties class", e); + } Review Comment: It seems unnecessary to use reflection in this method. Why don't we directly use `static void validate(AuthorizationProperties authorizationProperties, Map<String, String> properties)`? ########## core/src/test/java/org/apache/gravitino/connector/authorization/mysql/TestMySQLAuthorization.java: ########## @@ -26,9 +26,11 @@ public class TestMySQLAuthorization extends BaseAuthorization<TestMySQLAuthoriza public TestMySQLAuthorization() {} + public static String SHORT_NAME = "mysql"; Review Comment: should be `private static final` ########## core/src/test/java/org/apache/gravitino/connector/authorization/ranger/TestRangerAuthorization.java: ########## @@ -26,9 +26,11 @@ public class TestRangerAuthorization extends BaseAuthorization<TestRangerAuthori public TestRangerAuthorization() {} + public static String SHORT_NAME = "ranger"; Review Comment: should be `private static final` ########## authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/AuthorizationProperties.java: ########## @@ -0,0 +1,38 @@ +/* + * 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.ranger; + +import java.util.Map; + +public interface AuthorizationProperties { + /** The `Prefix.Wildcard` properties segment name */ + void validateProperties(Map<String, String> properties); Review Comment: What exactly does the comment mean? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org