OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parser::RevokePrivilegesStmt Class Reference

#include <ParserNode.h>

+ Inheritance diagram for Parser::RevokePrivilegesStmt:
+ Collaboration diagram for Parser::RevokePrivilegesStmt:

Public Member Functions

 RevokePrivilegesStmt (std::list< std::string * > *p, std::string *t, std::string *o, std::list< std::string * > *g)
 
 RevokePrivilegesStmt (const rapidjson::Value &payload)
 
const std::vector< std::string > & get_privs () const
 
const std::string & get_object_type () const
 
const std::string & get_object () const
 
const std::vector< std::string > & get_grantees () const
 
void execute (const Catalog_Namespace::SessionInfo &session, bool read_only_mode) override
 
- Public Member Functions inherited from Parser::DDLStmt
void setColumnDescriptor (ColumnDescriptor &cd, const ColumnDef *coldef)
 
- Public Member Functions inherited from Parser::Node
virtual ~Node ()
 

Private Attributes

std::vector< std::string > privileges_
 
std::unique_ptr< std::string > type_
 
std::unique_ptr< std::string > target_
 
std::vector< std::string > grantees_
 

Detailed Description

Definition at line 1642 of file ParserNode.h.

Constructor & Destructor Documentation

Parser::RevokePrivilegesStmt::RevokePrivilegesStmt ( std::list< std::string * > *  p,
std::string *  t,
std::string *  o,
std::list< std::string * > *  g 
)
inline

Definition at line 1644 of file ParserNode.h.

References grantees_, Parser::parser_slistval_to_vector(), and privileges_.

1648  : type_(t), target_(o) {
1651  }
void parser_slistval_to_vector(std::list< std::string * > *l, std::vector< std::string > &v)
Definition: ParserNode.h:1598
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1663
std::vector< std::string > grantees_
Definition: ParserNode.h:1665
std::unique_ptr< std::string > target_
Definition: ParserNode.h:1664
std::vector< std::string > privileges_
Definition: ParserNode.h:1662

+ Here is the call graph for this function:

Parser::RevokePrivilegesStmt::RevokePrivilegesStmt ( const rapidjson::Value &  payload)

Definition at line 5821 of file ParserNode.cpp.

References CHECK, grantees_, json_str(), privileges_, target_, and type_.

5821  {
5822  CHECK(payload.HasMember("type"));
5823  type_ = std::make_unique<std::string>(json_str(payload["type"]));
5824 
5825  CHECK(payload.HasMember("target"));
5826  target_ = std::make_unique<std::string>(json_str(payload["target"]));
5827 
5828  if (payload.HasMember("privileges")) {
5829  CHECK(payload["privileges"].IsArray());
5830  for (auto& privilege : payload["privileges"].GetArray()) {
5831  auto r = json_str(privilege);
5832  // privilege was a StringLiteral
5833  // and is wrapped with quotes which need to get removed
5834  boost::algorithm::trim_if(r, boost::is_any_of(" \"'`"));
5835  privileges_.emplace_back(r);
5836  }
5837  }
5838  if (payload.HasMember("grantees")) {
5839  CHECK(payload["grantees"].IsArray());
5840  for (auto& grantee : payload["grantees"].GetArray()) {
5841  std::string g = json_str(grantee);
5842  grantees_.emplace_back(g);
5843  }
5844  }
5845 }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1663
std::vector< std::string > grantees_
Definition: ParserNode.h:1665
std::unique_ptr< std::string > target_
Definition: ParserNode.h:1664
#define CHECK(condition)
Definition: Logger.h:222
std::vector< std::string > privileges_
Definition: ParserNode.h:1662

+ Here is the call graph for this function:

Member Function Documentation

void Parser::RevokePrivilegesStmt::execute ( const Catalog_Namespace::SessionInfo session,
bool  read_only_mode 
)
overridevirtual

Implements Parser::DDLStmt.

Definition at line 5847 of file ParserNode.cpp.

References Parser::createObject(), DBObjectTypeFromString(), Parser::extractObjectNameFromHierName(), g_enable_fsi, Catalog_Namespace::SessionInfo::get_currentUser(), get_object(), get_object_type(), get_privs(), Catalog_Namespace::SessionInfo::getCatalog(), grantees_, Parser::parseStringPrivs(), ServerDBObjectType, and Parser::verifyObject().

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

