hive集成kerberos问题1
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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;
}
}
|