Hive 通过HiveServer2对外提供服务,HiveServer2 是一种能使客户端执行 Hive 查询的服务。
HiveServer2 实现了一个新的基于 Thrift 的 RPC 接口,该接口可以处理客户端并发请求。当前版本支持 Kerberos,LDAP 以及自定义可插拔身份验证。新的 RPC 接口也是 JDBC 和 ODBC 客户端更好的选择,尤其是对于元数据访问。
hive身份认证的三种方式:
NONE:即不做身份校验;(不输入账户密码或任意账户密码都可以访问)
LDAP: 使用基于 LDAP/AD 的用户身份校验;(优先选择)
KERBEROS: 使用 Kerberos/GSSAPI 做身份校验;
CUSTOM:自定义认证;
配置CUSTOM身份认证流程
1.首先需要编写用户权限验证的类
import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hive.service.auth.PasswdAuthenticationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; import javax.security.sasl.AuthenticationException; /** * @author * @version 1.0.0 * @since 2022-09-28 10:00 **/ public class AuthLogin implements PasswdAuthenticationProvider, Configurable { private static Logger LOG = LoggerFactory.getLogger(AuthLogin.class); private String user; private String pwd; private Configuration conf = null; public AuthLogin() { user = getConf().get("hive.auth.user"); pwd = getConf().get("hive.auth.pwd"); } @Override public void setConf(Configuration configuration) { } @Override public Configuration getConf() { if (this.conf == null) { HiveConf conf = new HiveConf(); this.conf = new Configuration(conf); } return this.conf; } @Override public void Authenticate(String username, String password) throws AuthenticationException { if (username == null || password == null) { throw new AuthenticationException("error."); } LOG.info("user: " + username + " try login."); if (!user.equals(username)) { String message = "user name not exist:"; throw new AuthenticationException(message); } else { if (!password.equals(pwd)) { String message = "user name and password is mismaPasswdAuthenticationProvidertch. user:" + username; throw new AuthenticationException(message); } } LOG.info("user " + username + " login system successfully."); } } pom依赖 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 cn.li hive-auth 1.0 org.apache.hadoop hadoop-common 3.3.1 org.apache.hive hive-common 3.1.2 commons-logging commons-logging 1.2 org.apache.hive hive-service 3.1.2 将以上文件打包 mvn install 2.配置及复制jar包 将上面的程序打包的hive-auth-1.0.jar,放到$HIVE_HOME/lib下 配置hive-site.xml,追加以下文件 hive.server2.authentication CUSTOM hive.server2.custom.authentication.class AuthLogin hive.auth.user admin hive.auth.pwd Aa123456 hive.auth.user为用户名 hive.auth.pwd为密码View Code
原文链接:https://www.kuazhi.com/post/420621.html
标签:身份验证,auth,hive,conf,apache,org,user From: https://www.cnblogs.com/chong-zuo3322/p/17881305.html