OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowRolesCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for ShowRolesCommand:
+ Collaboration diagram for ShowRolesCommand:

Public Member Functions

 ShowRolesCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute (bool read_only_mode) override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Additional Inherited Members

- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 346 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

ShowRolesCommand::ShowRolesCommand ( const DdlCommandData ddl_data,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 3548 of file DdlCommandExecutor.cpp.

References CHECK, and anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload().

3551  : DdlCommand(ddl_data, session_ptr) {
3552  auto& ddl_payload = extractPayload(ddl_data);
3553  CHECK(ddl_payload["userName"].IsString());
3554  CHECK(ddl_payload["effective"].IsBool());
3555 }
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult ShowRolesCommand::execute ( bool  read_only_mode)
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 3557 of file DdlCommandExecutor.cpp.

References ResultSetLogicalValuesBuilder::create(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), genLiteralStr(), legacylockmgr::getExecuteReadLock(), Catalog_Namespace::SysCatalog::instance(), Catalog_Namespace::UserMetadata::isSuper, kTEXT, DdlCommand::session_ptr_, and Catalog_Namespace::UserMetadata::userId.

Referenced by heavydb.cursor.Cursor::executemany().

3557  {
3558  auto execute_read_lock = legacylockmgr::getExecuteReadLock();
3559 
3560  // valid in read_only_mode
3561 
3562  auto& ddl_payload = extractPayload(ddl_data_);
3563  auto& sys_cat = Catalog_Namespace::SysCatalog::instance();
3564 
3565  // label_infos -> column labels
3566  std::vector<TargetMetaInfo> label_infos;
3567  std::vector<std::string> labels{"ROLES"};
3568  label_infos.emplace_back(labels[0], SQLTypeInfo(kTEXT, true));
3569 
3570  // logical_values -> table data
3571  std::vector<RelLogicalValues::RowValues> logical_values;
3572  std::vector<std::string> roles_list;
3573  Catalog_Namespace::UserMetadata self = session_ptr_->get_currentUser();
3574  std::string user_name = ddl_payload["userName"].GetString();
3575  bool effective = ddl_payload["effective"].GetBool();
3576  if (user_name.empty()) {
3577  user_name = self.userName;
3578  }
3580  bool is_user = sys_cat.getMetadataForUser(user_name, user);
3581  if (!self.isSuper) {
3582  if (is_user) {
3583  if (self.userId != user.userId) {
3584  throw std::runtime_error(
3585  "Only a superuser is authorized to request list of roles granted to another "
3586  "user.");
3587  }
3588  } else {
3589  if (!sys_cat.isRoleGrantedToGrantee(
3590  self.userName, user_name, /*only_direct=*/false)) {
3591  throw std::runtime_error(
3592  "Only a superuser is authorized to request list of roles granted to a role "
3593  "they don't have.");
3594  }
3595  }
3596  }
3597  if (user.isSuper) {
3598  auto s = sys_cat.getCreatedRoles();
3599  roles_list.insert(roles_list.end(), s.begin(), s.end());
3600  } else {
3601  roles_list = sys_cat.getRoles(user_name, effective);
3602  }
3603  for (const std::string& role_name : roles_list) {
3604  logical_values.emplace_back(RelLogicalValues::RowValues{});
3605  logical_values.back().emplace_back(genLiteralStr(role_name));
3606  }
3607 
3608  // Create ResultSet
3609  std::shared_ptr<ResultSet> rSet = std::shared_ptr<ResultSet>(
3610  ResultSetLogicalValuesBuilder::create(label_infos, logical_values));
3611 
3612  return ExecutionResult(rSet, label_infos);
3613 }
auto getExecuteReadLock()
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:343
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
static ResultSet * create(std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
Definition: sqltypes.h:79
static std::unique_ptr< RexLiteral > genLiteralStr(std::string val)
Definition: DBHandler.cpp:7770
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_
std::vector< std::unique_ptr< const RexScalar >> RowValues
Definition: RelAlgDag.h:2656
std::atomic< bool > isSuper
Definition: SysCatalog.h:107

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: