package com.lxw.hive;
import org.apache.hadoop.hive.ql.parse.ASTNode;
import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
import org.apache.hadoop.hive.ql.parse.HiveParser;
import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.session.SessionState;
/**
* 只运行Admin用户(lxw用户)执行创建数据库,赋权等操作。
*/
public class MyAuthHook extends AbstractSemanticAnalyzerHook {
private static String admin = "lxw";
@Override
public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context,
ASTNode ast) throws SemanticException {
switch (ast.getToken().getType()) {
case HiveParser.TOK_CREATEDATABASE:
case HiveParser.TOK_DROPDATABASE:
case HiveParser.TOK_CREATEROLE:
case HiveParser.TOK_DROPROLE:
case HiveParser.TOK_GRANT:
case HiveParser.TOK_REVOKE:
case HiveParser.TOK_GRANT_ROLE:
case HiveParser.TOK_REVOKE_ROLE:
String userName = null;
if (SessionState.get() != null
&& SessionState.get().getAuthenticator() != null) {
userName = SessionState.get().getAuthenticator().getUserName();
}
if (!admin.equalsIgnoreCase(userName)) {
throw new SemanticException(userName
+ " can't use ADMIN options, except " + admin + ".");
}
break;
default:
break;
}
return ast;
}
}
打包放到$HIVE_HOME/lib目录下;
修改hive-site.xml
<property>
<name>hive.semantic.analyzer.hook</name>
<value>com.lxw.hive.MyAuthHook</value>
</property>
运行结果:
hive> drop database lxw2;
FAILED: Error in semantic analysis: lxw2 can't use ADMIN options, except lxw.
hive> create database lxw3;
FAILED: Error in semantic analysis: lxw2 can't use ADMIN options, except lxw.
hive> grant select on database lxw2 to user lxw2;
FAILED: Error in semantic analysis: lxw2 can't use ADMIN options, except lxw.
分享到:
相关推荐
apache-hive-2.1.1-bin.tar apache-hive-2.1.1-bin.tar apache-hive-2.1.1-bin.tarapache-hive-2.1.1-bin.tar apache-hive-2.1.1-bin.tar apache-hive-2.1.1-bin.tarapache-hive-2.1.1-bin.tar apache-hive-2.1.1-...
含两个文件hive-jdbc-3.1.2-standalone.jar和apache-hive-3.1.2-bin.tar.gz 含两个文件hive-jdbc-3.1.2-standalone.jar和apache-hive-3.1.2-bin.tar.gz 含两个文件hive-jdbc-3.1.2-standalone.jar和apache-hive-...
02、hive-exec-2.1.1-cdh6.3.1.jar 03、hive-jdbc-2.1.1-cdh6.3.1.jar 04、hive-jdbc-2.1.1-cdh6.3.1-standalone.jar 05、hive-metastore-2.1.1-cdh6.3.1.jar 06、hive-service-2.1.1-cdh6.3.1.jar 07、libfb303-...
dbeaver连接hive时需要的驱动包hive-jdbc-uber-2.6.5.0-292.jar
赠送jar包:flink-connector-hive_2.11-1.12.7.jar; 赠送原API文档:flink-connector-hive_2.11-1.12.7-javadoc.jar; 赠送源代码:flink-connector-hive_2.11-1.12.7-sources.jar; 赠送Maven依赖信息文件:flink-...
hive-jdbc-3.1.2-standalone适用于linux
hive-jdbc-uber-2.6.5.0-292.jar 驱动下载,hive-jdbc-uber-2.6.5.0-292.jar,hive-jdbc-uber-2.6.5.0-292.jar
hive-jdbc-uber-2.6.5.0-292.jar驱动
hive-jdbc-1.2.1-standalone.jar hive-jdbc驱动jar包,欢迎下载
hive-jdbc-2.3.7-standalone,可用dbeaver连接hive数据库,在工具中进行数据库记录的新增改查
hive-jdbc-uber-2.6.5.0-292.jar DbVisualizer (as of version 9.5.5) Below is an example configuration using DbVisualizer: Open the Diver Manager dialog ("Tools" > "Driver Manager...") and hit the ...
hive-jdbc-2.1.1-cdh6.2.0(ieda等jdbc链接hive2.1.1);cdh6.2.0安装的hive2.1.1
Hive连接的jar包——hive-jdbc-3.1.2-standalone.jar,使用数据库连接软件连接数据仓库时需要使用相应的驱动器驱动,希望对大家有所帮助
用java连接hive所必须的jar包,包括hadoop-commmon-2.6.4以及hive-jdbc-1.2.1-standalone
jdbc连接hive所需的一个包 ( hive-jdbc-3.1.2.jar)
Missing Hive Execution Jar: /hive/hive1.2.1/lib/hive-exec-*.jar
hive-hcatalog-core-1.2.1.jarhive-hcatalog-core-1.2.1.jarhive-hcatalog-core-1.2.1.jar
被编译的hive-hbase-handler-1.2.1.jar,用于在Hive中创建关联HBase表的jar,解决创建Hive关联HBase时报FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop....