1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 自定义Hive权限控制(4) 扩展Hive以实现自定义权限控制

自定义Hive权限控制(4) 扩展Hive以实现自定义权限控制

时间:2022-06-07 15:32:03

相关推荐

自定义Hive权限控制(4) 扩展Hive以实现自定义权限控制

数据库|mysql教程

自定义,Hive,权限,控制,扩展,实现,在前,3节中,已经

数据库-mysql教程

游戏充值源码,ubuntu18拼音,tomcat加载项目名称,egg爬虫图片,英泰php学习交流,台山SEOlzw

在前3节中,已经就 hive 权限控制 进行了基础数据的维护,现在用户权限配置功能已经实现。并且可以通过界面话的方式进行维护和管理。接着,最重要的事情就是针对Hive源码的修改。 主要是针对org.apache. hadoop . hive .conf.HiveConf及org.apache. hadoop .

php 考试开源系统源码,在vscode中加git,ubuntu安装ffm,tomcat出错闪退,sqlite安卓修改器,浏览器爬虫爬取手机号,php readline,盐城seo优化网络推广,南方数据企业网站管理系统破解,e资源模板lzw

安卓商城系统源码,p7510 ubuntu,tomcat命令行查看,flask 爬虫控制,php在线编程教程外包,seo 选品lzw

在前3节中,已经就hive权限控制进行了基础数据的维护,现在用户权限配置功能已经实现。并且可以通过界面话的方式进行维护和管理。接着,最重要的事情就是针对Hive源码的修改。

主要是针对org.apache.hadoop.hive.conf.HiveConf及org.apache.hadoop.hive.ql.Driver

首先针对我们的特定需求,

扩展org.apache.hadoop.hive.conf.HiveConf

??public static enum ConfVars {KUXUNUSER("hive.kuxun.username",""), //用户名KUXUNPASSWORD("hive.kuxun.password",""),//密码KUXUN_HIVESERVER_URL("hive.kuxun.hiveserver.url",""), //权限认证数据库地址KUXUN_HIVESERVER_USER("hive.kuxun.hiveserver.username",""),//权限认证数据库用户名KUXUN_HIVESERVER_PASSWORD("hive.kuxun.hiveserver.password",""),//权限认证数据库密码KUXUN_RESERVE_A("hive.kuxun.resrver.a",""),//保留KUXUN_RESERVE_B("hive.kuxun.resrver.b",""),//保留KUXUN_RESERVE_C("hive.kuxun.resrver.c",""),//保留KUXUN_RESERVE_D("hive.kuxun.resrver.d",""),//保留????????.......}

扩展org.apache.hadoop.hive.ql.Driver类

新增2个私有变量。用于存储传递来的用户和密码信息。

private String username ="";private String password ="";

在run()方法中增加获取username和password的实现

this.username = HiveConf.getVar(conf, HiveConf.ConfVars.KUXUNUSER);this.password = HiveConf.getVar(conf, HiveConf.ConfVars.KUXUNPASSWORD);

增加方法:

private void doAuthorizationExtend(BaseSemanticAnalyzer sem) throws HiveException, AuthorizationException {//获取用户权限信息UserAuthDataMode ua ;try{ua = new UserAuthDataMode(this.username,this.password,this.conf);ua.run();}catch(Exception e){throw new AuthorizationException(e.getMessage());}if(ua.isSuperUser()){LOG.error("current user is super user,do not check authorization.");return ;}LOG.warn("current user is ["+this.username+"]. start check authorization.......");????LOG.warn("current user["+this.username+"] execute command ["+this.userCommand+"].");?HashSet inputs = sem.getInputs();SessionState ss = SessionState.get();HiveOperation op = ss.getHiveOperation();if (op != null) {}//不处理这种方式,hiveserver并不提供写入操作LOG.debug("---------auth KUXUN--------------");if (inputs != null && inputs.size() > 0) {if (inputs.size() > ua.getMaxMapCount()){String errorMsg = "The max partition numbers which you can handler in one job is ["+ua.getMaxMapCount()+"],but current is ["+inputs.size()+"]. Pemission denied.";Exception ex = new Exception(errorMsg);throw new AuthorizationException(errorMsg,ex);}for (ReadEntity read : inputs) {if (read.getPartition() != null) {Table tbl = read.getTable();String tblName = tbl.getTableName();LOG.debug("-----dbName.tableName---------"+tbl.getDbName()+"."+tblName);String tblFullName = tbl.getDbName()+"."+tblName;//如果当前表所在db不在用户权限db中 ,同时表不在用户权限table中,则抛出异常if(ua.getDbNameList().indexOf(tbl.getDbName()) partValueList = part.getValues();List partList = tbl.getPartitionKeys();int partSize = partList.size();for (int i=0;i tsoTopMap = parseCtx.getTopToTable();?for (Map.Entry> topOpMap : querySem.getParseContext().getTopOps().entrySet()) {Operator topOp = topOpMap.getValue();if (topOp instanceof TableScanOperator&& tsoTopMap.containsKey(topOp)) {TableScanOperator tableScanOp = (TableScanOperator) topOp;Table tbl = tsoTopMap.get(tableScanOp);String dbName = tbl.getDbName();String tblName = tbl.getTableName();List neededColumnIds = tableScanOp.getNeededColumnIDs();List columns = tbl.getCols();List cols = new ArrayList();if (neededColumnIds != null){LOG.debug("-------neededColumnIds-----"+neededColumnIds.size());}else{LOG.debug("-------neededColumnIds-----null");}if (neededColumnIds != null&& neededColumnIds.size() > 0) {for (int i = 0; i < neededColumnIds.size(); i++) {cols.add(columns.get(neededColumnIds.get(i)).getName());}} else {for (int i = 0; i < columns.size(); i++) {cols.add(columns.get(i).getName());}}//判断非分区表,是否存在于权限对象中String fullTableName = dbName +"."+tblName;if(ua.getDbNameList().indexOf(tbl.getDbName()) authColList = ua.getExcludeColumnList().get(fullTableName);for(String col:cols){if(authColList.indexOf(col) !=-1){throw new AuthorizationException("table ["+fullTableName+"] column ["+col+"] Pemission denied.");}LOG.debug("--------col------------"+dbName+"."+tblName+":"+col);}}//判断是否有必须包含的列,但是在使用中没有使用的if(ua.getIncludeColumnList().containsKey(fullTableName)){List authColList = ua.getIncludeColumnList().get(fullTableName);for(String authCol:authColList){if(cols.indexOf(authCol) == -1 ){throw new AuthorizationException("table ["+fullTableName+"] must contain??column ["+authCol+"]. Pemission denied.");}}}?}}}}}

在complie方法中增加自定义权限认证方法调用

public int compile(String command, boolean resetTaskIds){??????try{??????doAuthorizationExtend(sem);??????}catch (AuthorizationException authExp){??????errorMessage ="FAILED:Kuxun Authorization failed:" + authExp.getMessage()??????????+ " Please contact anyoneking@ for your information." ;??????console.printError("Kuxun Authorization failed:" + authExp.getMessage()??????????????????+ "Please contact anyoneking@ for your information.");??????????????return 403;??????}}请注意:errorMessage在获取异常后,必须要进行赋值,否则通过hive client访问的时候,出现异常的时候不会给出异常提示,只会给出NUll。

以上完成后,重新打包,放到hivelib下面就ok了。

同时要注意修改hive-site.xml以传递对应的信息。

??hive.kuxun.username??test???hive.kuxun.password??test?????hive.kuxun.hiveserver.url??jdbc:mysql://localhost:3306/hiveserver??hiveserver jdbc connection url???hive.kuxun.hiveserver.username??test??username to use against hiveserver database???hive.kuxun.hiveserver.password??test??password to use against hiveserver database

原文地址:自定义Hive权限控制(4) 扩展Hive以实现自定义权限控制, 感谢原作者分享。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。