15 package com.cloudera.impala.analysis;
17 import java.util.HashSet;
26 import com.cloudera.impala.thrift.TQueryCtx;
31 analyzer_.getCatalog().getAuthPolicy().addRole(
32 new Role(
"myRole",
new HashSet<String>()));
38 TestUtils.createQueryContext(defaultDb, System.getProperty(
"user.name"));
45 TestUtils.createQueryContext(defaultDb, System.getProperty(
"user.name"));
58 "Authorization is not enabled.");
59 AnalysisError(
"SHOW ROLE GRANT GROUP myGroup", authDisabledAnalyzer,
60 "Authorization is not enabled.");
62 "Authorization is not enabled.");
68 AnalyzesOk(
"SHOW GRANT ROLE myRole ON SERVER");
69 AnalyzesOk(
"SHOW GRANT ROLE myRole ON DATABASE functional");
70 AnalyzesOk(
"SHOW GRANT ROLE myRole ON TABLE foo");
71 AnalyzesOk(
"SHOW GRANT ROLE myRole ON TABLE functional.alltypes");
72 AnalyzesOk(
"SHOW GRANT ROLE myRole ON URI 'hdfs:////test-warehouse//foo'");
74 "Role 'does_not_exist' does not exist.");
76 "Role 'does_not_exist' does not exist.");
80 "Authorization is not enabled.");
81 AnalysisError(
"SHOW GRANT ROLE myRole ON SERVER", authDisabledAnalyzer,
82 "Authorization is not enabled.");
90 AnalysisError(
"DROP ROLE doesNotExist",
"Role 'doesNotExist' does not exist.");
91 AnalysisError(
"CREATE ROLE myRole",
"Role 'myRole' already exists.");
95 AnalysisError(
"CREATE ROLE MYrole",
"Role 'MYrole' already exists.");
99 "Authorization is not enabled.");
100 AnalysisError(
"CREATE ROLE doesNotExist", authDisabledAnalyzer,
101 "Authorization is not enabled.");
107 AnalyzesOk(
"REVOKE ROLE myrole FROM GROUP abc");
109 "Role 'doesNotExist' does not exist.");
111 "Role 'doesNotExist' does not exist.");
114 AnalysisError(
"GRANT ROLE myrole TO GROUP abc", authDisabledAnalyzer,
115 "Authorization is not enabled.");
116 AnalysisError(
"REVOKE ROLE myrole FROM GROUP abc", authDisabledAnalyzer,
117 "Authorization is not enabled.");
122 boolean[] isGrantVals = {
true,
false};
123 for (
boolean isGrant: isGrantVals) {
124 Object[] formatArgs =
new String[] {
"REVOKE",
"FROM"};
125 if (isGrant) formatArgs =
new String[] {
"GRANT",
"TO"};
127 AnalyzesOk(String.format(
"%s ALL ON TABLE foo %s myrole", formatArgs));
128 AnalyzesOk(String.format(
"%s ALL ON TABLE bar.foo %s myrole", formatArgs));
129 AnalyzesOk(String.format(
"%s ALL ON DATABASE foo %s myrole", formatArgs));
130 AnalyzesOk(String.format(
"%s ALL ON SERVER %s myrole", formatArgs));
131 AnalyzesOk(String.format(
"%s ALL ON URI 'hdfs:////abc//123' %s myrole",
133 AnalysisError(String.format(
"%s ALL ON URI 'xxxx:////abc//123' %s myrole",
134 formatArgs),
"No FileSystem for scheme: xxxx");
137 AnalyzesOk(String.format(
"%s INSERT ON TABLE foo %s myrole", formatArgs));
138 AnalyzesOk(String.format(
"%s INSERT ON TABLE bar.foo %s myrole", formatArgs));
139 AnalyzesOk(String.format(
"%s INSERT ON DATABASE foo %s myrole", formatArgs));
140 AnalysisError(String.format(
"%s INSERT ON SERVER %s myrole", formatArgs),
141 "Only 'ALL' privilege may be applied at SERVER scope in privilege spec.");
142 AnalysisError(String.format(
"%s INSERT ON URI 'hdfs:////abc//123' %s myrole",
143 formatArgs),
"Only 'ALL' privilege may be applied at URI scope in " +
146 AnalyzesOk(String.format(
"%s SELECT ON TABLE foo %s myrole", formatArgs));
147 AnalyzesOk(String.format(
"%s SELECT ON TABLE bar.foo %s myrole", formatArgs));
148 AnalyzesOk(String.format(
"%s SELECT ON DATABASE foo %s myrole", formatArgs));
149 AnalyzesOk(String.format(
"%s SELECT ON TABLE foo %s myrole", formatArgs));
150 AnalyzesOk(String.format(
"%s SELECT ON TABLE bar.foo %s myrole", formatArgs));
151 AnalysisError(String.format(
"%s SELECT ON SERVER %s myrole", formatArgs),
152 "Only 'ALL' privilege may be applied at SERVER scope in privilege spec.");
153 AnalysisError(String.format(
"%s SELECT ON URI 'hdfs:////abc//123' %s myrole",
154 formatArgs),
"Only 'ALL' privilege may be applied at URI scope in " +
159 AnalysisError(
"GRANT ALL ON SERVER TO myRole", authDisabledAnalyzer,
160 "Authorization is not enabled.");
161 AnalysisError(
"REVOKE ALL ON SERVER FROM myRole", authDisabledAnalyzer,
162 "Authorization is not enabled.");
164 TQueryCtx queryCtxNoUsername = TestUtils.createQueryContext(
"default",
"");
167 AnalysisError(
"GRANT ALL ON SERVER TO myRole", noUsernameAnalyzer,
168 "Cannot execute authorization statement with an empty username.");
void AnalyzeGrantRevokeRole()
static ImpaladCatalog catalog_
Analyzer createAnalyzer(String defaultDb)
static AuthorizationConfig createHadoopGroupAuthConfig(String serverName, String policyFile, String sentryConfigFile)
ParseNode AnalyzesOk(String stmt)
void AnalyzeGrantRevokePriv()
Analyzer createAuthDisabledAnalyzer(String defaultDb)
static AuthorizationConfig createAuthDisabledConfig()
uint64_t Test(T *ht, const ProbeTuple *input, uint64_t num_tuples)
void AnalyzeCreateDropRole()
void AnalysisError(String stmt)
static final String DEFAULT_DB
void AnalyzeShowGrantRole()