dengzhhu653 commented on code in PR #6085: URL: https://github.com/apache/hive/pull/6085#discussion_r2377342512
########## service/src/java/org/apache/hive/service/auth/ldap/KerberosLdapFilterEnforcer.java: ########## @@ -0,0 +1,104 @@ +/* + * 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.hive.service.auth.ldap; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.commons.lang3.StringUtils; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.security.SaslRpcServer; +import org.apache.hive.service.auth.LdapAuthenticationProviderImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.security.sasl.AuthenticationException; +import java.io.IOException; + +/** + * Helper that encapsulates LDAP filter resolution and enforcement for Kerberos-authenticated users. + */ +public final class KerberosLdapFilterEnforcer { + private static final Logger LOG = LoggerFactory.getLogger(KerberosLdapFilterEnforcer.class); + + private final HiveConf conf; + private final DirSearchFactory dirSearchFactory; + private final boolean enableLdapGroupCheck; + private final Filter filter; + + public KerberosLdapFilterEnforcer(HiveConf conf, DirSearchFactory dirSearchFactory) { + this.conf = conf; + this.dirSearchFactory = dirSearchFactory; + this.enableLdapGroupCheck = conf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_LDAP_ENABLE_GROUP_CHECK_AFTER_KERBEROS); + this.filter = enableLdapGroupCheck ? LdapAuthenticationProviderImpl.resolveFilter(conf) : null; + + if (enableLdapGroupCheck && filter == null) { + LOG.warn("LDAP group check enabled but no filters configured"); + } + } + + /** + * Applies configured LDAP filters to authenticate a user principal. + * + * @param principal Kerberos principal to validate + * @return {@code true} if the principal passes all configured filters; {@code false} otherwise + */ + public boolean applyLdapFilter(String principal) { + if (!enableLdapGroupCheck || filter == null) { Review Comment: nit: `if (! isFilterConfigured())` -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org