<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        自定義Hive權限控制(3)擴展Hive以實現自定義權限控制

        來源:懂視網 責編:小采 時間:2020-11-09 13:20:51
        文檔

        自定義Hive權限控制(3)擴展Hive以實現自定義權限控制

        自定義Hive權限控制(3)擴展Hive以實現自定義權限控制:簡介 前兩篇文章已經將需要的數據進行了準備,比如用戶權限配置信息等。本節主要介紹我們的使用場景,因為使用場景的問題,我們只針對select進行相應的 權限控制 ,insert,delete,drop等動作從數據庫層面上進行了限定,非本部門的人員是只擁有查詢權限的。
        推薦度:
        導讀自定義Hive權限控制(3)擴展Hive以實現自定義權限控制:簡介 前兩篇文章已經將需要的數據進行了準備,比如用戶權限配置信息等。本節主要介紹我們的使用場景,因為使用場景的問題,我們只針對select進行相應的 權限控制 ,insert,delete,drop等動作從數據庫層面上進行了限定,非本部門的人員是只擁有查詢權限的。

        簡介 前兩篇文章已經將需要的數據進行了準備,比如用戶權限配置信息等。本節主要介紹我們的使用場景,因為使用場景的問題,我們只針對select進行相應的 權限控制 ,insert,delete,drop等動作從數據庫層面上進行了限定,非本部門的人員是只擁有查詢權限的。

        簡介
        前兩篇文章已經將需要的數據進行了準備,比如用戶權限配置信息等。本節主要介紹我們的使用場景,因為使用場景的問題,我們只針對select進行相應的權限控制,insert,delete,drop等動作從數據庫層面上進行了限定,非本部門的人員是只擁有查詢權限的。所以在處理上會相對簡單一些。
        首先,建立一個工具包,用來處理相應的數據方面的請求。主要是獲取用戶權限的對應關系,并組織成我需要的格式。
        包括3個類:

        HiveTable.java是針對hive的table建立的對象類。MakeMD5.Java 是針對MD5密碼加密使用的工具類。UserAuthDataMode.java 是用于獲取用戶權限的方法類,本類實現了按照需要的格式獲取數據庫中的信息。

        HiveTable類
        package com.anyoneking.www;?import java.util.ArrayList;import java.util.List;?public class HiveTable {	private int id ;	private String tableName ;	private int dbid ;	private String dbName ;	private List partitionList = new ArrayList();	public int getId() {	return id;	}	public void setId(int id) {	this.id = id;	}	public String getTableName() {	return tableName;	}	public void setTableName(String tableName) {	this.tableName = tableName;	}	public int getDbid() {	return dbid;	}	public void setDbid(int dbid) {	this.dbid = dbid;	}	public String getDbName() {	return dbName;	}	public void setDbName(String dbName) {	this.dbName = dbName;	}	public List getPartitionList() {	return partitionList;	}	public void setPartitionList(List partitionList) {	this.partitionList = partitionList;	}?	public String getFullName(){	return this.dbName+"."+this.tableName;	}}

        UserAuthDataModel.java
        package com.anyoneking.www;?import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.List;import java.util.Map;?import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.hadoop.hive.conf.HiveConf;import org.apache.hadoop.hive.ql.Driver;/**?* 用戶認證類,用于從數據庫中提取相關的信息。?* @author songwei?*?*/public class UserAuthDataMode {	static final private Log LOG = LogFactory.getLog(Driver.class.getName());	private HiveConf conf ;	private boolean isSuperUser = false; 	private Map allTableMap =new HashMap();	//auth db name List	private List dbNameList = new ArrayList();	//auth table name List ex:{"dbName.tableName":HiveTable}	private Map tableMap = new HashMap();?	//auth table excludeColumnList ex:{"dbName.tableName":["phone"]}	private Map> excludeColumnList = new HashMap>();	//auth table includeColumnList ex:{"dbName.tableName":["ptdate","ptchannel"]}	private Map> includeColumnList = new HashMap>();?	private List ptchannelValueList = new ArrayList();?	private String userName;	private String password;	private Connection conn ;	private int userid ;	private int maxMapCount =16;	private int maxRedCount =16;?	private void createConn() throws Exception{	Class.forName("com.mysql.jdbc.Driver");	String dbURL = HiveConf.getVar(this.conf,HiveConf.ConfVars.KUXUN_HIVESERVER_URL);	String dbUserName = HiveConf.getVar(this.conf,HiveConf.ConfVars.KUXUN_HIVESERVER_USER);	String dbPassword = HiveConf.getVar(this.conf,HiveConf.ConfVars.KUXUN_HIVESERVER_PASSWORD);	this.conn = DriverManager.getConnection(dbURL,dbUserName, dbPassword);	//this.conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","test", "tset");	}?	public UserAuthDataMode(String userName,String password,HiveConf conf) throws Exception{	this.userName = userName ;	this.password = password ;	this.conf = conf;	this.createConn();	}?	private ResultSet getResult(String sql) throws Exception{	Statement stmt = conn.createStatement();	ResultSet rs = stmt.executeQuery(sql);	return rs;	}?	private void checkUser() throws Exception{	MakeMD5 md5 = new MakeMD5();	String sql = "select username,password,id,is_superuser from auth_user where username='"+this.userName+"'"; 	LOG.debug(sql);	this.password = md5.makeMD5(this.password);	ResultSet rs= this.getResult(sql);	int size =0 ;	boolean flag = false ;	if(size != 0){	throw new Exception("username is error");	}	while(rs.next()){	size +=1 ;	this.userid = rs.getInt("id");	int superUser = rs.getInt("is_superuser");	if (superUser == 1){	this.isSuperUser = true ;	}else{	this.isSuperUser = false ;	}	String db_password = rs.getString("password");	if(db_password.equals(this.password)){	flag = true ;	}	}	if(size 0){	String[] pt = ptInfo.split(",");	ht.setPartitionList(Arrays.asList(pt));	}	this.allTableMap.put(tblid, ht);	}?	//處理有權限的db信息	String dbSql = " select t2.hivedb_id,(select name from hive_db where id = t2.hivedb_id) dbname"	+" from hive_user_auth t1 join hive_user_auth_dbGroups t2"	+" on (t1.id = t2.hiveuserauth_id)"	+"where t1.user_id ="+this.userid ;	ResultSet dbrs = this.getResult(dbSql);	while(dbrs.next()){	this.dbNameList.add(dbrs.getString("dbname"));	}?	//處理有權限的表信息	String tableSql = "select t2.hivetable_id "	+"from hive_user_auth t1 join hive_user_auth_tableGroups t2 "	+"on (t1.id = t2.hiveuserauth_id) "	+"where t1.user_id ="+this.userid ;	ResultSet tablers = this.getResult(tableSql);	while(tablers.next()){	int tableID = tablers.getInt("hivetable_id");	LOG.debug("-----"+tableID);	HiveTable ht = this.allTableMap.get(tableID);	LOG.debug("---table_name--"+ht.getTableName());	String tableFullName = ht.getFullName();	LOG.debug(tableFullName);	this.tableMap.put(tableFullName, ht);	}?	//處理不允許操作的列	String exSql = "select col.name,col.table_id,col.column "	+"from hive_user_auth t1 join hive_user_auth_exGroups t2 "	+"on (t1.id = t2.hiveuserauth_id) "	+"join hive_excludecolumn col "	+"on (t2.excludecolumn_id = col.id) "	+"where t1.user_id ="+this.userid ;	ResultSet exrs = this.getResult(exSql);	while(exrs.next()){	int tableID = exrs.getInt("table_id");	String column = exrs.getString("column");	HiveTable ht = this.allTableMap.get(tableID);	String tableFullName = ht.getFullName();	String[] columnList = column.split(",");	this.excludeColumnList.put(tableFullName, Arrays.asList(columnList));	}?	//處理必須包含的列	String inSql = "select col.name,col.table_id,col.column "	+"from hive_user_auth t1 join hive_user_auth_inGroups t2 "	+"on (t1.id = t2.hiveuserauth_id) "	+"join hive_includecolumn col "	+"on (t2.includecolumn_id = col.id) "	+"where t1.user_id ="+this.userid ;	ResultSet inrs = this.getResult(inSql);	while(inrs.next()){	int tableID = inrs.getInt("table_id");	String column = inrs.getString("column");	HiveTable ht = this.allTableMap.get(tableID);	String tableFullName = ht.getFullName();	String[] columnList = column.split(",");	this.includeColumnList.put(tableFullName, Arrays.asList(columnList));	}?	//處理ptchannel的value	String ptSql = "select val.name "	+"from hive_user_auth t1 join hive_user_auth_ptGroups t2 "	+"on (t1.id = t2.hiveuserauth_id) "	+"join hive_ptchannel_value val "	+"on (t2.hiveptchannelvalue_id = val.id) "	+"where t1.user_id ="+this.userid ;	ResultSet ptrs = this.getResult(ptSql);	while(ptrs.next()){	String val = ptrs.getString("name");	this.ptchannelValueList.add(val);	}	}?	public int getMaxMapCount() {	return maxMapCount;	}?	public void setMaxMapCount(int maxMapCount) {	this.maxMapCount = maxMapCount;	}?	public int getMaxRedCount() {	return maxRedCount;	}?	public void setMaxRedCount(int maxRedCount) {	this.maxRedCount = maxRedCount;	}?	public void run() throws Exception{	this.checkUser();	this.parseAuth();	this.checkData();	this.modifyConf();	this.clearData();	}?	public void clearData() throws Exception{	this.conn.close();	}?	private void modifyConf(){	this.conf.setInt("mapred.map.tasks",this.maxMapCount);	//this.conf.setInt("hive.exec.reducers.ma", this.maxRedCount);	HiveConf.setIntVar(this.conf,HiveConf.ConfVars.MAXREDUCERS,this.maxRedCount);	}?	private void checkData(){	LOG.debug(this.allTableMap.keySet().size());	LOG.debug(this.tableMap.keySet().size());	LOG.debug(this.dbNameList.size());	LOG.debug(this.excludeColumnList.size());	LOG.debug(this.includeColumnList.size());	LOG.debug(this.ptchannelValueList.size());	}????	public static void main(String[] args) throws Exception{	UserAuthDataMode ua = new UserAuthDataMode("swtest","swtest",null);	ua.run();	}?	public List getDbNameList() {	return dbNameList;	}?	public void setDbNameList(List dbNameList) {	this.dbNameList = dbNameList;	}?	public Map getTableMap() {	return tableMap;	}?	public void setTableMap(Map tableMap) {	this.tableMap = tableMap;	}?	public Map> getExcludeColumnList() {	return excludeColumnList;	}?	public void setExcludeColumnList(Map> excludeColumnList) {	this.excludeColumnList = excludeColumnList;	}?	public Map> getIncludeColumnList() {	return includeColumnList;	}?	public void setIncludeColumnList(Map> includeColumnList) {	this.includeColumnList = includeColumnList;	}?	public List getPtchannelValueList() {	return ptchannelValueList;	}?	public void setPtchannelValueList(List ptchannelValueList) {	this.ptchannelValueList = ptchannelValueList;	}?}

        MakeMD5.java

        package com.anyoneking.www;?import java.math.BigInteger;import java.security.MessageDigest;?public class MakeMD5 {	public String makeMD5(String password) {	MessageDigest md;	try {	// 生成一個MD5加密計算摘要	md = MessageDigest.getInstance("MD5"); // 同樣可以使用SHA1	// 計算md5函數	md.update(password.getBytes());	// digest()最后確定返回md5 hash值,返回值為8為字符串。因為md5 hash值是16位的hex值,實際上就是8位的字符	// BigInteger函數則將8位的字符串轉換成16位hex值,用字符串來表示;得到字符串形式的hash值	String pwd = new BigInteger(1, md.digest()).toString(16); // 參數也可不只用16可改動,當然結果也不一樣了	return pwd;	} catch (Exception e) {	e.printStackTrace();	}	return password;	}?	public static void main(String[] args) {	MakeMD5 md5 = new MakeMD5();	md5.makeMD5("swtest");	}}

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        自定義Hive權限控制(3)擴展Hive以實現自定義權限控制

        自定義Hive權限控制(3)擴展Hive以實現自定義權限控制:簡介 前兩篇文章已經將需要的數據進行了準備,比如用戶權限配置信息等。本節主要介紹我們的使用場景,因為使用場景的問題,我們只針對select進行相應的 權限控制 ,insert,delete,drop等動作從數據庫層面上進行了限定,非本部門的人員是只擁有查詢權限的。
        推薦度:
        標簽: 控制 文章 自定義
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 国产极品美女高潮抽搐免费网站| 日韩内射激情视频在线播放免费 | 亚洲福利精品一区二区三区| 亚洲中文无码永久免| 国产片AV片永久免费观看| 亚洲日本香蕉视频观看视频| 19禁啪啪无遮挡免费网站| 亚洲春色另类小说| 成人女人A级毛片免费软件| 亚洲一区二区三区丝袜| 日本免费一本天堂在线| 一级片在线免费看| 亚洲熟妇av一区二区三区 | 国产99久久久久久免费看| 国产亚洲精品福利在线无卡一 | 亚洲欧美国产精品专区久久| 韩国日本好看电影免费看| 免费福利资源站在线视频| 亚洲宅男天堂在线观看无病毒| 国产午夜精品理论片免费观看| 婷婷久久久亚洲欧洲日产国码AV | 黄色网址免费在线观看| 无码乱人伦一区二区亚洲| 成年女人免费视频播放体验区| 亚洲AV无码国产一区二区三区| 亚洲精品黄色视频在线观看免费资源| 亚欧乱色国产精品免费视频| 亚洲精品视频观看| 国产最新凸凹视频免费| 久久久久久AV无码免费网站| 亚洲精品福利你懂| 久久亚洲国产精品五月天婷| 成年黄网站色大免费全看| 麻豆69堂免费视频| 久久久综合亚洲色一区二区三区| 一区二区无码免费视频网站| jizz在线免费观看| 亚洲一级免费视频| 国产成人亚洲精品91专区手机| 中文字幕亚洲免费无线观看日本| 亚洲av永久中文无码精品|