import java.util.HashSet; 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; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class AuthHook extends AbstractSemanticAnalyzerHook { static final private Log LOG = LogFactory.getLog(AuthHook.class.getName()); private static HashSet<String> adminlist = new HashSet<String>() { {add("hdfs");} }; private static String adminstr = "hdfs"; @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(); } LOG.debug("authhook username = "+userName); if (!adminlist.contains(userName.toLowerCase())) { throw new SemanticException("User:"+userName + " isn‘t ADMIN, please ask for " + adminstr + "."); } break; default: LOG.debug("AST type = "+ast.getToken().getType()); break; } return ast; } }
本文出自 “菜光光的博客” 博客,请务必保留此出处http://caiguangguang.blog.51cto.com/1652935/1381334
hive集成kerberos问题1,布布扣,bubuko.com
原文:http://caiguangguang.blog.51cto.com/1652935/1381334