5848  {
5849  if (read_only_mode) {
5850  throw std::runtime_error("REVOKE invalid in read only mode.");
5851  }
5852  auto& catalog = session.getCatalog();
5853  const auto& currentUser = session.get_currentUser();
5854  const auto parserObjectType = boost::to_upper_copy<std::string>(get_object_type());
5855  const auto objectName =
5856  extractObjectNameFromHierName(get_object(), parserObjectType, catalog);
5857  auto objectType = DBObjectTypeFromString(parserObjectType);
5858  if (objectType == ServerDBObjectType && !g_enable_fsi) {
5859  throw std::runtime_error("REVOKE failed. SERVER object unrecognized.");
5860  }
5861  /* verify object exists and is of proper type *before* trying to execute */
5862  verifyObject(catalog, objectName, objectType, "REVOKE");
5863 
5864  DBObject dbObject = createObject(objectName, objectType);
5865  /* verify object ownership if not suser */
5866  if (!currentUser.isSuper) {
5867  if (!SysCatalog::instance().verifyDBObjectOwnership(currentUser, dbObject, catalog)) {
5868  throw std::runtime_error(
5869  "REVOKE failed. It can only be executed by super user or owner of the "
5870  "object.");
5871  }
5872  }
5873  /* set proper values of privileges & grant them to the object */
5874  std::vector<DBObject> objects(get_privs().size(), dbObject);
5875  for (size_t i = 0; i < get_privs().size(); ++i) {
5876  std::pair<AccessPrivileges, DBObjectType> priv = parseStringPrivs(
5877  boost::to_upper_copy<std::string>(get_privs()[i]), objectType, get_object());
5878  objects[i].setPrivileges(priv.first);
5879  objects[i].setPermissionType(priv.second);
5880  if (priv.second == ServerDBObjectType && !g_enable_fsi) {
5881  throw std::runtime_error("REVOKE failed. SERVER object unrecognized.");
5882  }
5883  }
5884  SysCatalog::instance().revokeDBObjectPrivilegesBatch(grantees_, objects, catalog);
5885 }
std::string extractObjectNameFromHierName(const std::string &objectHierName, const std::string &objectType, const Catalog_Namespace::Catalog &cat)
DBObjectType DBObjectTypeFromString(const std::string &type)
Definition: DBObject.cpp:110
std::vector< std::string > grantees_
Definition: ParserNode.h:1665
Catalog & getCatalog() const
Definition: SessionInfo.h:65
static std::pair< AccessPrivileges, DBObjectType > parseStringPrivs(const std::string &privs, const DBObjectType &objectType, const std::string &object_name)
static void verifyObject(Catalog_Namespace::Catalog &sessionCatalog, const std::string &objectName, DBObjectType objectType, const std::string &command)
const std::vector< std::string > & get_privs() const
Definition: ParserNode.h:1654
static DBObject createObject(const std::string &objectName, DBObjectType objectType)
const std::string & get_object() const
Definition: ParserNode.h:1656
bool g_enable_fsi
Definition: Catalog.cpp:96
const UserMetadata & get_currentUser() const
Definition: SessionInfo.h:71
const std::string & get_object_type() const
Definition: ParserNode.h:1655

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::vector<std::string>& Parser::RevokePrivilegesStmt::get_grantees ( ) const
inline

Definition at line 1657 of file ParserNode.h.

References grantees_.

1657 { return grantees_; }
std::vector< std::string > grantees_
Definition: ParserNode.h:1665
const std::string& Parser::RevokePrivilegesStmt::get_object ( ) const
inline

Definition at line 1656 of file ParserNode.h.

References target_.

Referenced by execute().

1656 { return *target_; }
std::unique_ptr< std::string > target_
Definition: ParserNode.h:1664

+ Here is the caller graph for this function:

const std::string& Parser::RevokePrivilegesStmt::get_object_type ( ) const
inline

Definition at line 1655 of file ParserNode.h.

References type_.

Referenced by execute().

1655 { return *type_; }
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1663

+ Here is the caller graph for this function:

const std::vector<std::string>& Parser::RevokePrivilegesStmt::get_privs ( ) const
inline

Definition at line 1654 of file ParserNode.h.

References privileges_.

Referenced by execute().

1654 { return privileges_; }
std::vector< std::string > privileges_
Definition: ParserNode.h:1662

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<std::string> Parser::RevokePrivilegesStmt::grantees_
private

Definition at line 1665 of file ParserNode.h.

Referenced by execute(), get_grantees(), and RevokePrivilegesStmt().

std::vector<std::string> Parser::RevokePrivilegesStmt::privileges_
private

Definition at line 1662 of file ParserNode.h.

Referenced by get_privs(), and RevokePrivilegesStmt().

std::unique_ptr<std::string> Parser::RevokePrivilegesStmt::target_
private

Definition at line 1664 of file ParserNode.h.

Referenced by get_object(), and RevokePrivilegesStmt().

std::unique_ptr<std::string> Parser::RevokePrivilegesStmt::type_
private

Definition at line 1663 of file ParserNode.h.

Referenced by get_object_type(), and RevokePrivilegesStmt().


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