日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hive 配置用户名_配置HiveServer2的安全策略之自定义用户名密码验证

發布時間:2024/7/23 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hive 配置用户名_配置HiveServer2的安全策略之自定义用户名密码验证 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

具體從網上看

http://doc.mapr.com/display/MapR/Using+HiveServer2#UsingHiveServer2-ConfiguringCustomAuthentication

一共提供了三種安全認證方式,我們通常采用的為第三種自定義的方式。

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;

}

有一個方法要實現,實現了這個接口就可以自定義驗證用戶名密碼了。代碼不是太多

package org.apache.hadoop.hive.contrib.auth;

import javax.security.sasl.AuthenticationException;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.apache.hadoop.conf.Configurable;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hive.contrib.utils.MD5Util;

import org.apache.hive.service.auth.PasswdAuthenticationProvider;

public class XXXXPasswdAuthenticator implements PasswdAuthenticationProvider,Configurable {

private static final Log LOG=LogFactory.getLog(XXXXPasswdAuthenticator.class);

private Configuration conf=null;

private static final String HIVE_JDBC_PASSWD_AUTH_PREFIX="hive.jdbc_passwd.auth.%s";

public XXXXPasswdAuthenticator() {

init();

}

/**

*

*/

public void init(){

}

@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);

}

LOG.info("user "+userName+" login system successfully.");

}

@Override

public Configuration getConf() {

if(conf==null){

this.conf=new Configuration();

}

return conf;

}

@Override

public void setConf(Configuration arg0) {

this.conf=arg0;

}

}

Add the following properties to the hive-site.xml file, then restart Hiveserver2:

開啟自定義驗證配置

hive.server2.authentication

CUSTOM

hive.server2.custom.authentication.class

org.apache.hadoop.hive.contrib.auth.XXXXPasswdAuthenticator

相信看懂代碼的人應該明白怎么做了,我們要把用戶名密碼配置到hive-site.xml配置文件中。

hive.jdbc_passwd.auth.hive_r

b531c271de4552ca2dec510d318c87f9

多個用戶可以添加多個property,里面配置的即用戶名密碼了。

以上代碼打包jar包,上傳到hive/lib下即可實現HiveServer2的安全策略之自定義用戶名密碼驗證了。

總結

以上是生活随笔為你收集整理的hive 配置用户名_配置HiveServer2的安全策略之自定义用户名密码验证的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。