在前3节中,已经就 hive 权限控制 进行了基础数据的维护,现在用户权限配置功能已经实现。并且可以通过界面话的方式进行维护和管理。接着,最重要的事情就是针对hive源码的修改。 主要是针对org.apache. hadoop . hive .conf.hiveconf及org.apache. hadoop .
在前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
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!