需要在两个部分分别进行设置
Hive部分
在虚拟机端安装使用hive时,初始是没有设置用户名和密码,
在我们使用pyhive连接hive时需要用到用户名和密码
此时,我们就要启用hive的自定义用户名密码验证
- 第一步:根据hiveServer2服务提供的接口,实现他
To implement custom authentication for HiveServer2, create a custom Authenticator class derived from the following interface:
从这段话看出来我们要实现一个接口:PasswdAuthenticationProvider (org.apache.hive.service.auth.PasswdAuthenticationProvider)我们来看看这个接口
发现有一个方法要实现,实现了这个接口就可以自定义验证用户名密码了
public interface PasswdAuthenticationProvider {
/**
* The Authenticate method is called by the HiveServer2 authentication layer
* to authenticate users for their requests.
* If a user is to be granted, return nothing/throw nothing.
* When a user is to be disallowed, throw an appropriate {
@link AuthenticationException}.
*
* For an example implementation, see {
@link LdapAuthenticationProviderImpl}.
*
* @param user - The username received over the connection request
* @param password - The password received over the connection request
* @throws AuthenticationException - When a user is found to be
* invalid by the implementation
*/
void Authenticate(String user, String password) throws AuthenticationException;
}
接口实现代码:
将代码打包为jar包,放在hive根目录的lib目录下
package org.apache.hadoop.hive.contrib.auth;
import javax.security.sasl.AuthenticationException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.conf.HiveConf;
import org.slf4j.Logger;
public class CustomPasswdAuthenticator implements org.apache.hive.service.auth.PasswdAuthenticationProvider{
private Logger LOG = org.slf4j.LoggerFactory.getLogger(CustomPasswdAuthenticator.class);
private static final String HIVE_JDBC_PASSWD_AUTH_PREFIX="hive.jdbc_passwd.auth.%s