0
回答
hive 超级用户如何限制grant
华为云实践训练营,热门技术免费实践!>>>   

先配置文件添加:

<property> 
    <name>hive.semantic.analyzer.hook</name> 
    <value>com.abc.hive.AuthHook</value>  
</property>

 

然后有个类代码:(问题是:如何编辑打包上传下面的码?具体步骤是啥?)

/*
 * Copyright (c) 2010-2013 All Rights Reserved.
 *
 * Author     :
 * Version    :1.0
 * Create Date:2013-6-13
 */
package com.abc.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;

/**
 * 设置Hive超级管理员
 * 
 * @author 
 * @version $Id: AuthHook.java,v 0.1 2013-6-13 下午3:32:12 yinxiu Exp $
 */
public class AuthHook extends AbstractSemanticAnalyzerHook {
    private static String admin = "hadoop";

    @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;
    }
}

 

<无标签>
举报
alibull
发帖于8个月前 0回/86阅
顶部