HiveServer2用户名密码验证


1.在hive-site.xml中加


  hive.server2.authentication
  CUSTOM



  hive.server2.custom.authentication.class
  org.apache.hadoop.hive.contrib.auth.XXXXPasswdAuthenticator

设置server2验证方式是CUSTOM ;并指定自定义验证类是org.apache.hadoop.hive.contrib.auth.XXXXPasswdAuthenticator


2.完成自定义验证类org.apache.hadoop.hive.contrib.auth.XXXXPasswdAuthenticator,继承org.apache.hive.service.auth.PasswdAuthenticationProvider

重写方法,如下:

@Override
  public void Authenticate(String userName, String passwd)
      throws AuthenticationException {
    LOG.info("user: "+userName+" try login.");
    
    String passwdMD5 = getConf().get(String.format(HIVE_JDBC_PASSWD_AUTH_PREFIX, userName));
    
    if(passwdMD5==null){
      String message = "user's ACL configration is not found. user:"+userName;
      LOG.info(message);
      throw new AuthenticationException(message);
    }
    
    String md5 = MD5Util.md5Hex(passwd);
    
    if(!md5.equals(passwdMD5)){
      String message = "user name and password is mismatch. user:"+userName;
      throw new AuthenticationException(message);
    }
  }

  @Override
  public Configuration getConf() {
    if(conf==null){
      this.conf=new Configuration();
    }
    
    return conf;
  }

  @Override
  public void setConf(Configuration arg0) {
    this.conf=arg0;
  }


3.打jar包放到hive\lib下。注意,jar包中的目录结构和org.apache.hadoop.hive.contrib.auth.XXXXPasswdAuthenticator是一致的。


4.在hive-site.xml中配置一组可用帐号密码


    hive.jdbc_passwd.auth.username
    用authenticate自定方法加密后的密码


多组,只要添加多个如上的property即可。


5.重启HiveServer2服务;


6.测试

try {
	Class.forName("org.apache.hive.jdbc.HiveDriver");// 指定连接类型
	conn = DriverManager.getConnection(url, user, password);// 获取连接
} catch (Exception e) {
	e.printStackTrace();
}


参考:

1.之二十-自定义HiveServer2的用户安全认证 – lxw的大数据田地 http://lxw1234.com/archives/2016/01/600.htm

2.配置HiveServer2的安全策略之自定义用户名密码验证 - 推酷 http://www.tuicool.com/articles/bQj6BvA

3.https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2#SettingUpHiveServer2-Configuration





你可能感兴趣的:(java,hive)