Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ShowRolesStmt.java
Go to the documentation of this file.
1 // Copyright 2014 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.analysis;
16 
19 import com.cloudera.impala.thrift.TShowRolesParams;
20 import com.google.common.base.Preconditions;
21 
26 public class ShowRolesStmt extends AuthorizationStmt {
27  // If null, all roles will be shown. Otherwise only roles granted to this
28  // group will be shown.
29  private final String groupName_;
30  private final boolean isShowCurrentRoles_;
31 
32  // Set during analysis.
34 
35  public ShowRolesStmt(boolean isShowCurrentRoles, String groupName) {
36  // An empty group name should never be possible since group name is an identifier
37  // and Impala does not allow empty identifiers.
38  Preconditions.checkState(!isShowCurrentRoles ||
39  (groupName == null || !groupName.isEmpty()));
40  groupName_ = groupName;
41  isShowCurrentRoles_ = isShowCurrentRoles;
42  }
43 
44  @Override
45  public String toSql() {
46  if (groupName_ == null) {
47  return isShowCurrentRoles_ ? "SHOW CURRENT ROLES" : "SHOW ROLES";
48  } else {
49  return "SHOW ROLE GRANT GROUP " + groupName_;
50  }
51  }
52 
53  public TShowRolesParams toThrift() {
54  TShowRolesParams params = new TShowRolesParams();
55  params.setRequesting_user(requestingUser_.getShortName());
56  params.setIs_show_current_roles(isShowCurrentRoles_);
57  if (groupName_ != null) params.setGrant_group(groupName_);
58  // Users should always be able to execute SHOW CURRENT ROLES.
59  params.setIs_admin_op(!isShowCurrentRoles_);
60  return params;
61  }
62 
63  @Override
64  public void analyze(Analyzer analyzer) throws AnalysisException {
65  super.analyze(analyzer);
66  requestingUser_ = analyzer.getUser();
67  }
68 }
ShowRolesStmt(boolean isShowCurrentRoles, String groupName)